How long has an application been running?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

How long has an application been running?

ian-3
Aside from the "take a timestamp when the app starts up" answer does
anyone know whether you can determine how long a DST (v6) has been
running? If there's no DST way of determining this does anyone know the
underlying MS structure/function?

There must be an answer somewhere but I guess I've not been asking the
DST image or MSDN the right questions...

     TIA, Ian


Reply | Threaded
Open this post in threaded view
|

Re: How long has an application been running?

ian-3
should read "...how long a DST (v6) application has been running?"

my proof reading's not what it should be...

       Ian


Reply | Threaded
Open this post in threaded view
|

Re: How long has an application been running?

Udo Schneider
In reply to this post by ian-3
Ian wrote:
> Aside from the "take a timestamp when the app starts up" answer does
> anyone know whether you can determine how long a DST (v6) has been
> running? If there's no DST way of determining this does anyone know the
> underlying MS structure/function?
The info you are searching should be available using the Toolhelp API
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/tool_help_library.asp 
and http://www.codeproject.com/threads/enumprocnt5.asp). If I remember
correctly Steve Waring's SWSysUI package contains wrappers for this
(http://www.stevewaring.net/dolphin/SWSysUI/index.html).

CU,

Udo


Reply | Threaded
Open this post in threaded view
|

Re: How long has an application been running?

Udo Schneider
In reply to this post by ian-3
Ian wrote:
> Aside from the "take a timestamp when the app starts up" answer does
> anyone know whether you can determine how long a DST (v6) has been
> running? If there's no DST way of determining this does anyone know the
> underlying MS structure/function?
The info you are searching should be available using the Toolhelp API
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/tool_help_library.asp 
and http://www.codeproject.com/threads/enumprocnt5.asp). If I remember
correctly Steve Waring's SWSysUI package contains wrappers for this
(http://www.stevewaring.net/dolphin/SWSysUI/index.html).

CU,

Udo


Reply | Threaded
Open this post in threaded view
|

Re: How long has an application been running?

Chris Uppal-3
In reply to this post by ian-3
Ian wrote:

> Aside from the "take a timestamp when the app starts up" answer does
> anyone know whether you can determine how long a DST (v6) has been
> running? If there's no DST way of determining this does anyone know the
> underlying MS structure/function?

I don't know of a record of the start time in the image.  The Kernel32.dll has
two functions which I think should suffice:

GetCurrentProcess()
http://msdn.microsoft.com/library/en-us/dllproc/base/getcurrentprocess.asp

GetProcessTimes()
http://msdn.microsoft.com/library/en-us/dllproc/base/getprocesstimes.asp

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: How long has an application been running?

ian-3
In reply to this post by ian-3
thanks Udo and Chris. I guess I'll try and re-use Steve Waring's work
rather than re-invent the wheel.

     Ian


Reply | Threaded
Open this post in threaded view
|

Re: How long has an application been running?

Schwab,Wilhelm K
Ian,

> thanks Udo and Chris. I guess I'll try and re-use Steve Waring's work
> rather than re-invent the wheel.

Dumb question to keep in mind: does the clock wrap at any point?  If so,
  you might be better off saving a time stamp that you can trust.

Have a good one,

Bill


--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: How long has an application been running?

Udo Schneider
In reply to this post by ian-3
Ian wrote:
> thanks Udo and Chris. I guess I'll try and re-use Steve Waring's work
> rather than re-invent the wheel.
After taking a look at the MSDN stuff Chriss sent I would take the way
Cris proposed.

Add the following method to KernelLibrary:
getProccessTime: hProcess lpCreationTime: lpCreationTime lpExitTime:
lpExitTime lpKernelTime: lpKernelTime lpUserTime: lpUserTime
        "The GetProcessTimes function retrieves timing information for the
specified process.

        BOOL GetProcessTimes(
                HANDLE hProcess,
                LPFILETIME lpCreationTime,
                LPFILETIME lpExitTime,
                LPFILETIME lpKernelTime,
                LPFILETIME lpUserTime
        );"

        <stdcall: bool GetProcessTimes handle FILETIME* FILETIME* FILETIME*
FILETIME*>
        ^self invalidCall


You should now be able to execute the following code:
lpCreationTime := FILETIME new.
lpExitTime := FILETIME new.
lpKernelTime := FILETIME new.
lpUserTime := FILETIME new.
KernelLibrary default
        getProccessTime: KernelLibrary default getCurrentProcess
        lpCreationTime: lpCreationTime
        lpExitTime: lpExitTime
        lpKernelTime: lpKernelTime
        lpUserTime: lpUserTime


The different FILETIMEs should now contain the times you are searching for.

CU,

Udo


Reply | Threaded
Open this post in threaded view
|

Re: How long has an application been running?

Chris Uppal-3
In reply to this post by Schwab,Wilhelm K
Bill,

> Dumb question to keep in mind: does the clock wrap at any point?

With GetProcessTimes() everything's expressed as FILETIMEs, which overflow
after about 6000 years.  Ian should be /fairly/ safe ;-)

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: How long has an application been running?

Schwab,Wilhelm K
Chris,

>>Dumb question to keep in mind: does the clock wrap at any point?
>
>
> With GetProcessTimes() everything's expressed as FILETIMEs, which overflow
> after about 6000 years.  Ian should be /fairly/ safe ;-)

True.  Linux could run that long, but _Windows_!!!! ;)

Have a good one,

Bill


--
Wilhelm K. Schwab, Ph.D.
[hidden email]