| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4987 人关注过本帖
标题:[求助]C#获取每个进程的CPU利用率??
只看楼主 加入收藏
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
这个应该是DEPHI 版的?反正我看不懂
如何编程得到和控制一个进程的cpu占用率?

...get the CPU usage in percent on Windows NT/2000/XP?

const
SystemBasicInformation = 0;
SystemPerformanceInformation = 2;
SystemTimeInformation = 3;

type
TPDWord = ^DWORD;

TSystem_Basic_Information = packed record
dwUnknown1: DWORD;
uKeMaximumIncrement: ULONG;
uPageSize: ULONG;
uMmNumberOfPhysicalPages: ULONG;
uMmLowestPhysicalPage: ULONG;
uMmHighestPhysicalPage: ULONG;
uAllocationGranularity: ULONG;
pLowestUserAddress: Pointer;
pMmHighestUserAddress: Pointer;
uKeActiveProcessors: ULONG;
bKeNumberProcessors: byte;
bUnknown2: byte;
wUnknown3: word;
end;

type
TSystem_Performance_Information = packed record
liIdleTime: LARGE_INTEGER; {LARGE_INTEGER}
dwSpare: array[0..75] of DWORD;
end;

type
TSystem_Time_Information = packed record
liKeBootTime: LARGE_INTEGER;
liKeSystemTime: LARGE_INTEGER;
liExpTimeZoneBias: LARGE_INTEGER;
uCurrentTimeZoneId: ULONG;
dwReserved: DWORD;
end;

var
NtQuerySystemInformation: function(infoClass: DWORD;
buffer: Pointer;
bufSize: DWORD;
returnSize: TPDword): DWORD; stdcall = nil;


liOldIdleTime: LARGE_INTEGER = ();
liOldSystemTime: LARGE_INTEGER = ();

function Li2Double(x: LARGE_INTEGER): Double;
begin
Result := x.HighPart * 4.294967296E9 + x.LowPart
end;

procedure GetCPUUsage;
var
SysBaseInfo: TSystem_Basic_Information;
SysPerfInfo: TSystem_Performance_Information;
SysTimeInfo: TSystem_Time_Information;
status: Longint; {long}
dbSystemTime: Double;
dbIdleTime: Double;

bLoopAborted : boolean;

begin
if @NtQuerySystemInformation = nil then
NtQuerySystemInformation := GetProcAddress(GetModuleHandle('ntdll.dll'),
'NtQuerySystemInformation');

// get number of processors in the system

status := NtQuerySystemInformation(SystemBasicInformation, @SysBaseInfo, SizeOf(SysBaseInfo), nil);
if status <> 0 then Exit;

// Show some information
with SysBaseInfo do
begin
ShowMessage(
Format('uKeMaximumIncrement: %d'#13'uPageSize: %d'#13+
'uMmNumberOfPhysicalPages: %d'+#13+'uMmLowestPhysicalPage: %d'+#13+
'uMmHighestPhysicalPage: %d'+#13+'uAllocationGranularity: %d'#13+
'uKeActiveProcessors: %d'#13'bKeNumberProcessors: %d',
[uKeMaximumIncrement, uPageSize, uMmNumberOfPhysicalPages,
uMmLowestPhysicalPage, uMmHighestPhysicalPage, uAllocationGranularity,
uKeActiveProcessors, bKeNumberProcessors]));
end;


bLoopAborted := False;

while not bLoopAborted do
begin

// get new system time
status := NtQuerySystemInformation(SystemTimeInformation, @SysTimeInfo, SizeOf(SysTimeInfo), 0);
if status <> 0 then Exit;

// get new CPU's idle time
status := NtQuerySystemInformation(SystemPerformanceInformation, @SysPerfInfo, SizeOf(SysPerfInfo), nil);
if status <> 0 then Exit;

// if it's a first call - skip it
if (liOldIdleTime.QuadPart <> 0) then
begin

// CurrentValue = NewValue - OldValue
dbIdleTime := Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime);
dbSystemTime := Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime);

// CurrentCpuIdle = IdleTime / SystemTime
dbIdleTime := dbIdleTime / dbSystemTime;

// CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
dbIdleTime := 100.0 - dbIdleTime * 100.0 / SysBaseInfo.bKeNumberProcessors + 0.5;

// Show Percentage
Form1.Label1.Caption := FormatFloat('CPU Usage: 0.0 %',dbIdleTime);

Application.ProcessMessages;

// Abort if user pressed ESC or Application is terminated
bLoopAborted := (GetKeyState(VK_ESCAPE) and 128 = 128) or Application.Terminated;

end;

// store new CPU's idle and system time
liOldIdleTime := SysPerfInfo.liIdleTime;
liOldSystemTime := SysTimeInfo.liKeSystemTime;

// wait one second
Sleep(1000);
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
GetCPUUsage
end;

此号自封于2006年11月30日
2006-11-28 10:20
CrazyWeed0907
Rank: 2
等 级:新手上路
威 望:5
帖 子:1385
专家分:0
注 册:2006-5-30
收藏
得分:0 

这不是C的吗/


“十步杀一人,千里不留行。事了拂衣去,深藏身与名。”
2006-11-28 10:22
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
从注册表获取如活动进程数、CPU占用率等信息[1]

在注册表中,有一个分支叫HKEY_DYN_DATA,大量的系统信息都保存在此分支下的PerfStats主键中。

为了获取如CPU的使用率等信息,你需要做三件事:

第一步是开始选择的计数器,可以通过读取相应的注册表主键完成。

例如:
如果我们想知道CPU的占用率,你可以读HKEY_DYN_DATA的这个主键
'PerfStats\StartStat\KERNEL\CPUusage'
这一步是开始计数器

下一步是是读取'PerfStats\StatData\KERNEL\CPUusage'的值,它的值给出了当前CPU的使用率。如果我们将代码放在一个Timer的事件中,我们就可以看到动态的变化了。

最后一步是停止计数器,通过读取注册表的'PerfStats\StopStat\KERNEL\CPUusage'键完成。

除CPU的占用率外,这里还有很多其它的计数器。你可以打开用注册表编辑器打开PerfStats\StatData键,可以看到全部的列表。

我生成了一个构件来获取注册表HKEY_DYN_DATA分支提供的所有计数的值。以下是代码:


此号自封于2006年11月30日
2006-11-28 10:23
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
2

unit SystemInfo;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,extctrls;

type TDialupAdapterInfo = record //Information of Dialup adapter
alignment:dword;
buffer:dword;
bytesrecieved:dword;
bytesXmit:dword;
ConnectSpeed:dword;
CRC:dword;
framesrecieved:dword;
FramesXmit:dword;
Framing:dword;
runts:dword;
Overrun:dword;
timeout:dword;
totalbytesrecieved:dword;
totalbytesXmit:dword;
end;

type TKernelInfo = record
CpuUsagePcnt:dword;
Numthreads:dword;
NumVMS:dword;
end;

type TVCACHEInfo = record
ccurpages:dword;
cMacPages:dword;
cminpages:dword;
FailedRecycles:dword;
Hits:dword;
LRUBuffers:dword;
LRURecycles:dword;
Misses:dword;
RandomRecycles:dword;
end;

type TFATInfo = record
BreadsSec:dword;
BwritesSec:dword;
Dirtydata:dword;
ReadsSec:dword;
WritesSec:dword;
end;

type TVMMInfo = record
CDiscards:dword;
CInstancefaults:dword;
CPageFaults:dword;
cPageIns:dword;
cPageOuts:dword;
cpgCommit:dword;
cpgDiskCache:dword;
cpgDiskCacheMac:dword;
cpgDiskCacheMid:dword;
cpgDiskCacheMin:dword;
cpgfree:dword;

cpglocked:dword;
cpglockedNoncache:dword;
cpgother:dword;
cpgsharedpages:dword;
cpgswap:dword;
cpgswapfile&:dword;
cpgswapfiledefective:dword;
cpgswapfileinuse:dword;
end;

type
TSysInfo = class(TComponent)
private
fDialupAdapterInfo:TDialupAdapterInfo;
fKernelInfo:TKernelInfo;
fVCACHEInfo:TVCACHEInfo;
fFATInfo:TFATInfo;
fVMMInfo:TVMMInfo;
ftimer:TTimer;
fupdateinterval:integer;
tmp:dword;
vsize:dword;
pkey:hkey;
regtype:pdword;
fstopped:boolean;
procedure fupdatinginfo(sender:tobject);
procedure fsetupdateinterval(aupdateinterval:integer);
protected
fsysInfoChanged:TNotifyEvent;
public
constructor Create(Aowner:Tcomponent);override;
destructor Destroy;override;

