![]() Int ProcessCpuUsageByID = usageC.GetCpuUsage(processID) Int ProcessCpuUsageByName = usageB.GetCpuUsage( " explorer") Int SystemWideCpuUsage = usageA.GetCpuUsage() ![]() Display the system-wide cpu usage and the "Explorer" cpu usage Printf( " SystemWide Cpu Usage " " Explorer cpu usage " " Cpu Usage for processID 0\n") ![]() #include " CpuUsage.h" int main( int argc, char* argv) The counter '% processor time' whose index is 6 under the object 'Process' whose index is 230. There is no difference between WinNT and Win2K/XP in the performance counters for getting CPU usage for a specific process. Read 'INFO: Percent Total Performance Counter Changes on Windows 2000' (Q259390) in MSDN. However, in Win2K/XP, Microsoft moved that counter to '% processor time' whose index is 6 under '_Total' instance of 'Processor' object whose index is 238. On Windows NT, CPU usage counter is '% Total processor time' whose index is 240 under 'System' object whose index is 2. Since the CPU usage can be determined by two samplings, the first call to GetCpuUsage() returns 0, and all calls thereafter returns the CPU usage. My CCpuUsage class has a method called GetCpuUsage which runs through the performance objects and counters and retrieves the CPU usage. Where the denominator (Y) represents the total elapsed time of the sample interval and the numerator (X) represents the time during the interval when the monitored components were inactive.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |