开发者

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

开发者 https://www.devze.com 2023-02-27 05:03 出处:网络
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# 开

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 C++.


No, you cannot implement the CLR profiling APIs in managed code (C# or otherwise) since the profiling callbacks are called at very specific times when the managed environment is assumed to be in a certain state. Implementing your callbacks in managed code would violate a lot of assumptions.

David Broman, the developer of the CLR profiling APIs, has this to say:

You need to write your profiler in C++. The profiler is called by the runtime at very delicate points during execution of the profiled application, and it is often extremely unsafe to be running managed code at those points.

David's blog is a great resource for dealing with the CLR profiling APIs.

0

精彩评论

暂无评论...
验证码 换一张
取 消