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)?
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
1 Asked on October 20, 2020 by sumitk
0 Asked on October 18, 2020 by katlego-masanabo
2 Asked on September 25, 2020
0 Asked on September 9, 2020 by eric-gonzalez
Get help from others!
Recent Questions
Recent Answers
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP