Questions tagged [clr-profiling-api]

The Common Language Runtime (CLR) Profiling API is a set of native unmanaged interfaces useful for implementing .NET profilers. It primarily consists of the ICorProfilerCallback and ICorProfilerInfo interface families.

The Common Language Runtime (CLR) Profiling API is a set of native unmanaged interfaces useful for implementing .NET profilers.

The primary interfaces are:

  • ICorProfilerCallback - for receiving notifications regarding various events in the CLR, including Class Loading, Just-In-Time Compilation, and Garbage Collection.

  • ICorProfilerInfo- for querying information regarding the different application entities, such as objects, classes, functions, modules and assemblies.

For a complete reference, refer to Microsoft's official documentation:
Microsoft Unmanaged API Reference / Profiling Interfaces.

54 questions
62
votes
1 answer

Profiling a dynamic pinvoke

I am working on MSIL profiler and encountered problems with ManagedToUnmanagedTransition and UnmanagedToManagedTransition callbacks of ICorProfilerCallback interface. What I want to retrieve is an information about method being called (name and…
dud3
  • 621
  • 4
  • 3
24
votes
1 answer

Is is possible to use Profiling API right from C#?

I just want to use .NET Profiling API (ICorProfilerCallback etc) but at the same time don't want to deal with C++. I've been looking around for a while and haven't found any example in C# but C# + C++ where the most interesting part is written using…
Alex LaWay
  • 435
  • 4
  • 7
24
votes
2 answers

What does 'Cor' stand for?

I've seen in it in the primary CLR dll, mscorlib.dll, and I've seen in it in this CLR Profiling API interface, ICorProfilerCallback2. Just curious: what does the word 'Cor' stand for?
G S
  • 35,511
  • 22
  • 84
  • 118
20
votes
1 answer

CLR profiler: issue in using DefineAssemblyRef

I want to write a CLR profiler to hook our application function with GetILFunctionBody/SetILFunctionBody. I want to use DefineAssemblyRef to import our c# dll (for use in IL code) in this code DefineAssemblyRef always return True? Does my dll…
maysam
  • 201
  • 1
  • 3
12
votes
2 answers

How do you map a native to IL instruction pointer in-process

When using the unmanaged API for the .NET framework to profile a .NET process in-process, is it possible to look up the IL instruction pointer that correlates to the native instruction pointer provided to the StackSnapshotCallback function? As is…
Steven
  • 259
  • 1
  • 10
7
votes
1 answer

CLR Profiling: DoStackSnapshot after a throw inside a catch block gives wrong instruction pointer

I'm currently writing a CLR profiler, and I came across something very odd. When throwing two different exceptions, one from the try clause and one from the catch clause, the CLR notifies me of the same instruction pointer. More specifically: I'm…
Egozy
  • 380
  • 2
  • 13
7
votes
4 answers

Do I need to write my own unmanaged IL library to rewrite IL with the CLR Profiling API?

I've been looking at some of the articles for the CLR Profiling API, and many of those articles talk about calling SetILFunctionBody() to do the actual IL rewriting; however, none of those articles actually explain exactly what you could use to…
plaureano
  • 3,139
  • 6
  • 30
  • 29
6
votes
1 answer

ICorProfilerCallback::ClassUnloadStarted not called for a generic class, even though the class was unloaded

I'm currently debugging my company's CLR profiler (over ASP.NET 4.7.3282.0, .NET framework 4.7.2), and seeing a scenario in which the CLR unloads a generic class, but the ClassUnloadStarted callback is not called. In a nutshell, our profiler keeps…
valiano
  • 16,433
  • 7
  • 64
  • 79
5
votes
1 answer

Understanding "this" argument for structs (specifically Iterators/async)

I'm currently inspecting deep objects in the CLR using the Profiler API. I have a specific problem analyzing "this" argument for Iterators/async methods (generated by the compiler, in the form of d__123::MoveNext). While researching this I…
Egozy
  • 380
  • 2
  • 13
5
votes
0 answers

.NET Instrumentation - Function call to Custom Assembly Fails - Azure Web apps

I have deployed my .NET instrumentation profiler into Azure webapps through Visual studio 2012. My profiler does byte code instrumentation which looks like below, FunctionA() { --> Injected C# function Call functionA's body -->Injected C#…
5
votes
1 answer

Using .NET's ICorProfilerInfo::SetILFunctionBody, is it possible to add a try-finally EH clause to a method that does not have any exception handling?

I am working on an IL-rewriting profiler and my goal is to be able to add a try-finally block to methods. Essentially: // IL to set some state try { // original IL } finally { // IL to revert state } Based on the limited documentation and…
Dan Fiedler
  • 161
  • 8
4
votes
1 answer

ICorProfilerCallback2: CLR profiler does not log all Leave calls

I am trying to write a profiler that logs all .Net method calls in a process. The goal is to make it highly performant and keep let's say the last 5-10 minutes in memory (fixed buffer, cyclically overwrite old info) until the user triggers that info…
Christoph
  • 2,211
  • 1
  • 16
  • 28
3
votes
1 answer

clr profiler api: is ICorProfilerCallback::ExceptionThrown GC safe

I was wondering in .net framework profiler, is ExceptionThrown (https://learn.microsoft.com/en-us/dotnet/framework/unmanaged-api/profiling/icorprofilercallback-exceptionthrown-method) guaranteed to not overlap with GC? Looking at documentation, it…
user967710
  • 1,815
  • 3
  • 32
  • 58
3
votes
0 answers

Can I load a managed C# DLL from a physical path instead of loading from GAC via CLRProfiler

The managed DLL can be loaded when it is in GAC using the public key token and assembly name. MetaDataAssemblyEmit->DefineAssemblyRef(pbPublicKeyOrToken, publicKeySize, assemblyName, &assemblyMetaData, NULL, 0, 0, &mdAssemblyRef); I want to load…
anbu2388
  • 41
  • 3
3
votes
1 answer

IL Rewrite fails to load .Net DLL

I have built the IL Rewriter for some custom requirement. All it does is Creates method references for another .Net DLL (newly built custom DLL) Inject epilogue & prologue for few required methods, they internally call above method references.…
Hitesh
  • 1,067
  • 1
  • 10
  • 27
1
2 3 4