Q&A

  • CPU 사용률을 구하는데 잘 않되내요..
김영대님의 홈페이지에서 보았는데..

레지스트리의..

HKEY_DYN_DATAPerfStatsStatDataKERNELCPUUsage

여기에 사용률이 표시가 된다는 정보를 얻었습니다..

역시 사용률이 잘 되는것 같았습니다..

그런데 정상적으로 레지스트리에 사용률이 표시되지 않을때가 있습니다.

그러니까 계속 100으로 나올때가 있는데..

처음 컴퓨터를 켜서 저기의 값을 읽어보면 16진수 64(10진수 100)이 나옴니다.

CPU의 부하를 주던 아무 일도 하지않던 계속 100이나오다가..

레지스트리 에디터를 돌려서

HKEY_DYN_DATAPerfStatsStartSrvKERNELCPUUsage

StartStat,

StatData,

StopSrv,

StopStat

이 부문의 데이타들 읽다보면 어느순간부터 또 정상적인 CPU 사용률이

읽혀 집니다...

외 그럴까요??..

다른분은 사용률을 어떻게 구하고 계신지??.

아니면 제가 레지스트리를 잘못 읽고 있는것인지..

제가 레지스트리를 읽었던 소스를 같이 보냅니다.



//====

function ReadRegistryStr(ROOTKEY :HKEY;RegPath,InfoStr:string):string;

var

retstring, BinDataStr,_1Byte : string;

reg : TRegistry;

RegDataType : TregDataType;

i,ReadInteger,readbyte : integer;

buf, bufPtr: PChar;

begin

readbyte :=0;

retstring := '';

try

reg := TRegistry.Create;

if (ROOTKEY = HKEY(nil)) then begin

reg.RootKey := HKEY_CURRENT_USER;

end else begin

reg.RootKey :=ROOTKEY;

end;

reg.OpenKey(RegPath, false);

RegDataType :=reg.GetDataType(InfoStr);

readbyte := reg.GetDataSize(InfoStr);

if (rdString = RegDataType) or(rdExpandString = RegDataType) then begin

retstring := reg.ReadString(InfoStr);

end else

if rdInteger = RegDataType then begin

ReadInteger := reg.ReadInteger(InfoStr);

retstring := inttostr(ReadInteger);

end else

if rdBinary = RegDataType then begin

BinDataStr :=''; _1Byte :='';

GetMem(buf, readbyte);

bufPtr := buf;

reg.ReadBinaryData( InfoStr, buf^ , readbyte);

for i := 0 to readbyte-1 do begin

try

FmtStr(_1Byte, '%X', [Integer(buf^)]);

// if Length(_1Byte) = 1 then _1Byte := '0'+_1Byte;

except

// Application.MessageBox('Can not read binary register data', 'oop', mb_Ok);

end;

buf := buf + 1;

if i = 0 then begin

BinDataStr := _1Byte;

end else BinDataStr := BinDataStr + ' ' + _1Byte;



end;

FreeMem(bufPtr);

retstring := BinDataStr;

end else begin

// showmessage('타입알수없음');

retstring :='';

end;

reg.CloseKey;

finally

reg.free;

end;

result := retstring;

end;











function CPUUsage:integer;

var

retint : integer;

regpath ,temp: string;

temparray: array[0..255] of char;

begin

try

regpath := 'PerfStatsStatData';

//regpath := 'PerfStatsStartStat';

temp := ReadRegistryStr(HKEY_DYN_DATA,regpath,'KERNELCPUUsage');

strpcopy(temparray, temp);

temparray[2] :=char( 0);

retint :=hex2int(strpas(temparray));

except

retint :=0;

end;

result := retint;

end;





0  COMMENTS