特定过程的性能计数器功能 [英] Performance Counter Function for specific process

查看:80
本文介绍了特定过程的性能计数器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI朋友,

i我正在使用下面提到的功能是我计算的整体CPU使用率



但是我希望功能在i中我会传递进程名称作为参数并获取cpu使用率,Ram使用率和胎面。



请帮助完成这项任务



HI Friends,
i am using function below mention is which i have calculate overall CPU usage

but i want function in i will pass process name as parameter and get cpu usage, Ram usage and tread.

please help for this task

private void CalcCpu()
{
    // refresh delay 1.5 seconds    
    int RefreshInterval = 1500; 
    // keeps the previous usage value.
    long OldRawUsageValue = GetCurrentUsageValue(); 
    // keeps the current usage value.
    long NewRawUsageValue;
    // holds the cpu usage in a friendly reading way. 
    string CpuUsage; 

    Thread.Sleep(RefreshInterval);

    while (KeepCalculation)
    {
        NewRawUsageValue = GetCurrentUsageValue();
        CpuUsage = ((int)((NewRawUsageValue - OldRawUsageValue) / 
                                  RefreshInterval)).ToString() + "%";
        Thread.Sleep(RefreshInterval);
        OldRawUsageValue = NewRawUsageValue;
    }
}

推荐答案

本文 [ ^ ]用于阅读性能计数器。



具体代码它的用途是: -



There is code in this article[^] for reading performance counters.

The specific code it uses is:-

Imports System.Diagnostics

If PerformanceCounterCategory.InstanceExists( applicationInstanceName , "% Processor Time") Then
  ' Code to use that performance counter....

End If





我建议你不要使用Thread.Sleep虽然...



I would recommend you do NOT use Thread.Sleep though...


亲爱的简单函数,其中作为参数传递进程名称获取该特定进程的CPU使用率
Dear It simple function in which as parameter pass process name get return CPU Usage for that particular process


这篇关于特定过程的性能计数器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