Z
zhjwjan
Unregistered / Unconfirmed
GUEST, unregistred user!
我抄了一段程序获得cpu占用率,但显示cpu使用率总是1245048%,请问哪里不对?
procedure TForm1.Button1Click(Sender: TObject);
var
Dummy : array[0..1024] of byte;
begin
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_DYN_DATA; //统计数据在这个表项下
Reg.OpenKey('PerfStats/StartStat',false);
Reg.ReadBinaryData('KERNEL/CPUUsage',Dummy,Sizeof(Dummy));
Reg.CloseKey;
started:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Dummy : array[0..1024] of byte;
begin
Reg.OpenKey('PerfStats/StopStat',false);
Reg.ReadBinaryData('KERNEL/CPUUsage',Dummy,SizeOf(Dummy));
Reg.Free;
Started:=false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
CPUU : integer;
begin
if started then
begin
Reg.OpenKey('PerfStats/StatData',false);
Reg.ReadBinaryData('KERNEL/CPUUsage',CPUU,SizeOf(Integer));
Reg.CloseKey;
Label1.Caption:=IntToStr(CPUU)+'%';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Dummy : array[0..1024] of byte;
begin
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_DYN_DATA; //统计数据在这个表项下
Reg.OpenKey('PerfStats/StartStat',false);
Reg.ReadBinaryData('KERNEL/CPUUsage',Dummy,Sizeof(Dummy));
Reg.CloseKey;
started:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Dummy : array[0..1024] of byte;
begin
Reg.OpenKey('PerfStats/StopStat',false);
Reg.ReadBinaryData('KERNEL/CPUUsage',Dummy,SizeOf(Dummy));
Reg.Free;
Started:=false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
CPUU : integer;
begin
if started then
begin
Reg.OpenKey('PerfStats/StatData',false);
Reg.ReadBinaryData('KERNEL/CPUUsage',CPUU,SizeOf(Integer));
Reg.CloseKey;
Label1.Caption:=IntToStr(CPUU)+'%';
end;
end;