3

I have used the builtin sampling-based performance profiler of VS 2010 successfully in the past. Sometimes the highlighted code in the code window was off by a couple of lines. That might have been due to code optimization, which the profiler is said not to handle very well. Other than that, it worked for me (in contrast to the instrumenting variant)

However, this time the results are just plain wrong. For instance, there is a single line in my code (a call to another method that results in a DB query) that accounts for 40% of the total run time, and which I found by the "comment out code bisection" method.

The sampling profiler of VS2012 (and VS2010, I double checked) however tells me the method accounts for something like 1% (inclusive), i.e. it does not even show up in the report summary and I have to search to the bottom of the detail tables to find it. I cranked up the sampling frequency just in case, to no avail.

What could throw the profiler this far off?

I am profiling a .net 3.5 based project, with a fair number of dlls. I tried profiling in both 'Release' and 'Debug' mode. No substantial difference.

Evgeniy Berezovsky
  • 18,571
  • 13
  • 82
  • 156
  • This is what I read: "I used the profiler to find a line of code that takes 40%, as expected. I commented it out and now it takes 1%". Well, sure. – Hans Passant Aug 13 '13 at 11:30
  • @HansPassant Well, then the question wouldn't make any sense at all. Wrong line highlighting aside, the profiler wouldn't show a commented out line at all. I edited the question to clarify: the profiler did not find that slow line of code, I find it by other means. – Evgeniy Berezovsky Aug 14 '13 at 00:51

2 Answers2

2

Are you in "CPU profiling" mode? In that mode it will be blind to I/O, and I assume a DB query will do I/O.

That's why I rely on this old but surprisingly effective technique. There are no such caveats.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
1

Thanks MikeDunlavey,

your answer is accurate, time spent doing I/O, like accessing a DB, does not show up in the results.

That insight made me search and find something like this pretty awesome feature of Visual Studio: TIP (Tier Interaction Profiler).

It lists all my SQL queries (the exact text of the query), how often they got called, to which DB the calls were made, the time it took to execute them. And it seems to handle other I/O (like HTTP requests as well). Hats off to MS for creating this little-known (?) gem!

After this rare opportunity to praise MS I have to say that the profiler crashes on my app most of the time. But that's another story, and perhaps another question.

Evgeniy Berezovsky
  • 18,571
  • 13
  • 82
  • 156