home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kompon / d2345 / MSYSINFO.ZIP / Source / MiTeC_PerfLib9x.pas < prev    next >
Pascal/Delphi Source File  |  2001-06-25  |  6KB  |  214 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       MiTeC System Information Component              }
  5. {           Performance Library for Win9x               }
  6. {           version 5.6 for Delphi 3,4,5                }
  7. {                                                       }
  8. {       Copyright ⌐ 1997,2001 Michal Mutl               }
  9. {                                                       }
  10. {*******************************************************}
  11.  
  12. {$INCLUDE MITEC_DEF.INC}
  13.  
  14. unit MiTeC_PerfLib9x;
  15.  
  16. interface
  17.  
  18. uses Windows, Classes, SysUtils, Registry;
  19.  
  20. type
  21.   TPerfLib9x = class(TPersistent)
  22.   private
  23.     FActive   : Boolean;
  24.     FRegistry : TRegistry;
  25.     FCounters: TStringList;
  26.     function GetSysData(Key: string): Integer;
  27.     function GetSysDataDesc(Key: string): string;
  28.     function GetSysDataName(Key: string): string;
  29.     function GetSysDataDiff(Key: string): boolean;
  30.     procedure GetSysCounters;
  31.   public
  32.     procedure Open;
  33.     procedure Close;
  34.     constructor Create;
  35.     destructor Destroy; override;
  36.     property Names: TStringList read FCounters;
  37.     property SysData[Key: string]: Integer read GetSysData;
  38.     property SysDataDesc[Key: string]: string read GetSysDataDesc;
  39.     property SysDataName[Key: string]: string read GetSysDataName;
  40.     property SysDataDiff[Key: string]: boolean read GetSysDataDiff;
  41.     property Active: Boolean read FActive;
  42.   end;
  43.  
  44. const
  45.   cPerfIndex95 = {HKEY_LOCAL_MACHINE\}'System\CurrentControlSet\Control\PerfStats\Enum';
  46.   cPerfData95 = {HKEY_DYN_DATA\}'PerfStats\StatData';
  47.   cPerfStart95 = {HKEY_DYN_DATA\}'PerfStats\StartStat';
  48.   cPerfStop95 = {HKEY_DYN_DATA\}'PerfStats\StopStat';
  49.  
  50. implementation
  51.  
  52. { TPerfLib9x }
  53.  
  54. procedure TPerfLib9x.Close;
  55. var
  56.   KeysList : TStringList;
  57.   i        : Integer;
  58.   Dummy    : Integer;
  59. begin
  60.   if (FActive) then
  61.     with FRegistry do begin
  62.       RootKey := HKEY_DYN_DATA;
  63.       if OpenKeyReadOnly(cPerfStop95) then begin
  64.         KeysList := TStringList.Create;
  65.         try
  66.           GetValueNames(KeysList);
  67.           for i:=0 to KeysList.Count-1 do
  68.             ReadBinaryData(KeysList.Strings[i], Dummy, 4);
  69.         finally
  70.           KeysList.Free;
  71.         end;
  72.         FActive := False;
  73.         CloseKey;
  74.       end;
  75.     end;
  76. end;
  77.  
  78. constructor TPerfLib9x.Create;
  79. begin
  80.   FActive:=False;
  81.   FRegistry:=TRegistry.Create;
  82.   FCounters:=TStringList.Create;
  83.   GetSysCounters;
  84. end;
  85.  
  86. destructor TPerfLib9x.Destroy;
  87. begin
  88.   Close;
  89.   FRegistry.Free;
  90.   FCounters.Free;
  91.   inherited;
  92. end;
  93.  
  94. procedure TPerfLib9x.GetSysCounters;
  95. begin
  96.   with FRegistry do begin
  97.     RootKey := HKEY_DYN_DATA;
  98.     if OpenKeyReadOnly(cPerfData95) then begin
  99.       GetValueNames(FCounters);
  100.       CloseKey;
  101.     end else
  102.       raise Exception.Create('Error opening key: '+cPerfData95);
  103.   end;
  104. end;
  105.  
  106. function TPerfLib9x.GetSysData(Key: string): Integer;
  107. begin
  108.   with FRegistry do begin
  109.     RootKey := HKEY_DYN_DATA;
  110.     if OpenKeyReadOnly(cPerfData95) then begin
  111.       ReadBinaryData(Key, Result, 4);
  112.       CloseKey;
  113.     end else
  114.       raise Exception.Create('Error opening key: '+Key);
  115.   end;
  116. end;
  117.  
  118. function TPerfLib9x.GetSysDataDesc(Key: string): string;
  119. var
  120.   akey,avalue :string;
  121.   p :integer;
  122. begin
  123.   with FRegistry do begin
  124.     RootKey := HKEY_LOCAL_MACHINE;
  125.     p:=pos('\',key);
  126.     if p>0 then begin
  127.       akey:=cPerfIndex95+'\'+copy(key,1,p-1)+'\'+copy(key,p+1,255);
  128.       avalue:='Description';
  129.     end else begin
  130.       akey:=cPerfIndex95+'\'+key;
  131.       avalue:='Name';
  132.     end;
  133.     if OpenKeyReadOnly(akey) then begin
  134.       result:=ReadString(avalue);
  135.       CloseKey;
  136.     end else
  137.       raise Exception.Create('Error opening key: '+Key);
  138.   end;
  139. end;
  140.  
  141. function TPerfLib9x.GetSysDataDiff(Key: string): boolean;
  142. var
  143.   akey,avalue :string;
  144.   p :integer;
  145. begin
  146.   with FRegistry do begin
  147.     RootKey := HKEY_LOCAL_MACHINE;
  148.     p:=pos('\',key);
  149.     if p>0 then begin
  150.       akey:=cPerfIndex95+'\'+copy(key,1,p-1)+'\'+copy(key,p+1,255);
  151.       avalue:='Differentiate';
  152.       if OpenKeyReadOnly(akey) then begin
  153.         if ReadString(avalue)='TRUE' then
  154.           result:=true
  155.         else
  156.           result:=false;
  157.         CloseKey;
  158.       end else
  159.         raise Exception.Create('Error opening key: '+Key);
  160.     end else begin
  161.       result:=false;
  162.     end;
  163.   end;
  164. end;
  165.  
  166. function TPerfLib9x.GetSysDataName(Key: string): string;
  167. var
  168.   akey,avalue :string;
  169.   p :integer;
  170. begin
  171.   with FRegistry do begin
  172.     RootKey := HKEY_LOCAL_MACHINE;
  173.     p:=pos('\',key);
  174.     if p>0 then begin
  175.       akey:=cPerfIndex95+'\'+copy(key,1,p-1)+'\'+copy(key,p+1,255);
  176.       avalue:='Name';
  177.     end else begin
  178.       akey:=cPerfIndex95+'\'+key;
  179.       avalue:='Name';
  180.     end;
  181.     if OpenKeyReadOnly(akey) then begin
  182.       result:=ReadString(avalue);
  183.       CloseKey;
  184.     end else
  185.       raise Exception.Create('Error opening key: '+Key);
  186.   end;
  187. end;
  188.  
  189. procedure TPerfLib9x.Open;
  190. var
  191.   KeysList : TStringList;
  192.   i        : Integer;
  193.   Dummy    : Integer;
  194. begin
  195.   if (not FActive) then
  196.     with FRegistry do begin
  197.       RootKey := HKEY_DYN_DATA;
  198.       if OpenKeyReadOnly(cPerfStart95) then begin
  199.         KeysList := TStringList.Create;
  200.         try
  201.           GetValueNames(KeysList);
  202.           for i:=0 to KeysList.Count-1 do
  203.             ReadBinaryData(KeysList.Strings[i], Dummy, 4);
  204.         finally
  205.          KeysList.Free;
  206.         end;
  207.         FActive := True;
  208.         CloseKey;
  209.       end;
  210.     end;
  211. end;
  212.  
  213. end.
  214.