简体   繁体   中英

C# performance counter Timer100Ns. How to?

I have an application which monitors a particular event and then starts to calculate things once it happens. Events are irregular and can come in any pattern from bunches in a sec to none for long time..

I want to measure %% of time the application is busy (similar to CPU % Usage)

I want to use Timer100Ns counter

Two questions:

  1. Do I increment it by hardware ticks or by DateTime ticks (eg if I use Stopwatch - do I use sw.ElapsedTicks or sw.Elapsed.Ticks) ?

  2. Do I need a base counter for it?

so I am about to write something like this:

Stopwatch sw = new Stopwatch();
sw.Start();
// Do some operation which is irregular by nature
sw.Stop();

// Measure utilization of the application
myCounterOfTypeTimer100Ns.IncrementBy(sw.Elapsed.Ticks);

Will it do ?

EDIT : I experimented with it a bit and now its even more confusing.. It actually shows the values I increment it by. Not %%.

The mystery unravelled. It currently appears that I don't use it in the way it was supposed to be used (or rather I didn't read TFM properly). If the sampling interval is 1s (as in perf mon live window) and you intervals are more than 1s then it shows you a nonsense number... To achieve smoothness, the activity you are trying to measure must be really fractions of 1s.. Otherwise this counter is not a good idea..

The answer for this kind of problem (although its not obvious, but still disturbing that nobody suggested it in a week) is actually SampleCounter .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM