home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 March
/
Chip_2002-03_cd1.bin
/
zkuste
/
delphi
/
kompon
/
d56
/
MSYSINFO.ZIP
/
Demos
/
GUI
/
ProcessProps.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2002-01-04
|
13KB
|
381 lines
unit ProcessProps;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
MiTeC_PerfLibNT, ComCtrls, StdCtrls, ExtCtrls;
type
TpropProcess = class(TFrame)
pc: TPageControl;
tsGeneral: TTabSheet;
tsPerformance: TTabSheet;
tsMemory: TTabSheet;
Panel1: TPanel;
Image1: TImage;
Bevel1: TBevel;
Bevel2: TBevel;
Bevel3: TBevel;
lPID: TLabel;
Label2: TLabel;
eFile: TEdit;
bProcProps: TButton;
lHandles: TLabel;
lThreads: TLabel;
lModules: TLabel;
lPriority: TLabel;
tsModules: TTabSheet;
tsThread: TTabSheet;
Panel2: TPanel;
lvPerf: TListView;
Panel3: TPanel;
lvMem: TListView;
lPPID: TLabel;
stPID: TStaticText;
stPPID: TStaticText;
stModules: TStaticText;
stThreads: TStaticText;
stName: TEdit;
stHandles: TStaticText;
stPriority: TStaticText;
lvHeap: TListView;
Panel4: TPanel;
lvMods: TListView;
Panel5: TPanel;
lvThds: TListView;
lHeapID: TLabel;
stHeapID: TStaticText;
Splitter1: TSplitter;
Panel6: TPanel;
Panel7: TPanel;
bModProps: TButton;
ModsPanel: TPanel;
Panel8: TPanel;
Panel9: TPanel;
ThdsPanel: TPanel;
bKill: TButton;
procedure cmProcProps(Sender: TObject);
procedure cmModProps(Sender: TObject);
procedure cmKill(Sender: TObject);
private
FProcess: TObject;
FPerfLib: TPerfLibNT;
public
property Process: TObject read FProcess write FProcess;
property PerfLib: TPerfLibNT read FPerfLib write FPerfLib;
procedure Refresh;
end;
implementation
uses MiTeC_Routines, MiTeC_EnumsNT, MiTeC_Enums9x;
{$R *.DFM}
{ TpropProcess }
const
SNotAvail = 'Not Available';
SEmpty = '-';
SWARN = 'WARNING: Terminating a process can cause undesired '#13#10+
'results including loss of data and system instability. The '#13#10+
'process will not be given the chance to save its state or '#13#10+
'data before it is terminated. Are you sure you want to '#13#10+
'terminate the process?';
SCannotTerm = 'Cannot terminate this process.';
procedure TpropProcess.Refresh;
var
i: integer;
p95: P95Process;
pNT: PNTProcess;
begin
pc.ActivePage:=tsGeneral;
Splitter1.Visible:=Is2K or not IsNT;
lvHeap.Visible:=Is2K or not IsNT;
lvMem.Visible:=IsNT;
if not lvMem.Visible then
lvHeap.Align:=alClient;
tsPerformance.TabVisible:=IsNT;
if IsNT then begin
if Assigned(FPerfLib) then begin
pNT:=PNTProcess(Process);
GetNTProcessInfo(pNT^,PerfLib,pNT^.PID,True);
with pNT^ do begin
bKill.Enabled:=OpenProcess(PROCESS_TERMINATE,False,PID)<>0;
stName.Text:=Name;
stPID.Caption:=Format('%d (0x%0:x)',[PID]);
eFile.Text:=ImageName;
bProcProps.Enabled:=FileExists(ImageName);
eFile.Hint:=eFile.Text;
stModules.Caption:=Format('%d',[Modules.Count]);
stThreads.Caption:=Format('%d',[ThreadCount]);
stHandles.Caption:=Format('%d',[HandleCount]);
stPriority.Caption:=Format('%d',[PriorityBase]);
if Is2K then begin
stPPID.Caption:=Format('%d (0x%0:x)',[ParentPID]);
stHeapID.Caption:=Format('%d (0x%0:x)',[HeapID]);
end;
with lvPerf, Items do begin
BeginUpdate;
with Add do begin
Caption:='Elapsed Time';
SubItems.Add(FormatSeconds(ElapsedTime,True,False,True));
end;
with Add do begin
Caption:='CPU Time';
SubItems.Add(FormatSeconds(CPUTime,True,False,True));
end;
with Add do begin
Caption:='Kernel Time';
SubItems.Add(FormatSeconds(KernelTime,True,False,True));
end;
with Add do begin
Caption:='User Time';
SubItems.Add(FormatSeconds(UserTime,True,False,True));
end;
if Is2K then begin
with Add do begin
Caption:='';
SubItems.Add('');
end;
with Add do begin
Caption:='IO Read Operations/sec';
SubItems.Add(FormatFloat('#,#0',IOReadOps));
end;
with Add do begin
Caption:='IO Write Operations/sec';
SubItems.Add(FormatFloat('#,#0',IOWriteOps));
end;
with Add do begin
Caption:='IO Data Operations/sec';
SubItems.Add(FormatFloat('#,#0',IOWriteOps));
end;
with Add do begin
Caption:='IO Other Operations/sec';
SubItems.Add(FormatFloat('#,#0',IOOtherOps));
end;
with Add do begin
Caption:='IO Read Bytes/sec';
SubItems.Add(FormatFloat('#,#0',IOReadB));
end;
with Add do begin
Caption:='IO Write Bytes/sec';
SubItems.Add(FormatFloat('#,#0',IOWriteB));
end;
with Add do begin
Caption:='IO Data Bytes/sec';
SubItems.Add(FormatFloat('#,#0',IODataB));
end;
with Add do begin
Caption:='IO Other Bytes/sec';
SubItems.Add(FormatFloat('#,#0',IOOtherB));
end;
end;
EndUpdate;
end;
with lvMem, Items do begin
BeginUpdate;
with Add do begin
Caption:='Page Fault Count';
SubItems.Add(FormatFloat('#,#0 B/sec',PageFaultCount));
SubItems.Add(SEmpty);
end;
with Add do begin
Caption:='Private Space';
SubItems.Add(FormatFloat('#,#0 B',PrivateSpace));
SubItems.Add(SEmpty);
end;
with Add do begin
Caption:='Working Set Size';
SubItems.Add(FormatFloat('#,#0 B',WorkingSetSize));
SubItems.Add(FormatFloat('#,#0 B',PeakWorkingSetSize));
end;
with Add do begin
Caption:='Paged Pool Size';
SubItems.Add(FormatFloat('#,#0 B',PagedPoolSize));
SubItems.Add(SEmpty);
end;
with Add do begin
Caption:='NonPaged Pool Size';
SubItems.Add(FormatFloat('#,#0 B',NonPagedPoolSize));
SubItems.Add(SEmpty);
end;
with Add do begin
Caption:='Virtual Address Space Size';
SubItems.Add(FormatFloat('#,#0 B',VirtualAddressSpaceSize));
SubItems.Add(FormatFloat('#,#0 B',PeakVirtualAddressSpaceSize));
end;
with Add do begin
Caption:='Page File Usage';
SubItems.Add(FormatFloat('#,#0 B',PageFileUsage));
SubItems.Add(FormatFloat('#,#0 B',PeakPageFileUsage));
end;
EndUpdate;
end;
if Is2K then begin
lvHeap.Items.BeginUpdate;
for i:=0 to HeapLists.Count-1 do
with lvHeap, Items do begin
with Add do begin
Caption:=Format('0x%x',[PHeapList(HeapLists.Objects[i])^.ID]);
SubItems.Add(PHeapList(HeapLists.Objects[i])^.szFlags);
end;
end;
lvHeap.Items.EndUpdate;
end;
lvMods.Items.BeginUpdate;
for i:=0 to Modules.Count-1 do
with lvMods, Items, PNTModule(Modules.Objects[i])^ do begin
with Add do begin
Caption:=Name;
if Is2K then
SubItems.Add(Format('0x%x',[ID]))
else
SubItems.Add(SEmpty);
SubItems.Add(Format('0x%x',[EntryPoint]));
SubItems.Add(Format('0x%x',[LoadAddress]));
SubItems.Add(FormatFloat('#,#0',ImageSize));
if Is2K then begin
SubItems.Add(FormatFloat('#,#0',BaseSize));
SubItems.Add(Format('0x%x',[Handle]));
SubItems.Add(Format('%d',[GlobalUsage]));
SubItems.Add(Format('%d',[ProcessUsage]));
end else begin
SubItems.Add(SEmpty);
SubItems.Add(SEmpty);
SubItems.Add(SEmpty);
SubItems.Add(SEmpty);
end;
SubItems.Add(ImageName);
end;
end;
lvMods.Items.EndUpdate;
ModsPanel.Caption:=Format('%d items',[lvMods.Items.Count]);
lvThds.Items.BeginUpdate;
for i:=0 to Threads.Count-1 do
with lvThds, Items, PNTThread(Threads.Objects[i])^ do begin
with Add do begin
Caption:=Format('0x%x',[ID]);
SubItems.Add(szStatus);
SubItems.Add(Format('%d',[PriorityBase]));
SubItems.Add(Format('%d',[PriorityDelta]));
SubItems.Add(szWaitReason);
SubItems.Add(Format('0x%x',[StartAddr]));
SubItems.Add(Format('%d',[CntxtSwtcs]));
SubItems.Add(FormatSeconds(CPUTime,True,False,True));
SubItems.Add(SEmpty);
end;
end;
lvThds.Items.EndUpdate;
ThdsPanel.Caption:=Format('%d items',[lvThds.Items.Count]);
end;
end;
end else begin
p95:=P95Process(Process);
p95^:=Get95ProcessInfo(p95.PID,True);
with p95^ do begin
bKill.Enabled:=OpenProcess(PROCESS_TERMINATE,False,PID)<>0;
stName.Text:=Name;
stPID.Caption:=Format('%d (0x%0:x)',[PID]);
eFile.Text:=ImageName;
bProcProps.Enabled:=FileExists(ImageName);
eFile.Hint:=eFile.Text;
stModules.Caption:=Format('%d',[Modules.Count]);
stThreads.Caption:=Format('%d',[ThreadCount]);
stPriority.Caption:=Format('%d',[Priority]);
stPPID.Caption:=Format('%d (0x%0:x)',[ParentPID]);
stHeapID.Caption:=Format('%d (0x%0:x)',[HeapID]);
lvHeap.Items.BeginUpdate;
for i:=0 to HeapLists.Count-1 do
with lvHeap, Items do begin
with Add do begin
Caption:=Format('0x%x',[PHeapList(HeapLists.Objects[i])^.ID]);
SubItems.Add(PHeapList(HeapLists.Objects[i])^.szFlags);
end;
end;
lvHeap.Items.EndUpdate;
lvMods.Items.BeginUpdate;
for i:=0 to Modules.Count-1 do
with lvMods, Items, P95Module(Modules.Objects[i])^ do begin
with Add do begin
Caption:=Name;
SubItems.Add(Format('0x%x',[ID]));
SubItems.Add(Format('0x%x',[EntryPoint]));
SubItems.Add(SEmpty);
SubItems.Add(SEmpty);
SubItems.Add(FormatFloat('#,#0',BaseSize));
SubItems.Add(Format('0x%x',[Handle]));
SubItems.Add(Format('%d',[GlobalUsage]));
SubItems.Add(Format('%d',[ProcessUsage]));
SubItems.Add(ImageName);
end;
end;
lvMods.Items.EndUpdate;
ModsPanel.Caption:=Format('%d items',[lvMods.Items.Count]);
lvThds.Items.BeginUpdate;
for i:=0 to Threads.Count-1 do
with lvThds, Items, P95Thread(Threads.Objects[i])^ do begin
with Add do begin
Caption:=Format('0x%x',[ID]);
SubItems.Add(SEmpty);
SubItems.Add(Format('%d',[PriorityBase]));
SubItems.Add(Format('%d',[PriorityDelta]));
SubItems.Add(SEmpty);
SubItems.Add(SEmpty);
SubItems.Add(SEmpty);
SubItems.Add(SEmpty);
SubItems.Add(Format('%d',[Usage]));
end;
end;
lvThds.Items.EndUpdate;
ThdsPanel.Caption:=Format('%d items',[lvThds.Items.Count]);
end;
end;
end;
procedure TpropProcess.cmProcProps(Sender: TObject);
begin
if FileExists(eFile.Text) then
DisplayPropDialog(Self.Parent.Handle,eFile.Text);
end;
procedure TpropProcess.cmModProps(Sender: TObject);
begin
if Assigned(lvMods.Selected) and FileExists(lvMods.Selected.SubItems[8]) then
DisplayPropDialog(Self.Parent.Handle,lvMods.Selected.SubItems[8]);
end;
procedure TpropProcess.cmKill(Sender: TObject);
var
ph :thandle;
pid :integer;
begin
if IsNT then
pid:=PNTProcess(Process)^.PID
else
pid:=P95Process(Process)^.PID;
ph:=openprocess(PROCESS_TERMINATE,false,pid);
if (ph<>0) then begin
if (MessageDlg(stName.Text+#13#10#13#10+SWARN,mtWarning,[mbYes,mbNo],0)=mryes) then begin
TerminateProcess(ph,0);
Refresh;
end;
end else
MessageDlg(SCannotTerm,mtInformation,[mbOK],0);
end;
end.