home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.win32
- Path: sparky!uunet!microsoft!hexnut!johnhall
- From: johnhall@microsoft.com (John Hall)
- Subject: Re: Getting the Process/Thread CPU Time:
- Message-ID: <1992Sep14.065534.16336@microsoft.com>
- Date: 14 Sep 92 06:55:34 GMT
- Organization: Microsoft Corporation
- References: <1709@sousa.ltn.dec.com>
- Lines: 75
-
- In article perkins@sousa.ltn.dec.com (Eric Perkins) writes:
- |
- | Has anyone seen any API which will give the amount of CPU
- | time a thread or process has used up? The program Pview that
- | comes with the SDK can do this so there must be a way with the
- | API to do this, right?
-
- Mostly, you need to use the API's already there in new and
- interesting ways. On the ftp server under OS2toWindows
- [sort of where I hang out] I placed a *rough* example of how
- to do this with the PDC build.
-
- Yes, Perfmon does use a few Nt calls because not everything
- of interest was exposed through the official mechanisms by
- the PDC build date. Those Nt calls are not (according to
- the designer) necessary in future versions but no word on
- when it will be cleaned up.
-
- Brief how to:
-
- The counters available can vary from system to system, and
- theoretically the index number of the counters can as well.
- You find the counters for a given system by looking at:
- HKEY_LOCAL_MACHINE\\Software\\Microsoft\\CurrentVersion\\
- Perflib\\<Lang ID -- '409' for now>\\Counters as a set
- of MULTI_SZ data which looks like:
- "2" "% Process Time" "4" "Processes" etc.
- There is also a Help value with odd numbers which explains
- each counter string.
- "5" "List of Processes active in the local machine"
-
- The perf2.zip I uploaded contains a program called
- 'perf1.exe' which dumps all this in a useful manner
- (as #define's). For reasons I explain, at the current state
- of the system you probably want to hard code these values
- [after figuring out what they are].
-
- Then, armed with values for: Processes, Threads, Total Process
- time, Total thread time, User thread time, Privlidged thread time
- the algorithm looked like this:
-
- Query HKEY_PERFORMANCE_DATA\\Global. You probably have to get
- it multiple times till you grow your buffer big enough.
-
- When this exceeds, you have all the performance data (as a snapshot)
- that anyone could want -- you just need to interpret it.
-
- Interpretation:
-
- Basically, you walk the structures contained in winperf.h.
- Loop through all objects looking for the objects of interest
- (Processes and Threads) save pointers to them.
-
- Examine the Process Object and Thread Object looking for
- counter definitions (type, offset).
-
- Loop through all process instances:
- [Instance 0 is special, it has no threads by definition]
- print the process name [it is in unicode!]
- output Process Time data.
- For every THREAD instance, see if the thread parent is this
- process instance. If it is accumulate the info.
- output thread data.
-
- This yields a simple output. I discuss some extentions to
- make this a true time() system. Again, this is rough but
- I hope it helps.
-
-
-
-
-
-
- --
- -------------------------
- My comments are my own. They are independent and unrelated to the
- views of my company , relatives or elected representatives.
-
-