home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / mswindo / programm / win32 / 951 < prev    next >
Encoding:
Text File  |  1992-09-13  |  3.1 KB  |  89 lines

  1. Newsgroups: comp.os.ms-windows.programmer.win32
  2. Path: sparky!uunet!microsoft!hexnut!johnhall
  3. From: johnhall@microsoft.com (John Hall)
  4. Subject: Re: Getting the Process/Thread CPU Time:
  5. Message-ID: <1992Sep14.065534.16336@microsoft.com>
  6. Date: 14 Sep 92 06:55:34 GMT
  7. Organization: Microsoft Corporation
  8. References: <1709@sousa.ltn.dec.com>
  9. Lines: 75
  10.  
  11. In article perkins@sousa.ltn.dec.com (Eric Perkins) writes:
  12. | Has anyone seen any API which will give the amount of CPU
  13. | time a thread or process has used up? The program Pview that
  14. | comes with the SDK can do this so there must be a way with the 
  15. | API to do this, right?
  16.  
  17. Mostly, you need to use the API's already there in new and
  18. interesting ways.  On the ftp server under OS2toWindows
  19. [sort of where I hang out] I placed a *rough* example of how
  20. to do this with the PDC build.
  21.  
  22. Yes, Perfmon does use a few Nt calls because not everything
  23. of interest was exposed through the official mechanisms by
  24. the PDC build date.  Those Nt calls are not (according to
  25. the designer) necessary in future versions but no word on
  26. when it will be cleaned up.
  27.  
  28. Brief how to:
  29.  
  30. The counters available can vary from system to system, and
  31. theoretically the index number of the counters can as well.
  32. You find the counters for a given system by looking at:
  33. HKEY_LOCAL_MACHINE\\Software\\Microsoft\\CurrentVersion\\
  34. Perflib\\<Lang ID -- '409' for now>\\Counters as a set
  35. of MULTI_SZ data which looks like:
  36. "2" "% Process Time" "4" "Processes" etc.
  37. There is also a Help value with odd numbers which explains
  38. each counter string.
  39. "5" "List of Processes active in the local machine"
  40.  
  41. The perf2.zip I uploaded contains a program called
  42. 'perf1.exe' which dumps all this in a useful manner
  43. (as #define's).  For reasons I explain, at the current state
  44. of the system you probably want to hard code these values
  45. [after figuring out what they are].
  46.  
  47. Then, armed with values for: Processes, Threads, Total Process
  48. time, Total thread time, User thread time, Privlidged thread time
  49. the algorithm looked like this:
  50.  
  51. Query HKEY_PERFORMANCE_DATA\\Global.  You probably have to get
  52. it multiple times till you grow your buffer big enough.
  53.  
  54. When this exceeds, you have all the performance data (as a snapshot)
  55. that anyone could want -- you just need to interpret it.
  56.  
  57. Interpretation:
  58.  
  59. Basically, you walk the structures contained in winperf.h.
  60. Loop through all objects looking for the objects of interest
  61. (Processes and Threads) save pointers to them.
  62.  
  63. Examine the Process Object and Thread Object looking for
  64. counter definitions (type, offset).
  65.  
  66. Loop through all process instances:
  67.   [Instance 0 is special, it has no threads by definition]
  68.   print the process name [it is in unicode!]
  69.   output Process Time data.
  70.   For every THREAD instance, see if the thread parent is this
  71.      process instance.  If it is accumulate the info.
  72.   output thread data.
  73.  
  74. This yields a simple output.  I discuss some extentions to
  75. make this a true time() system.  Again, this is rough but
  76. I hope it helps.
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. -- 
  84. -------------------------
  85. My comments are my own.  They are independent and unrelated to the
  86. views of my company , relatives or elected representatives.
  87.  
  88.