📄 jvqperfmon95.pas
字号:
{******************************************************************************}
{* WARNING: JEDI VCL To CLX Converter generated unit. *}
{* Manual modifications will be lost on next release. *}
{******************************************************************************}
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvPerfMon95.PAS, released Dec 26, 1999.
The Initial Developer of the Original Code is Petr Vones (petr dott v att mujmail dott cz)
Portions created by Petr Vones are Copyright (C) 1999 Petr Vones.
Portions created by Microsoft are Copyright (C) 1998, 1999 Microsoft Corp.
All Rights Reserved.
Contributor(s): ______________________________________.
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvQPerfMon95.pas,v 1.16 2004/11/06 22:08:20 asnepvangers Exp $
unit JvQPerfMon95;
{$I jvcl.inc}
{$I windowsonly.inc}
interface
uses
SysUtils, Registry, Classes, Contnrs,
Windows, QForms,
JvQComponent, JvQTypes;
type
EJvPerfStatException = class(EJVCLException);
TJvPerfStat95 = class;
PJvPerfStatCategory = ^TJvPerfStatCategory;
TJvPerfStatCategory = record
Category: string; // MBCS
Name: string; // MBCS
end;
TJvPerfStatActiveItem = class(TObject)
private
FCategoryIndex: Integer;
FDescription: string;
FDifferentiate: Boolean;
FKey: string; // MBCS
FLastPerfData: Longword;
FLastTime: Longword;
FName: string;
FOwner: TJvPerfStat95;
FStarted: Boolean;
function GetCategory: TJvPerfStatCategory;
function GetPerfData: Longword;
function GetPerfDataStr: string;
function GetKey: string;
protected
function InternalStartStop(Start: Boolean): Boolean;
public
constructor Create(AOwner: TJvPerfStat95; const AKey: string;
ACategoryIndex: Integer);
procedure Start(NoCheckState: Boolean = False);
procedure Stop(NoCheckState: Boolean = False);
property Category: TJvPerfStatCategory read GetCategory;
property Description: string read FDescription;
property Differentiate: Boolean read FDifferentiate;
property Key: string read GetKey;
property Name: string read FName;
property PerfData: Longword read GetPerfData;
property PerfDataStr: string read GetPerfDataStr;
property Started: Boolean read FStarted;
end;
TJvPerfStatItem = class(TCollectionItem)
private
FActiveItem: TJvPerfStatActiveItem;
FPerfStatKey: string;
procedure SetPerfStatKey(const Value: string);
function GetActiveItem: TJvPerfStatActiveItem;
function GetExist: Boolean;
protected
function GetDisplayName: string; override;
public
property ActiveItem: TJvPerfStatActiveItem read GetActiveItem;
property Exist: Boolean read GetExist;
published
property PerfStatKey: string read FPerfStatKey write SetPerfStatKey;
end;
TJvPerfStatItems = class(TCollection)
private
FOwner: TJvPerfStat95;
function GetItem(Index: Integer): TJvPerfStatItem;
procedure SetItem(Index: Integer; const Value: TJvPerfStatItem);
protected
function GetOwner: TPersistent; override;
procedure Update(Item: TCollectionItem); override;
public
constructor Create(AOwner: TJvPerfStat95);
function Add: TJvPerfStatItem;
property Items[Index: Integer]: TJvPerfStatItem read GetItem write SetItem; default;
end;
TJvPerfStat95 = class(TJvComponent)
private
FCategories: array of TJvPerfStatCategory;
FActiveObjectsList: TObjectList;
FItems: TJvPerfStatItems;
FWarnIfWrongOS: Boolean;
function GetActiveObjects(Index: Integer): TJvPerfStatActiveItem;
function GetActiveObjectCount: Integer;
function GetCategories(Index: Integer): TJvPerfStatCategory;
function GetCategoryCount: Integer;
function GetKeys(const Name: string): TJvPerfStatActiveItem;
procedure SetItems(const Value: TJvPerfStatItems);
protected
Reg: TRegistry;
procedure Loaded; override;
procedure ReadActiveObjects;
function ReadMBStringValue(const Name: string): string;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure StopAll;
property ActiveObjects[Index: Integer]: TJvPerfStatActiveItem read GetActiveObjects; default;
property ActiveObjectCount: Integer read GetActiveObjectCount;
property Categories[Index: Integer]: TJvPerfStatCategory read GetCategories;
property CategoryCount: Integer read GetCategoryCount;
property Keys[const Name: string]: TJvPerfStatActiveItem read GetKeys;
published
property Items: TJvPerfStatItems read FItems write SetItems;
property WarnIfWrongOS: Boolean read FWarnIfWrongOS write FWarnIfWrongOS default True;
end;
function JvGetPerfStatItems(List: TStrings): Boolean;
implementation
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
{$IFDEF HAS_UNIT_RTLCONSTS}
RTLConsts,
{$ENDIF HAS_UNIT_RTLCONSTS}
JvQJCLUtils, JvQJVCLUtils, JvQResources;
const
PerfEnumKey = 'System\CurrentControlSet\Control\PerfStats\Enum';
StartDataKey = 'PerfStats\StartStat';
StopDataKey = 'PerfStats\StopStat';
StatDataKey = 'PerfStats\StatData';
var
WrongOSWarningShown: Boolean = False;
function MultiByteStringToString(const S: string): string;
var
W: array [0..MAX_PATH] of WideChar;
begin
OSCheck(MultiByteToWideChar(CP_OEMCP, 0, PChar(S), -1, W, MAX_PATH) <> 0);
Result := W;
end;
function StringToMultiByteString(const S: string): string;
var
W: WideString;
C: array [0..MAX_PATH] of AnsiChar;
begin
W := S;
OSCheck(WideCharToMultiByte(CP_OEMCP, 0, PWideChar(W), -1, C, MAX_PATH, nil, nil) <> 0);
Result := C;
end;
function JvGetPerfStatItems(List: TStrings): Boolean;
var
List1, List2: TStringList;
Reg: TRegistry;
I1, I2: Integer;
begin
Result := True;
Reg := TRegistry.Create;
List1 := TStringList.Create;
List2 := TStringList.Create;
List.BeginUpdate;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKeyReadOnly(PerfEnumKey) then
begin
Reg.GetKeyNames(List1);
Reg.CloseKey;
List1.Sort;
for I1 := 0 to List1.Count - 1 do
if Reg.OpenKeyReadOnly(PerfEnumKey + '\' + List1[I1]) then
begin
Reg.GetKeyNames(List2);
Reg.CloseKey;
for I2 := 0 to List2.Count - 1 do
List.Add(MultiByteStringToString(Format('%s\%s', [List1[I1], List2[I2]])));
end;
end
else
Result := False;
finally
Reg.Free;
List2.Free;
List1.Free;
List.EndUpdate;
end;
end;
procedure ShowWrongOSWarning;
begin
if WrongOSWarningShown or (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) then
Exit;
with Application do
MessageBox(RsWrongOS, Title, [smbOK], smsWarning);
WrongOSWarningShown := True;
end;
//=== { TJvPerfStatActiveItem } ==============================================
constructor TJvPerfStatActiveItem.Create(AOwner: TJvPerfStat95;
const AKey: string; ACategoryIndex: Integer);
begin
inherited Create;
FOwner := AOwner;
FKey := AKey;
FCategoryIndex := ACategoryIndex;
with FOwner do
if Reg.OpenKeyReadOnly(PerfEnumKey + '\' + FKey) then
try
FDifferentiate := (ReadMBStringValue('Differentiate') = 'TRUE');
FDescription := ReadMBStringValue('Description');
FName := ReadMBStringValue('Name');
finally
Reg.CloseKey;
end;
end;
function TJvPerfStatActiveItem.GetCategory: TJvPerfStatCategory;
begin
Result := FOwner.GetCategories(FCategoryIndex);
end;
function TJvPerfStatActiveItem.GetKey: string;
begin
Result := MultiByteStringToString(FKey);
end;
function TJvPerfStatActiveItem.GetPerfData: Longword;
var
Size: Integer;
Value: Longword;
CurrentTickCount: DWORD;
begin
with FOwner.Reg do
begin
RootKey := HKEY_DYN_DATA;
if OpenKeyReadOnly(StatDataKey) then
begin
Size := GetDataSize(FKey);
if Size = SizeOf(Value) then
ReadBinaryData(FKey, Value, Size);
CloseKey;
end;
end;
if FDifferentiate then
begin
CurrentTickCount := GetTickCount;
if (FLastTime = 0) or (CurrentTickCount = FLastTime) then
Result := 0
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -