用adCpuUsage读取CPU使用率为什么会读出负数?(200分)

  • 主题发起人 主题发起人 younghat
  • 开始时间 开始时间
Y

younghat

Unregistered / Unconfirmed
GUEST, unregistred user!
我使用adCpuUsage.pas来读取CPU的使用率,发现在单CPU的机器上一切正常,可是在多CPU的机器上经常会读出负数来,这是怎么回事?该怎么处理?<br>请使用过adCpuUsage的DFW不吝赐教,谢谢。
 
在此附上adCpuUsage.pas源代码,请有条件的帮我分析一下问题出在哪里,不胜感激。<br><br>unit adCpuUsage;<br>{*<br>USAGE:<br><br>1. Include this unit into project.<br><br>2. Call GetCPUCount to obtain the numbr of processors in the system<br><br>3. Each time you need to know the value of CPU usage call the CollectCPUData<br> &nbsp; to refresh the CPU usage information. Then call the GetCPUUsage to obtain<br> &nbsp; the CPU usage for given processor. Note that succesive calls of GetCPUUsage<br> &nbsp; without calling CollectCPUData will return the same CPU usage value.<br><br>Example:<br><br>procedure TTestForm.TimerTimer(Sender: TObject);<br>var i: Integer;<br>begin<br> &nbsp; &nbsp;CollectCPUData; // Get the data for all processors<br><br> &nbsp; &nbsp;for i:=0 to GetCPUCount-1 do // Show data for each processor<br> &nbsp; &nbsp; &nbsp; &nbsp;MInfo.Lines:=Format('CPU #%d - %5.2f%%',[i,GetCPUUsage(i)*100]);<br>end;<br>*}<br><br>interface<br><br>uses<br> &nbsp; &nbsp;Windows, SysUtils;<br><br>// Call CollectCPUData to refresh information about CPU usage<br>procedure CollectCPUData;<br><br>// Call it to obtain the number of CPU's in the system<br>function _GetCPUCount: Integer;<br><br>// Call it to obtain the % of usage for given CPU<br>function _GetCPUUsage(Index: Integer): Double;<br><br>// For Win9x only: call it to stop CPU usage monitoring and free system resources<br>procedure ReleaseCPUData;<br><br>implementation<br><br>{$ifndef ver110}<br><br> &nbsp; &nbsp;{$ifndef ver90}<br> &nbsp; &nbsp;{$ifndef ver100}<br> &nbsp; &nbsp;{$define UseInt64}<br> &nbsp; &nbsp;{$endif}<br> &nbsp; &nbsp;{$endif}<br><br><br> &nbsp; &nbsp;{$ifdef UseInt64}<br> &nbsp; &nbsp;type TInt64 = Int64;<br> &nbsp; &nbsp;{$else}<br> &nbsp; &nbsp;type TInt64 = Comp;<br> &nbsp; &nbsp;{$endif}<br><br>{$else}<br><br> &nbsp; &nbsp;type TInt64 = TLargeInteger;<br><br>{$endif}<br><br>type<br> &nbsp; &nbsp;PInt64 = ^TInt64;<br><br>type<br> &nbsp; &nbsp;TPERF_DATA_BLOCK = record<br> &nbsp; &nbsp; &nbsp; &nbsp;Signature : array[0..4 - 1] of WCHAR;<br> &nbsp; &nbsp; &nbsp; &nbsp;LittleEndian : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;Version : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;Revision : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;TotalByteLength : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;HeaderLength : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;NumObjectTypes : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;DefaultObject : Longint;<br> &nbsp; &nbsp; &nbsp; &nbsp;SystemTime : TSystemTime;<br> &nbsp; &nbsp; &nbsp; &nbsp;Reserved: DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;PerfTime : TInt64;<br> &nbsp; &nbsp; &nbsp; &nbsp;PerfFreq : TInt64;<br> &nbsp; &nbsp; &nbsp; &nbsp;PerfTime100nSec : TInt64;<br> &nbsp; &nbsp; &nbsp; &nbsp;SystemNameLength : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;SystemNameOffset : DWORD;<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;PPERF_DATA_BLOCK = ^TPERF_DATA_BLOCK;<br><br> &nbsp; &nbsp;TPERF_OBJECT_TYPE = record<br> &nbsp; &nbsp; &nbsp; &nbsp;TotalByteLength : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;DefinitionLength : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;HeaderLength : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;ObjectNameTitleIndex : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;ObjectNameTitle : LPWSTR;<br> &nbsp; &nbsp; &nbsp; &nbsp;ObjectHelpTitleIndex : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;ObjectHelpTitle : LPWSTR;<br> &nbsp; &nbsp; &nbsp; &nbsp;DetailLevel : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;NumCounters : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;DefaultCounter : Longint;<br> &nbsp; &nbsp; &nbsp; &nbsp;NumInstances : Longint;<br> &nbsp; &nbsp; &nbsp; &nbsp;CodePage : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;PerfTime : TInt64;<br> &nbsp; &nbsp; &nbsp; &nbsp;PerfFreq : TInt64;<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;PPERF_OBJECT_TYPE = ^TPERF_OBJECT_TYPE;<br><br>type<br> &nbsp; &nbsp;TPERF_COUNTER_DEFINITION = record<br> &nbsp; &nbsp; &nbsp; &nbsp;ByteLength : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;CounterNameTitleIndex : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;CounterNameTitle : LPWSTR;<br> &nbsp; &nbsp; &nbsp; &nbsp;CounterHelpTitleIndex : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;CounterHelpTitle : LPWSTR;<br> &nbsp; &nbsp; &nbsp; &nbsp;DefaultScale : Longint;<br> &nbsp; &nbsp; &nbsp; &nbsp;DetailLevel : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;CounterType : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;CounterSize : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;CounterOffset : DWORD;<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;PPERF_COUNTER_DEFINITION = ^TPERF_COUNTER_DEFINITION;<br><br> &nbsp; &nbsp;TPERF_COUNTER_BLOCK = record<br> &nbsp; &nbsp; &nbsp; &nbsp;ByteLength : DWORD;<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;PPERF_COUNTER_BLOCK = ^TPERF_COUNTER_BLOCK;<br><br> &nbsp; &nbsp;TPERF_INSTANCE_DEFINITION = record<br> &nbsp; &nbsp; &nbsp; &nbsp;ByteLength : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;ParentObjectTitleIndex : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;ParentObjectInstance : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;UniqueID : Longint;<br> &nbsp; &nbsp; &nbsp; &nbsp;NameOffset : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;NameLength : DWORD;<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;PPERF_INSTANCE_DEFINITION = ^TPERF_INSTANCE_DEFINITION;<br><br>//------------------------------------------------------------------------------<br>{$ifdef ver130}<br>{$L-} &nbsp; &nbsp; &nbsp; &nbsp; // The L+ causes internal error in Delphi 5 compiler<br>{$O-} &nbsp; &nbsp; &nbsp; &nbsp; // The O+ causes internal error in Delphi 5 compiler<br>{$Y-} &nbsp; &nbsp; &nbsp; &nbsp; // The Y+ causes internal error in Delphi 5 compiler<br>{$endif}<br><br>{$ifndef ver110}<br>type<br> &nbsp; &nbsp;TInt64F = TInt64;<br>{$else}<br>type<br> &nbsp; &nbsp;TInt64F = Extended;<br>{$endif}<br><br>{$ifdef ver110}<br>function FInt64(Value: TInt64): TInt64F;<br>function Int64D(Value: DWORD): TInt64;<br>{$else}<br>type<br> &nbsp; &nbsp;FInt64 = TInt64F;<br> &nbsp; &nbsp;Int64D = TInt64;<br>{$endif}<br><br>{$ifdef ver110}<br>function FInt64(Value: TInt64): TInt64F;<br>var V: TInt64;<br>begin<br> &nbsp; &nbsp;if (Value.HighPart and $80000000) = 0 then // positive value<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;result:=Value.HighPart;<br> &nbsp; &nbsp; &nbsp; &nbsp;result:=result*$10000*$10000;<br> &nbsp; &nbsp; &nbsp; &nbsp;result:=result+Value.LowPart;<br> &nbsp; &nbsp;end else<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;V.HighPart:=Value.HighPart xor $FFFFFFFF;<br> &nbsp; &nbsp; &nbsp; &nbsp;V.LowPart:=Value.LowPart xor $FFFFFFFF;<br> &nbsp; &nbsp; &nbsp; &nbsp;result:= -1 - FInt64(V);<br> &nbsp; &nbsp;end;<br>end;<br><br>function Int64D(Value: DWORD): TInt64;<br>begin<br> &nbsp; &nbsp;result.LowPart:=Value;<br> &nbsp; &nbsp;result.HighPart := 0; // positive only<br>end;<br>{$endif}<br><br>//------------------------------------------------------------------------------<br><br>const<br> &nbsp; &nbsp;Processor_IDX_Str = '238';<br> &nbsp; &nbsp;Processor_IDX = 238;<br> &nbsp; &nbsp;CPUUsageIDX = 6;<br><br>type<br> &nbsp; &nbsp;AInt64F = array[0..$FFFF] of TInt64F;<br> &nbsp; &nbsp;PAInt64F = ^AInt64F;<br><br>var<br> &nbsp; &nbsp;_PerfData : PPERF_DATA_BLOCK;<br> &nbsp; &nbsp;_BufferSize: Integer;<br> &nbsp; &nbsp;_POT : PPERF_OBJECT_TYPE;<br> &nbsp; &nbsp;_PCD: PPerf_Counter_Definition;<br> &nbsp; &nbsp;_ProcessorsCount: Integer;<br> &nbsp; &nbsp;_Counters: PAInt64F;<br> &nbsp; &nbsp;_PrevCounters: PAInt64F;<br> &nbsp; &nbsp;_SysTime: TInt64F;<br> &nbsp; &nbsp;_PrevSysTime: TInt64F;<br> &nbsp; &nbsp;_IsWinNT: Boolean;<br><br> &nbsp; &nbsp;_W9xCollecting: Boolean;<br> &nbsp; &nbsp;_W9xCpuUsage: DWORD;<br> &nbsp; &nbsp;_W9xCpuKey: HKEY;<br><br><br>//------------------------------------------------------------------------------<br>function _GetCPUCount: Integer;<br>begin<br> &nbsp; &nbsp;if _IsWinNT then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if _ProcessorsCount &lt; 0 then CollectCPUData;<br> &nbsp; &nbsp; &nbsp; &nbsp;result:=_ProcessorsCount;<br> &nbsp; &nbsp;end else<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;result:=1;<br> &nbsp; &nbsp;end;<br><br>end;<br><br>//------------------------------------------------------------------------------<br>procedure ReleaseCPUData;<br>var H: HKEY;<br> &nbsp; &nbsp;R: DWORD;<br> &nbsp; &nbsp;dwDataSize, dwType: DWORD;<br>begin<br> &nbsp; &nbsp;if _IsWinNT then exit;<br> &nbsp; &nbsp;if not _W9xCollecting then exit;<br> &nbsp; &nbsp;_W9xCollecting:=False;<br><br> &nbsp; &nbsp;RegCloseKey(_W9xCpuKey);<br><br> &nbsp; &nbsp;R:=RegOpenKeyEx( HKEY_DYN_DATA, 'PerfStats/StopStat', 0, KEY_ALL_ACCESS, H );<br><br> &nbsp; &nbsp;if R &lt;&gt; ERROR_SUCCESS then exit;<br><br> &nbsp; &nbsp;dwDataSize:=sizeof(DWORD);<br><br> &nbsp; &nbsp;RegQueryValueEx ( H, 'KERNEL/CPUUsage', nil, @dwType, PBYTE(@_W9xCpuUsage), @dwDataSize);<br><br> &nbsp; &nbsp;RegCloseKey(H);<br><br>end;<br><br>//------------------------------------------------------------------------------<br>function _GetCPUUsage(Index: Integer): Double;<br>begin<br> &nbsp; &nbsp;if _IsWinNT then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if _ProcessorsCount &lt; 0 then CollectCPUData;<br> &nbsp; &nbsp; &nbsp; &nbsp;if (Index &gt;= _ProcessorsCount) or (Index &lt; 0) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise Exception.Create('CPU index out of bounds');<br> &nbsp; &nbsp; &nbsp; &nbsp;if _PrevSysTime = _SysTime then result:=0 else<br> &nbsp; &nbsp; &nbsp; &nbsp;result:=1-(_Counters[index] - _PrevCounters[index])/(_SysTime-_PrevSysTime);<br> &nbsp; &nbsp;end else<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if Index &lt;&gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise Exception.Create('CPU index out of bounds');<br> &nbsp; &nbsp; &nbsp; &nbsp;if not _W9xCollecting then CollectCPUData;<br> &nbsp; &nbsp; &nbsp; &nbsp;result:=_W9xCpuUsage / 100;<br> &nbsp; &nbsp;end;<br>end;<br><br>var VI: TOSVERSIONINFO;<br><br>//------------------------------------------------------------------------------<br>procedure CollectCPUData;<br>var BS: integer;<br> &nbsp; &nbsp;i: Integer;<br> &nbsp; &nbsp;_PCB_Instance: PPERF_COUNTER_BLOCK;<br> &nbsp; &nbsp;_PID_Instance: PPERF_INSTANCE_DEFINITION;<br> &nbsp; &nbsp;ST: TFileTime;<br><br>var H: HKEY;<br> &nbsp; &nbsp;R: DWORD;<br> &nbsp; &nbsp;dwDataSize, dwType: DWORD;<br>begin<br> &nbsp; &nbsp;if _IsWinNT then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;BS:=_BufferSize;<br> &nbsp; &nbsp; &nbsp; &nbsp;while RegQueryValueEx( HKEY_PERFORMANCE_DATA, Processor_IDX_Str, nil, nil,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PByte(_PerfData), @BS ) = ERROR_MORE_DATA do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Get a buffer that is big enough.<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;INC(_BufferSize,$1000);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BS:=_BufferSize;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ReallocMem( _PerfData, _BufferSize );<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp;// Locate the performance object<br> &nbsp; &nbsp; &nbsp; &nbsp;_POT := PPERF_OBJECT_TYPE(DWORD(_PerfData) + _PerfData.HeaderLength);<br> &nbsp; &nbsp; &nbsp; &nbsp;for i := 1 to _PerfData.NumObjectTypes do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if _POT.ObjectNameTitleIndex = Processor_IDX then Break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_POT := PPERF_OBJECT_TYPE(DWORD(_POT) + _POT.TotalByteLength);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp;// Check for success<br> &nbsp; &nbsp; &nbsp; &nbsp;if _POT.ObjectNameTitleIndex &lt;&gt; Processor_IDX then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise Exception.Create('Unable to locate the &quot;Processor&quot; performance object');<br><br> &nbsp; &nbsp; &nbsp; &nbsp;if _ProcessorsCount &lt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_ProcessorsCount:=_POT.NumInstances;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetMem(_Counters,_ProcessorsCount*SizeOf(TInt64));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetMem(_PrevCounters,_ProcessorsCount*SizeOf(TInt64));<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp;// Locate the &quot;% CPU usage&quot; counter definition<br> &nbsp; &nbsp; &nbsp; &nbsp;_PCD := PPERF_Counter_DEFINITION(DWORD(_POT) + _POT.HeaderLength);<br> &nbsp; &nbsp; &nbsp; &nbsp;for i := 1 to _POT.NumCounters do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if _PCD.CounterNameTitleIndex = CPUUsageIDX then break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_PCD := PPERF_COUNTER_DEFINITION(DWORD(_PCD) + _PCD.ByteLength);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp;// Check for success<br> &nbsp; &nbsp; &nbsp; &nbsp;if _PCD.CounterNameTitleIndex &lt;&gt; CPUUsageIDX then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise Exception.Create('Unable to locate the &quot;% of CPU usage&quot; performance counter');<br><br> &nbsp; &nbsp; &nbsp; &nbsp;// Collecting coutners<br> &nbsp; &nbsp; &nbsp; &nbsp;_PID_Instance := PPERF_INSTANCE_DEFINITION(DWORD(_POT) + _POT.DefinitionLength);<br> &nbsp; &nbsp; &nbsp; &nbsp;for i := 0 to _ProcessorsCount-1 do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_PCB_Instance := PPERF_COUNTER_BLOCK(DWORD(_PID_Instance) + _PID_Instance.ByteLength );<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_PrevCounters:=_Counters;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_Counters:=FInt64(PInt64(DWORD(_PCB_Instance) + _PCD.CounterOffset)^);<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_PID_Instance := PPERF_INSTANCE_DEFINITION(DWORD(_PCB_Instance) + _PCB_Instance.ByteLength);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp;_PrevSysTime:=_SysTime;<br> &nbsp; &nbsp; &nbsp; &nbsp;SystemTimeToFileTime(_PerfData.SystemTime, ST);<br> &nbsp; &nbsp; &nbsp; &nbsp;_SysTime:=FInt64(TInt64(ST));<br> &nbsp; &nbsp;end else<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if not _W9xCollecting then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;R:=RegOpenKeyEx( HKEY_DYN_DATA, 'PerfStats/StartStat', 0, KEY_ALL_ACCESS, H );<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if R &lt;&gt; ERROR_SUCCESS then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise Exception.Create('Unable to start performance monitoring');<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dwDataSize:=sizeof(DWORD);<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RegQueryValueEx( H, 'KERNEL/CPUUsage', nil, @dwType, PBYTE(@_W9xCpuUsage), @dwDataSize );<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RegCloseKey(H);<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;R:=RegOpenKeyEx( HKEY_DYN_DATA, 'PerfStats/StatData', 0,KEY_READ, _W9xCpuKey );<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if R &lt;&gt; ERROR_SUCCESS then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise Exception.Create('Unable to read performance data');<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_W9xCollecting:=True;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp;dwDataSize:=sizeof(DWORD);<br> &nbsp; &nbsp; &nbsp; &nbsp;RegQueryValueEx( _W9xCpuKey, 'KERNEL/CPUUsage', nil,@dwType, PBYTE(@_W9xCpuUsage), @dwDataSize );<br> &nbsp; &nbsp;end;<br>end;<br><br><br>initialization<br> &nbsp; &nbsp;_ProcessorsCount:= -1;<br> &nbsp; &nbsp;_BufferSize:= $2000;<br> &nbsp; &nbsp;_PerfData := AllocMem(_BufferSize);<br><br> &nbsp; &nbsp;VI.dwOSVersionInfoSize:=SizeOf(VI);<br> &nbsp; &nbsp;if not GetVersionEx(VI) then raise Exception.Create('Can''t get the Windows version');<br><br> &nbsp; &nbsp;_IsWinNT := VI.dwPlatformId = VER_PLATFORM_WIN32_NT;<br>finalization<br> &nbsp; &nbsp;ReleaseCPUData;<br> &nbsp; &nbsp;FreeMem(_PerfData);<br>end.
 
后退
顶部