3

The last week or so I've been playing with the CLR Profiling API, as a pet project for the summer.

I started thinking about how ANTS and DotTrace implement line-level profiling. I can't see anything related to this in the Profiling API, so I assume they've got something proprietary.

I'm looking for pointers or thoughts on how this is implemented by them.

Do they inject MSIL code when the code is being JIT'ed?

trydis
  • 3,905
  • 1
  • 26
  • 31
  • If the reason you're doing it is to find ways to speed up the code (where precision of location is more important than precision of timing), the method I rely on is [*this*](http://stackoverflow.com/a/378024/23771). – Mike Dunlavey Jul 16 '13 at 11:56
  • I've actually seen that answer already, which makes sense. I'm not doing it because i want to speed up some specific code, just because i was curious :) – trydis Jul 16 '13 at 18:32
  • 1
    There are two ways, instrumenting and stack-sampling. Instrumenting involves inserting calls into the code, so it's invasive and costly. Stack sampling (as in [*Zoom*](http://www.rotateright.com/)) is non-invasive and gives line-level cost. I'm not sure if there are any for .net. If not, there should be. – Mike Dunlavey Jul 16 '13 at 18:53

1 Answers1

1

CLR Profiling API support out of the box only tracing on Enter & Leave level. This can be done using ICorProfilerInfo::SetEnterLeaveFunctionHooks

In order to trace at finer level weaving of IL is required. You can use these open source profilers code as references:

Both weave code during JITCompilationStarted callback.

Elisha
  • 23,310
  • 6
  • 60
  • 75
  • Thanks for the reply. Yes, I've got the enter, leave and tail call callbacks working nicely. Will look closer at the projects you mention, have only briefly looked at the code of one of them. – trydis Jul 16 '13 at 18:28