c#:运行时代码分析 - 是否有现有的库?

发布于 2024-10-02 06:06:52 字数 291 浏览 4 评论 0原文

我有一个应用程序,用户可以将节点连接在一起以执行实时计算。 我希望能够向用户显示 CPU 使用率百分比,以显示正在使用多少可用 CPU 时间,以及每个节点的细分情况,以便能够发现问题区域。

是否有像这样的运行时分析器可用的开源实现? 我可以使用 System.Diagnostics.Process.TotalProcessorTime、秒表/性能计数器编写自己的代码,但我宁愿选择尝试过的东西如果可能的话,经过测试,稍后可能会为我提供更详细的信息。

编辑: 我并不是在寻找独立的分析器,因为我想在应用程序的 UI 中显示实时统计信息。

I have an application where the user can connect nodes together to perform realtime calculations.
I'd like to be able to show the user a CPU-usage percentage to show how much of available CPU-time is being used, and a per-node breakdown to be able to spot the problem-areas.

Are there any available open source implementations for a runtime profiler like this ?
I can write my own using System.Diagnostics.Process.TotalProcessorTime, stopwatches / performancecounters, but I'd rather go with something tried & tested that could maybe offer me more detailed information later if possible.

Edit:
I'm not looking for a stand-alone profiler since I want to show the realtime stats in the UI of my application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只怪假的太真实 2024-10-09 06:06:52

您可以尝试具有此类功能的商业 GlowCode 分析器。

或者开源 SlimTune,但它仍处于测试阶段。

You can try commercial GlowCode profiler that has such feature.

Or open source SlimTune, but it is still in beta.

平安喜乐 2024-10-09 06:06:52

我假设您正在运行一个计时器,比如每秒 10 次计算,因为否则您只是使用 100% 的 CPU(除非您还执行 I/O)。

您能否设置一个闹钟中断以某个合理的频率(例如 10 或 100 Hz)启动,独立于程序正在执行的其他操作,甚至特别是在 I/O 或其他阻塞时间期间?

然后,对于每个块,只需记录它在最近 100 个中断中处于活动状态的次数。这就是你的百分比,而获得它的成本是最低的。

块是否作为子例程相互调用?在这种情况下,在每次中断时,您可能希望捕获块之间的调用堆栈,如果块位于堆栈上的某个位置,则它是“活动的”,如果它位于堆栈末尾,则它是“处理的”(不在调用另一个块的过程中,也不在 I/O 中)。然后,您可以在每个块上选择指示“处理”(对块求和时不会超过 100%)或“活动”(对块求和时可能会超过 100%)的时间百分比。

后一个数字的价值在于,它不会告诉您太多时间花在“哪里”,而是告诉您“为什么”。这可以回答诸如“我发现 foo 花费了很多时间,但我是如何到达那里?”之类的问题。 I/O 也一样。这也是一个过程,它只是发生在其他硬件上。您不想忽略它,因为如果您这样做,您最终可能会说“为什么我只使用了 CPU 的一小部分?有什么阻碍?”

I assume you are running off a timer, like say 10 calculations per second, because otherwise you are simply using 100% of the CPU (unless you're also doing I/O).

Can you set an alarm-clock interrupt to go off at some reasonable frequency, like 10 or 100 Hz, independent of whatever else the program is doing, and even especially during I/O or other blocked time?

Then for each block just keep a count of how many times out of the last 100 interrupts it was active. That's your percent, and the cost of acquiring it is minimal.

Do blocks call each other as subroutines? In that case, on each interrupt, you may want to capture the call stack among blocks, and a block is "active" if it is somewhere on the stack, and it is "crunching" if it is at the end of the stack (not in the process of calling another block, and not in I/O). Then you have a choice on each block of indicating the percent of time it is "crunching" (which will not exceed 100% when summed over blocks) or "active" (which probably will exceed 100% when summed over blocks).

The value of the latter number is it doesn't tell you so much "where" the time is spent, it tells you "why". That can answer questions like "I see that foo is taking a lot of time, but how did I get there?" Same for I/O. That's a process too, it just takes place on other hardware. You don't want to ignore it, because if you do you could end up saying "How come I'm only using a small fraction of the CPU? What's the holdup?"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文