问题描述
我的工作将运行很长一段时间的一种后台程序,我有一个外部记录程序(),我要周期性地与一些值来养活,要调试时监视它在实时。
I am working on a background program that will be running for a long time, and I have a external logging program (SmartInspect) that I want to feed with some values periodically, to monitor it in realtime when debugging.
我知道我可以简单地火了多个程序,如任务经理或IARSN TaskInfo,但我希望把一切都在我的计划,这一点,因为我也想添加一些简单的规则一样,如果程序不是X%的CPU使用更多的,在日志中标记此。
I know I can simply fire up multiple programs, like the Task Manager, or IARSN TaskInfo, but I'd like to keep everything in my own program for this, as I also wants to add some simple rules like if the program uses more than X% CPU, flag this in the log.
我有一个后台线程定期供稿一些统计数据来SmartInspect,如内存消耗,工作组等。
I have a background thread that periodically feeds some statistics to SmartInspect, like memory consumption, working set, etc.
时有可能为这个线程得到它是如何计算机的CPU资源的消耗多少合理准确的衡量?主程序是单线程应用程序(除了它记录统计看门狗线程),所以如果一个技术限制的需要多少使用单个线程的那么这将是一件好事。
Is it possible for this thread to get a reasonably accurate measure of how much of the computer's CPU resources it consumes? The main program is a single-threaded application (apart from the watchdog thread that logs statistics) so if a technique is limited to how much does a single thread use then that would be good too.
我发现与一些所谓的某些条目的 rusage 的Linux和C.是否有类似的东西我可以用这个?
I found some entries related to something called rusage for Linux and C. Is there something similar I can use for this?
修改确定,我试过的性能计数器的方式,但它增加了一个相当很多所谓的每一次GC-数据,因此对于内存使用情况的图形和垃圾收集的暴涨。我想我就离开这个部分了,现在
Ok, I tried the performance counter way, but it added quite a lot of GC-data each time called, so the graph for memory usage and garbage collection skyrocketed. I guess I'll just leave this part out for now.
推荐答案
您还可以使用的和的属性来计算你的处理器用法这介绍。
You can also use System.Diagnostics.Process.TotalProcessorTime and System.Diagnostics.ProcessThread.TotalProcessorTime properties to calculate your processor usage as this article describes.
这篇关于C#程序可以以某种方式衡量自己的CPU使用率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!