property DialupAdapterInfo: TDialupAdapterInfo read fDialupAdapterInfo;
property KernelInfo: TKernelInfo read fKernelInfo;
property VCACHEInfo: TVCACHEInfo read fVCACHEInfo;
property FATInfo: TFATInfo read fFATInfo;
property VMMInfo: TVMMInfo read fVMMInfo;
procedure StartRecievingInfo;
procedure StopRecievingInfo;
published
property SysInfoChanged:TNotifyEvent read fsysInfoChanged write
fsysInfoChanged;//this event is called after a specific interval.
property UpdateInterval:integer read fupdateInterval write
fsetupdateinterval default 5000;
end;

procedure Register;

implementation

constructor TSysInfo.Create(Aowner:Tcomponent);
begin
inherited;
ftimer:=ttimer.Create(self);
ftimer.enabled:=false;
ftimer.OnTimer:=fupdatinginfo;
vsize:=4;
fstopped:=true;
end;

procedure TSysInfo.startrecievingInfo;
var
res:integer;
begin
res:=RegOpenKeyEx(HKEY_DYN_DATA,'PerfStats\StartStat',0,KEY_ALL_ACCESS,pkey);
if res<>0 then
raise exception.Create('Could not open registry key');
fstopped:=false;
// For Dial Up Adapter
RegQueryvalueEx(pkey,'Dial-Up Adapter\Alignment',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Buffer',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Framing',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Overrun ',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Timeout',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\CRC',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Runts',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\FramesXmit',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\FramesRecvd',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\BytesXmit',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\BytesRecvd',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\TotalBytesXmit',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\TotalBytesRecvd',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\ConnectSpeed',nil,regtype,@tmp,@vsize);

// For VCACHE
RegQueryvalueEx(pkey,'VCACHE\LRUBuffers',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\FailedRecycles',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\RandomRecycles',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\LRURecycles',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\Misses',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\Hits',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\cMacPages',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\cMinPages',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\cCurPages',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\BytesXmit',nil,regtype,@tmp,@vsize);

//For VFAT

RegQueryvalueEx(pkey,'VFAT\DirtyData',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VFAT\BReadsSec',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VFAT\BWritesSec',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VFAT\ReadsSec',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VFAT\WritesSec',nil,regtype,@tmp,@vsize);
//For VMM

RegQueryvalueEx(pkey,'VMM\cpgLockedNoncache',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgCommit',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSharedPages',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcacheMid',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcacheMac',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcacheMin',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcache',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwapfileDefective',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwapfileInUse',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwapfile',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cDiscards',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cPageOuts',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cPageIns',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cInstanceFaults',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cPageFaults',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgOther',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwap',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgLocked',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgFree',nil,regtype,@tmp,@vsize);
//For KERNEL
RegQueryvalueEx(pkey,'KERNEL\CPUUsage',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'KERNEL\VMs',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'KERNEL\Threads',nil,regtype,@tmp,@vsize);
RegCloseKey(pkey);
ftimer.enabled:=true;
end;


此号自封于2006年11月30日
2006-11-28 10:30
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
3

procedure tsysinfo.fupdatinginfo(sender:tobject);
var
res:integer;
begin
res:=RegOpenKeyEx(HKEY_DYN_DATA,'PerfStats\StatData',0,KEY_ALL_ACCESS,pkey);
if res<>0 then
raise exception.Create('Could not open registry key');
//For Dial Up Adapter
RegQueryvalueEx(pkey,'Dial-Up Adapter\Alignment',nil,regtype,@fDialupAdapterInfo.alignment,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Buffer',nil,regtype,@fDialupAdapterInfo.buffer,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Framing',nil,regtype,@fDialupAdapterInfo.framing,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Overrun ',nil,regtype,@fDialupAdapterInfo.overrun,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Timeout',nil,regtype,@fDialupAdapterInfo.timeout,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\CRC',nil,regtype,@fDialupAdapterInfo.crc,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Runts',nil,regtype,@fDialupAdapterInfo.runts,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\FramesXmit',nil,regtype,@fDialupAdapterInfo.framesxmit,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\FramesRecvd',nil,regtype,@fDialupAdapterInfo.framesrecieved,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\BytesXmit',nil,regtype,@fDialupAdapterInfo.bytesxmit,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\BytesRecvd',nil,regtype,@fDialupAdapterInfo.bytesrecieved,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\TotalBytesXmit',nil,regtype,@fDialupAdapterInfo.totalbytesxmit,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\TotalBytesRecvd',nil,regtype,@fDialupAdapterInfo.totalbytesrecieved,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\ConnectSpeed',nil,regtype,@fDialupAdapterInfo.connectspeed,@vsize);
// For VCACHE
RegQueryvalueEx(pkey,'VCACHE\LRUBuffers',nil,regtype,@fVCACHEInfo.lrubuffers,@vsize);
RegQueryvalueEx(pkey,'VCACHE\FailedRecycles',nil,regtype,@fVCACHEInfo.failedrecycles,@vsize);
RegQueryvalueEx(pkey,'VCACHE\RandomRecycles',nil,regtype,@fVCACHEInfo.randomrecycles,@vsize);
RegQueryvalueEx(pkey,'VCACHE\LRURecycles',nil,regtype,@fVCACHEInfo.lrurecycles,@vsize);
RegQueryvalueEx(pkey,'VCACHE\Misses',nil,regtype,@fVCACHEInfo.misses,@vsize);
RegQueryvalueEx(pkey,'VCACHE\Hits',nil,regtype,@fVCACHEInfo.hits,@vsize);
RegQueryvalueEx(pkey,'VCACHE\cMacPages',nil,regtype,@fVCACHEInfo.cmacpages,@vsize);
RegQueryvalueEx(pkey,'VCACHE\cMinPages',nil,regtype,@fVCACHEInfo.cminpages,@vsize);
RegQueryvalueEx(pkey,'VCACHE\cCurPages',nil,regtype,@fVCACHEInfo.ccurpages,@vsize);
//For VFAT
RegQueryvalueEx(pkey,'VFAT\DirtyData',nil,regtype,@ffatinfo.dirtydata,@vsize);
RegQueryvalueEx(pkey,'VFAT\BReadsSec',nil,regtype,@ffatinfo.breadssec,@vsize);
RegQueryvalueEx(pkey,'VFAT\BWritesSec',nil,regtype,@ffatinfo.bwritessec,@vsize);
RegQueryvalueEx(pkey,'VFAT\ReadsSec',nil,regtype,@ffatinfo.readssec,@vsize);
RegQueryvalueEx(pkey,'VFAT\WritesSec',nil,regtype,@ffatinfo.writessec,@vsize);
//For VMM
RegQueryvalueEx(pkey,'VMM\cpgLockedNoncache',nil,regtype,@fvmminfo.cpglockednoncache,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgCommit',nil,regtype,@fvmminfo.cpgcommit,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSharedPages',nil,regtype,@fvmminfo.cpgsharedpages,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcacheMid',nil,regtype,@fvmminfo.cpgdiskcacheMid,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcacheMac',nil,regtype,@fvmminfo.cpgdiskcacheMac,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcacheMin',nil,regtype,@fvmminfo.cpgdiskcacheMin,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcache',nil,regtype,@fvmminfo.cpgdiskcache,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwapfileDefective',nil,regtype,@fvmminfo.cpgswapfiledefective,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwapfileInUse',nil,regtype,@fvmminfo.cpgswapfileinuse,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwapfile',nil,regtype,@fvmminfo.cpgswapfile,@vsize);
RegQueryvalueEx(pkey,'VMM\cDiscards',nil,regtype,@fvmminfo.cdiscards,@vsize);
RegQueryvalueEx(pkey,'VMM\cPageOuts',nil,regtype,@fvmminfo.cpageouts,@vsize);
RegQueryvalueEx(pkey,'VMM\cPageIns',nil,regtype,@fvmminfo.cpageins,@vsize);
RegQueryvalueEx(pkey,'VMM\cInstanceFaults',nil,regtype,@fvmminfo.cinstancefaults,@vsize);
RegQueryvalueEx(pkey,'VMM\cPageFaults',nil,regtype,@fvmminfo.cpagefaults,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgOther',nil,regtype,@fvmminfo.cpgother,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwap',nil,regtype,@fvmminfo.cpgswap,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgLocked',nil,regtype,@fvmminfo.cpglocked,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgFree',nil,regtype,@fvmminfo.cpgfree,@vsize);
//For KERNEL
RegQueryvalueEx(pkey,'KERNEL\CPUUsage',nil,regtype,@fkernelinfo.cpuusagepcnt,@vsize);
RegQueryvalueEx(pkey,'KERNEL\VMs',nil,regtype,@fkernelinfo.numvms,@vsize);
RegQueryvalueEx(pkey,'KERNEL\Threads',nil,regtype,@fkernelinfo.numThreads,@vsize);
RegCloseKey(pkey);
if assigned(SysInfoChanged) then
SysInfoChanged(self);
end;

procedure TSysInfo.stoprecievingInfo;
var
res:integer;
begin
res:=RegOpenKeyEx(HKEY_DYN_DATA,'PerfStats\StopStat',0,KEY_ALL_ACCESS,pkey);
if not fstopped then
begin
if res<>0 then
raise exception.Create('Could not open registry key');
//For Dial Up Adapter
RegQueryvalueEx(pkey,'Dial-Up Adapter\Alignment',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Buffer',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Framing',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Overrun ',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Timeout',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\CRC',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\Runts',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\FramesXmit',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\FramesRecvd',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\BytesXmit',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\BytesRecvd',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\TotalBytesXmit',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\TotalBytesRecvd',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\ConnectSpeed',nil,regtype,@tmp,@vsize);

// For VCACHE
RegQueryvalueEx(pkey,'VCACHE\LRUBuffers',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\FailedRecycles',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\RandomRecycles',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\LRURecycles',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\Misses',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\Hits',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\cMacPages',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\cMinPages',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VCACHE\cCurPages',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'Dial-Up Adapter\BytesXmit',nil,regtype,@tmp,@vsize);

//For VFAT
RegQueryvalueEx(pkey,'VFAT\DirtyData',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VFAT\BReadsSec',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VFAT\BWritesSec',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VFAT\ReadsSec',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VFAT\WritesSec',nil,regtype,@tmp,@vsize);

//For VMM
RegQueryvalueEx(pkey,'VMM\cpgLockedNoncache',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgCommit',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSharedPages',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcacheMid',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcacheMac',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcacheMin',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgDiskcache',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwapfileDefective',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwapfileInUse',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwapfile',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cDiscards',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cPageOuts',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cPageIns',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cInstanceFaults',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cPageFaults',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgOther',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgSwap',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgLocked',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'VMM\cpgFree',nil,regtype,@tmp,@vsize);

//For KERNEL
RegQueryvalueEx(pkey,'KERNEL\CPUUsage',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'KERNEL\VMs',nil,regtype,@tmp,@vsize);
RegQueryvalueEx(pkey,'KERNEL\Threads',nil,regtype,@tmp,@vsize);

RegCloseKey(pkey);
ftimer.enabled:=false;
fstopped:=true;
end;
end;

procedure tsysinfo.fsetupdateinterval(aupdateinterval:integer);
begin
if (ftimer<>nil) and(aupdateinterval>0) then
begin
ftimer.Interval:=aupdateinterval;
fupdateinterval:=aupdateinterval;
end;
if (ftimer<>nil) and(aupdateinterval=0) then
begin
ftimer.Interval:=500;
fupdateinterval:=500;
end;

end;

destructor tsysinfo.Destroy;
begin
StopRecievingInfo;
ftimer.Destroy;
inherited;
end;

procedure Register;
begin
RegisterComponents('Samples', [TSysInfo]);
end; 转自: neweb.dhcn.net


此号自封于2006年11月30日
2006-11-28 10:30
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
不错,我也要看一下先。

noshow比网络蜘蛛还厉害啊~~!
2006-11-28 10:32
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
以下是引用CrazyWeed0907在2006-11-28 10:22:40的发言:

这不是C的吗/






谁搞明白了 留个言 这些代码都是在网上搜索的

此号自封于2006年11月30日
2006-11-28 10:32
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
以下是引用live41在2006-11-28 10:32:08的发言:
不错,我也要看一下先。

noshow比网络蜘蛛还厉害啊~~!

郁闷坏了 网络上总共就那几个版本 大家COPY来COPY去的 但是我一个也没看懂的说


此号自封于2006年11月30日
2006-11-28 10:33
CrazyWeed0907
Rank: 2
等 级:新手上路
威 望:5
帖 子:1385
专家分:0
注 册:2006-5-30
收藏
得分:0 
delphi我能搞明白
我机器上没有C

“十步杀一人,千里不留行。事了拂衣去,深藏身与名。”
2006-11-28 10:37
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
以下是引用CrazyWeed0907在2006-11-28 10:37:21的发言:
delphi我能搞明白
我机器上没有C

那段代码我用VS调试了半天也没通 放弃了先


此号自封于2006年11月30日
2006-11-28 10:40
快速回复:[求助]C#获取每个进程的CPU利用率??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045685 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved