Measuring average execution time in service
I'm trying to use Windows Performance Counters to measure the Hits Per Second a开发者_运维知识库nd Seconds Per Hit of a WCF service and am seeing some strange results.
Currently, what I'm doing is this:
public void MethodToTime()
{
StopWatch sw = new StopWatch();
sw.Start();
//...do stuff...
totalHitsCounter.Increment(); //this one works fine - NumberOfItems32 counter
hitsPerSecondCounter.Increment(); //appears broken - RateOfCountsPerSecond32 counter
secondsPerHitBaseTime.Increment(); //can't tell - AverageBase counter
sw.Stop();
secondsPerHitCounter.IncrementBy( sw.ElapsedTime ); //appears broken - AverageTimer32
}
At the end of the day, I want to know:
-This method was hit x times (in its lifetime). -This method takes, on average, x.x seconds to execute. -This method is called x times per second (across all service instances, since one call to the service results in one call to the method).
Am I on the right track? Is there a better way to approach this issue? Any feedback is much appreciated :)
Thanks in advance, everyone!
Just so you know, the seconds / hit is simply the inverse of the hits / second. You just need to divide 1 by your hits / second to get it.
精彩评论