Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many seconds does a "sample" represent in the profiler?

In the Visual Studio Profiler, there is an option to use a "sampling" method of profiling which can be used on my ASP.NET MVC app:

The sampling profiling method of the Visual Studio Profiling Tools interrupts the computer processor at set intervals and collects the function call stack. A call stack is a dynamic structure that stores information about the functions that are executing on the processor.

This allows me to get a rough indication of what code is taking the longest to execute. However, I am not sure how much time each sample value represents. Is 3,441 34.41 seconds? Maybe there is no pure conversion to a time measurement. If so, can someone explain why? The documentation claims that there are set intervals, but does not elaborate on how long each interval lasts.

like image 587
stevebot Avatar asked Oct 03 '22 19:10

stevebot


1 Answers

In my ideal world, nobody would care what the time measurement for individual routines or lines of code was, as long as the samples happened during the interval one cared about, and were uncorrelated with the state of the program.

What matters is the inclusive percent.

For each line of code that appears on stack samples, the percent of samples it appears on (at the end or in the middle) is what matters, because that's the percent of time that would be saved if it could be removed.

(Also, unless I'm wrong, I don't believe the VS profiler samples during I/O, which makes it blind to needless I/O.)

Responding to your comment: Suppose samples were 100/second vs. 10/second, and the total time was 10 seconds, so the number of samples were 1000 vs. 100. If a line of code is on 20% of the stack samples, then removing it would save 20% of 10 seconds, or 2 seconds, regardless of the sample rate. That's why the sample rate doesn't matter.

like image 112
Mike Dunlavey Avatar answered Oct 19 '22 09:10

Mike Dunlavey