G
Guest
I have a logging application that records various performance metrics into a database every 5 minutes, and to this I'd like to add a performace counter that shows the processor usage in a manner akin to what you see in the Performance tab of the Task Manager -- whatever that value is when the timer fires is what I want to record
I'm using System.Diagnostics.PerformanceCounter with the "% Processor Time" counter, but I'm having a problem. The counter grabs the instantaneous usage, giving me something like: 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, etc. If I let the program run for long enough, the 100s turn to 26.738 or 33.242 -- following closely the values shown in the Task Manager. I assume that in the Task Manager or in perfmon.msc it takes a specified (seemingly large) number of samples per second and averages them to get the final value, and I've thought about doing that, but even simply spitting out the value of the counter continuously jumped processor usage up quite high. For me to sit in a loop taking samples and then average them when a 1-second timer (or 5-minute) timer fires seems like it'd be a huge CPU gobbler, which I can't have
Is there a way I can get the values that are showing when I load that counter into Performance Monitor, or does anyone have any other ideas about how to do this
Thanks
Jeff
I'm using System.Diagnostics.PerformanceCounter with the "% Processor Time" counter, but I'm having a problem. The counter grabs the instantaneous usage, giving me something like: 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, etc. If I let the program run for long enough, the 100s turn to 26.738 or 33.242 -- following closely the values shown in the Task Manager. I assume that in the Task Manager or in perfmon.msc it takes a specified (seemingly large) number of samples per second and averages them to get the final value, and I've thought about doing that, but even simply spitting out the value of the counter continuously jumped processor usage up quite high. For me to sit in a loop taking samples and then average them when a 1-second timer (or 5-minute) timer fires seems like it'd be a huge CPU gobbler, which I can't have
Is there a way I can get the values that are showing when I load that counter into Performance Monitor, or does anyone have any other ideas about how to do this
Thanks
Jeff