测量 .NET 应用程序的 JIT 时间

发布于 2024-11-03 05:26:04 字数 188 浏览 1 评论 0原文

我知道您可以使用 NGen 制作本机预.NET 应用程序的编译映像。

但如何衡量应用程序在 JIT 上花费了多少时间呢?我想知道在这样做之前可以节省多少时间。

I'm aware that you can use NGen to make native pre-compiled images of your .NET application.

But how do you measure how much time your application has spent in JIT? I'd like to know how much time is to be saved before doing this.

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

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

发布评论

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

评论(3

晨曦慕雪 2024-11-10 05:26:04

不幸的是,您无法获得“JIT 中的绝对时间”统计数据。 CLR 确实公开了一个定期更新的“% Time in Jit”性能计数器,但它的准确性取决于它选择的采样。

您可以通过 Windows 性能监视器工具或 RedGate 的 ANTS Profiler 等工具轻松访问此性能计数器 - 这就是我第一次接触它的方式。如果您需要以编程方式访问它,您可以使用 WMI 或 .NET PerformanceCounter 类。

Unfortunately there is no "Absolute time in JIT" statistic that you will be able to get. The CLR does expose a "% Time in Jit" performance counter that it updates periodically, but it is only as accurate as it chooses to sample.

You can access this performance counter pretty easily through the Windows Performance Monitor tool or through tools like RedGate's ANTS Profiler--which is how I was first exposed to it. If you need programmatic access to it, you could use WMI or the .NET PerformanceCounter class.

满天都是小星星 2024-11-10 05:26:04

此关于衡量 JIT 影响的文章非常有帮助。基本上,您会使用 NGen 进行热启动场景。冷启动时间通常主要是将 DLL 加载到内存中。 JIT 编译对热启动的影响更大。

关于如何安装 xperf 有点模糊:基本上你想下载 Windows 7 .NET 4 SDK 并确保选择性能工具包。然后以管理员身份打开 VS 2010 命令提示符,更改到要分析的程序的目录并按照本文中的命令进行操作。

其基本要点是,通过 xperf 捕获,您可以深入了解进程并查看 clrjit.dll 花费了多少时间。就我而言,30% 的 CPU 时间花在了热启动上。

This article about measuring JIT impact was very helpful. Basically you would use NGen for warm startup scenarios. Cold startup times are usually dominated by loading the DLLs into memory. JIT compilation has much more impact on warm startup.

It's kind of fuzzy about how to install xperf: basically you want to download the Windows 7 .NET 4 SDK and make sure to select the Performance Toolkit. Then open a VS 2010 command prompt as administrator, change to the directory of the program you want to profile and follow the commands in the article.

The basic gist of it is that with an xperf capture you can then drill down into your process and see how much time was spent in clrjit.dll. In my case 30% of CPU time was spent there on warm startup.

韶华倾负 2024-11-10 05:26:04

从 NET6.0 开始,您可以使用 System.Runtime.JitInfo 静态类来获取概述:

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.jitinfo?view=net-6.0

示例:

Console.WriteLine($"Time: {JitInfo.GetCompilationTime(false)}");
Console.WriteLine($"ILBytes: {JitInfo.GetCompiledILBytes(false)}");
Console.WriteLine($"MethodCount: {JitInfo.GetCompiledMethodCount(false)}");

true 传递给这些方法会返回当前线程的值(而不是全局值)。

Since NET6.0 you can use the System.Runtime.JitInfo static class to get an overview:

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.jitinfo?view=net-6.0

Example:

Console.WriteLine(
quot;Time: {JitInfo.GetCompilationTime(false)}");
Console.WriteLine(
quot;ILBytes: {JitInfo.GetCompiledILBytes(false)}");
Console.WriteLine(
quot;MethodCount: {JitInfo.GetCompiledMethodCount(false)}");

Passing in true to these methods returns values for the current thread (instead of global).

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