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"/>


<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!

Related Questions


0  Asked on October 18, 2020 by katlego-masanabo


Multiroot Treelist with datasource queries

1  Asked on September 26, 2020 by meenu-chauhan


Error processing block: Core.block.StartEnvironmentMinions

0  Asked on September 9, 2020 by eric-gonzalez


Error when trying to configure JSS connected Demo

1  Asked on July 21, 2020 by himanshu-agarwal


Ask a Question

Get help from others!

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