2

Is there some way to track the number of items read during the execution of a method?

If you look at hostname/sitecore/admin/stats.aspx you see values such as "Average Items", "Max Items" and "Total Items" retrieved per rendering. I'm thinking that if Sitecore can capture that info for a rendering, it must be possible to do the same for an individual method (or hierarchy of methods)?

1 Answer 1

5

The class of interest here is Sitecore.Diagnostics.PerformanceCounters.DataCount (in Sitecore.Kernel.dll). You can simply use the following technique:

var initialItemsAccessed = Sitecore.Diagnostics.PerformanceCounters.DataCount.DataItemsAccessed.Value;
SomeMethod();//the method you want to assess
var totalItemsAccessed = Sitecore.Diagnostics.PerformanceCounters.DataCount.DataItemsAccessed.Value - initialItemsAccessed;

The DataCount class has various other static counter properties which you can query in the same way.

I found this out by looking first at /Sitecore/admin/ShowConfig.aspx to see what processors are used within the mvc.renderRendering pipeline. Two processors are of interest here:

<processor type="Sitecore.Mvc.Pipelines.Response.RenderRendering.StartStatisticRecording, Sitecore.Mvc"/>

and

<processor type="Sitecore.Mvc.Pipelines.Response.RenderRendering.RecordStatistic, Sitecore.Mvc"/>

Looking at these, I saw a call to DataCount.DataItemsAccessed.Value which is used to query total items accessed before and after rendering the rendering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.