TransWikia.com

Performance profiling - assess the number of items read during the execution of a method

Sitecore Asked on December 2, 2021

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)?

One Answer

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.

Answered by Matthew Dresser on December 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP