Tuesday, January 22, 2013

QuickCounters goof...

I can't believe how blind I was!  I added a quick counter for a WCF service because I wanted to track how long a certain process takes.  I added code similar to this:


// TODO: LEE DEBUG QuickCounters
var qcRequest = RequestType.Attach(QCCategoryOut, "SomeProcessName", true);
try
{
   SomeCode.Instance.DoStuff(asset);
   qcRequest.SetComplete();
}
catch (Exception ex)
{
   qcRequest.SetAbort();
   throw ex;
}

What happened is that the counter ended up showing some very large value for SomeProcessName's "Request Execution Time (msec)" value.  I couldn't figure out why something that was finishing in what looked like a second was displaying values like 1298793265 for Maximum value.

I spent a good bit of time searching for posts on QuickCounters having invalid values for the execution time, but couldn't find anything.  Finally, I noticed the problem - I forgot the BeginRequest() call!  I don't know if it is a feature of QuickCounters to not throw an exception if you call SetComplete() without first calling BeginRequest, but I suppose it is nice to not have code blowing up in production because you added QuickCounter code incorrectly.

The following code works just fine:


// TODO: LEE DEBUG QuickCounters
var qcRequest = RequestType.Attach(QCCategoryOut, "SomeProcessName", true);
try
{
   qcRequest.BeginRequest();
   SomeCode.Instance.DoStuff(asset);
   qcRequest.SetComplete();
}
catch (Exception ex)
{
   qcRequest.SetAbort();
   throw ex;
}





No comments:

Post a Comment