0

I've created a .NET Profiling DLL that implements the ICorProfilerCallback3 interface.

I'm using the profiling to trace the functions called during Runtime, however, I'm looking to trace application specific functions, not the standard .NET framework functions.

I successfully used the SetEnterLeaveFunctionHook method and supply it with callback functions.

Then while I'm in the callback functions, I get the function information and assembly information using the GetFunctionInfo and GetModuleInfo2 functions.

The issue I'm running into is this obviously gets called for EVERY function and I'm looking for a way to distinguish between a .Net framework DLL and not a standard DLL.

For instance the majority of calls when the application starts goes to the mscorlib.dll which I'm not interested in tracing.

Any thoughts or ideas? I've tried call this function but pdwImplFlags doesn't appear to populate with anything useful.

https://learn.microsoft.com/en-us/dotnet/framework/unmanaged-api/metadata/imetadataimport-getmethodprops-method

CBaker
  • 830
  • 2
  • 10
  • 25

1 Answers1

1

You can use SetFunctionIDMapper2 to specify a mapper which checks to see if the function is of interest and return false in pbHookFunction if it's not. Then you should only get callbacks for the methods where you returned true in pbHookFunction.

Brian Reichle
  • 2,798
  • 2
  • 30
  • 34
  • Thats an interesting solution. Appreciate the response. I feel like I would still run into the same problem. I'm not sure how to distinguish between a function I want and a function I don't want. I still would need a way to differentiate between a .NET framework function and a non framework function for the mapper. – CBaker Jul 13 '21 at 02:34
  • 1
    I would probably go with a 'whitelist' of assemblies that gets given to the profiler. Or you could make the decision based on the location of the assembly. – Brian Reichle Jul 13 '21 at 02:39
  • The location of the assembly makes sense. I really would of thought there would be some type of flag or API call to make it a little bit cleaner. Guess not. – CBaker Jul 13 '21 at 14:08
  • The other option is to exclude by namespace, for example System.* etc – Alex Buyny Jul 16 '21 at 08:46