问题描述
我只想使用 .NET Profiling API(ICorProfilerCallback
等)但同时不想处理 C++.我已经环顾了一段时间,没有找到任何 C# 的例子,但是 C# + C++ 中最有趣的部分是使用 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++.
推荐答案
不,您不能在托管代码(C# 或其他)中实现 CLR 分析 API,因为在假定托管环境的特定时间调用分析回调处于某种状态.在托管代码中实现回调会违反很多假设.
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.
CLR 分析 API 的开发人员 David Broman 拥有 这个要说:
David Broman, the developer of the CLR profiling APIs, has this to say:
您需要将分析器写入C++.探查器由在非常微妙的点运行时执行分析的应用程序,并且通常非常不安全在这些点运行托管代码.
David 的博客是处理 CLR 分析 API 的重要资源.
David's blog is a great resource for dealing with the CLR profiling APIs.
这篇关于是否可以直接从 C# 使用 Profiling API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!