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.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.Button2Click(Sender: TObject);
var
Dummy : array[0..1024] of byte;
begin
'PerfStats/StopStat' }
Reg.OpenKey('PerfStats\StopStat',false);
Reg.ReadBinaryData('KERNEL\CPUUsage',Dummy,SizeOf(Dummy));
Reg.Free;
Started:=false;
end;
type
TForm1 = class(TForm)
Label1 : TLabel;
procedure Label1Click(Sender: TObject);
procedure Label1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1 : TForm1;
stop : boolean;
implementation
{$R *.DFM}
function GetCPUSpeed : Double;
const
DelayTime = 500; // measure time in ms
var
TimerHi, TimerLo : DWORD;
PriorityClass, Priority : Integer;
begin
PriorityClass := GetPriorityClass(GetCurrentProcess);
Priority := GetThreadPriority(GetCurrentThread);
procedure TForm1.Label1Click(Sender: TObject);
begin
Stop := False;
while not Stop do
begin
label1.Caption := Format('CPU speed: %f MHz',
[GetCPUSpeed]);
Application.ProcessMessages;
end;
end;
procedure TForm1.Label1DblClick(Sender: TObject);
begin
Stop := True;
end;
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
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