1

my code:

using (new SPMonitoredScope("Sleepy Time", 1000)) {
    System.Threading.Thread.Sleep(5000);
}

when I enable the Developer Dashboard, I am expecting a red border around it because the code running in the monitored scope is running longer than 1000 milliseconds.

But it doesn't happen. I do get a bullet point in the Developer Dashboard such as

  • Sleepy Time (5008.26 ms)

but no indication that the counter was triggered. Can anyone explain why?

1

DD only show you the standard events called by SharePoint. Eg OnPreRender, CreateChildControls etc.

If you want to add monitors to a web part, you would need to create a method like this

private void SleepyTime()
{
    using (SPMonitoredScope scope = new SPMonitoredScope("SleepyTime"))
    {                
        System.Threading.Thread.Sleep(5000);
    }
}

and it would show up in DD from the overridden event from which the method was called CreateChildControls (50xx ms) - SleepyTime (5000 ms)

Note that the code above wont run in a sandboxed solution!

You can also create a custom monitored scope using the ISPScopedPerformanceMonitor interface. This is used in conjunction with an overridden constructor

int maxExecutionTime = 1000; // The maximum duration of the monitoring operation, in milliseconds
using (SPMonitoredScope scope = new SPMonitoredScope("SleepyTime", maxExecutionTime, new MyCustomMonitor()))
{
    // MyCustomMonitor implements ISPScopedPerformanceMonitor interface
    // If monitoring the scope exceeds the time represented by the maximumExecutionTime value, you can use the maximumExecutionTime value to increase the logging level.
}
1

The red border is only triggered by SharePoint defined monitors at the root scope. A yellow border should indicate that the request took more than one second.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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