栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

什么是获得进程的CPU和内存使用率的正确性能计数器?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

什么是获得进程的CPU和内存使用率的正确性能计数器?

从这篇文章:

要获取整个PC的CPU和内存使用情况:

using System.Diagnostics;

然后全局声明:

private PerformanceCounter theCPUCounter =    new PerformanceCounter("Processor", "% Processor Time", "_Total");

然后,要获取CPU时间,只需调用

NextValue()
方法:

this.theCPUCounter.NextValue();

这将使您获得CPU使用率

至于内存使用,我相信同样的事情:

private PerformanceCounter theMemCounter =    new PerformanceCounter("Memory", "Available MBytes");

然后,要获取内存使用情况,只需调用

NextValue()
方法:

this.theMemCounter.NextValue();

对于特定的进程CPU和内存使用情况:

private PerformanceCounter theCPUCounter =    new PerformanceCounter("Process", "% Processor Time",      Process.GetCurrentProcess().ProcessName);

Process.GetCurrentProcess().ProcessName
您希望获取有关信息的进程名称在哪里?

private PerformanceCounter theMemCounter =    new PerformanceCounter("Process", "Working Set",   Process.GetCurrentProcess().ProcessName);

Process.GetCurrentProcess().ProcessName
您希望获取有关信息的进程名称在哪里?

请注意, 工作集本身可能不足以确定进程的内存占用量
-请参阅什么是专用字节,虚拟字节,工作集?

要检索所有类别,请参阅 演练:检索类别和计数器

之间的差异

Processor% Processor Time
,并
Process% ProcessorTime
Processor
从PC本身
Process
是每个个体的过程。因此,处理器的处理器时间将是PC上的使用时间。进程的处理器时间将是指定的进程使用率。有关类别名称的完整说明:性能监视器计数器

使用性能计数器的替代方法

使用System.Diagnostics.Process.TotalProcessorTime和System.Diagnostics.ProcessThread.TotalProcessorTime属性来计算您的处理器使用率,如本文所述。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/442732.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号