如何以编程方式记录 PerformanceCounter

发布于 2024-09-16 01:36:57 字数 402 浏览 2 评论 0原文

据我了解,使用 Perfmon.msc 您可以创建自定义性能计数器,并通过使用计数器日志,您可以将计数器值写入文本文件。

我还了解我还可以通过使用 System.Diagnostics.PerformanceCounter,并使用NextValue()方法获取计数器值。 是否有一种编程方式来告诉 PerformanceCounter 对象将日志写入文本文件(类似于 perfmon.msc 中的计数器日志)?

I understand that using Perfmon.msc you can create a custom performance counter and by using counter log, you can write the counter value to a text file.

I also understand I can also use this programmatically by creating a performance counter by using System.Diagnostics.PerformanceCounter, and get the counter value using NextValue() method.
Is there a programmatical way to tell the PerformanceCounter object to write the log to a text file too (similar to Counter Log in perfmon.msc)?

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

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

发布评论

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

评论(2

心病无药医 2024-09-23 01:36:57

在 .NET 中,您必须自己对计数器进行采样并将采样值写入文件。然而,Win32 API 具有执行您想要的功能的函数。有关本机 API 的示例,请参阅写入性能数据到日志文件。您可以尝试使用 p/invoke 来调用 API。

In .NET you will have to sample the counter yourself and write the sampled value to a file. However, the Win32 API has functions to do what you want. For an example of the native API see Writing Performance Data to a Log File. You could try to use p/invoke to call the API.

我早已燃尽 2024-09-23 01:36:57

按照另一张海报的建议使用 P/Invoke 太麻烦了。我建议使用 logman 从命令行运行 <代码>System.Diagnostics.Process.Start()

Using P/Invoke as suggested by another poster gave too much trouble. I suggest running logman from command line using System.Diagnostics.Process.Start()

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