- Type
- // Structure utilisée pour le retour des temps d'utilisation systèmes
- TSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION=Record
- Case Integer Of
- 1:( IdleTime : Int64; // Temps inoccpé par pas de 100 NanoSecondes
- KernelTime : Int64; // Temps du noyau par pas de 100 NanoSecondes
- UserTime : Int64; // Temps utilisateur par pas de 100 NanoSecondes
- Reserved1 : Array[0..2]Of Int64;
- Reserved2 : Cardinal;);
- 2:( Res : Array[1..$138]Of Byte);
- End;
-
- // Fonction de demande d'informations sytèmes. Elle sert pour diverses
- // demandes sytèmes suivant le paramètre SystemInfoClass. Voir MSDN
- // pour plus de détails.
- Function NtQuerySystemInformation(SystemInfoClass:Integer;Info:Pointer;InfoLength:Cardinal;
- Var ReturnLength:Cardinal):Integer;StdCall;
- External 'NTDLL.DLL' Name 'NtQuerySystemInformation';
-
- Const
- // Constante utilisée pour la demande d'occupation du processeur
- SystemProcessorPerformanceInformation=$2;
-
- // Constantes de conversion
- CentNanoSecondesParJour = 24.0*60.0*60.0*10000000.0;
- MilliSecondesParJour = 24.0*60.0*60.0*1000.0;
-
- Var
- MemTickTotal : Integer = 0;
- MemTickIdle : Integer = 0;
-
- procedure TForm1.Timer1Timer(Sender: TObject);
- Var Info : TSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
- Long : Cardinal;
- TickTotal : Integer;
- TickIdle : Integer;
- DiffTotal : Integer;
- DiffIdle : Integer;
- Occupe : Double;
- begin
- // Primo on demande les information au système
- NtQuerySystemInformation(SystemProcessorPerformanceInformation,@Info,SizeOf(Info),Long);
-
- // Conversion du temps 'idle' en millisecondes
- TickIdle := Info.IdleTime Div 10000;
- // Obtention du temps total
- TickTotal := GetTickCount;
-
- // Calcul du pourcentage
- DiffIdle := TickIdle - MemTickIdle;
- DiffTotal := TickTotal - MemTickTotal;
- Occupe := 100-DiffIdle/DiffTotal*100;
- If Occupe<0 Then Occupe:=0;
-
- // Affichage des informations
- Label1.Caption := FormatDateTime('HH:NN:SS:zzz',Info.IdleTime /CentNanoSecondesParJour);
- Label4.Caption := FormatDateTime('HH:NN:SS:zzz',TickTotal /MilliSecondesParJour );
- Label5.Caption := IntToStr(Round(Occupe));
- ProgressBar1.Position := Trunc(Occupe);
-
- // Mémorisation pour le prochain passage
- MemTickIdle := TickIdle;
- MemTickTotal := TickTotal;
- end;
Type
// Structure utilisée pour le retour des temps d'utilisation systèmes
TSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION=Record
Case Integer Of
1:( IdleTime : Int64; // Temps inoccpé par pas de 100 NanoSecondes
KernelTime : Int64; // Temps du noyau par pas de 100 NanoSecondes
UserTime : Int64; // Temps utilisateur par pas de 100 NanoSecondes
Reserved1 : Array[0..2]Of Int64;
Reserved2 : Cardinal;);
2:( Res : Array[1..$138]Of Byte);
End;
// Fonction de demande d'informations sytèmes. Elle sert pour diverses
// demandes sytèmes suivant le paramètre SystemInfoClass. Voir MSDN
// pour plus de détails.
Function NtQuerySystemInformation(SystemInfoClass:Integer;Info:Pointer;InfoLength:Cardinal;
Var ReturnLength:Cardinal):Integer;StdCall;
External 'NTDLL.DLL' Name 'NtQuerySystemInformation';
Const
// Constante utilisée pour la demande d'occupation du processeur
SystemProcessorPerformanceInformation=$2;
// Constantes de conversion
CentNanoSecondesParJour = 24.0*60.0*60.0*10000000.0;
MilliSecondesParJour = 24.0*60.0*60.0*1000.0;
Var
MemTickTotal : Integer = 0;
MemTickIdle : Integer = 0;
procedure TForm1.Timer1Timer(Sender: TObject);
Var Info : TSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
Long : Cardinal;
TickTotal : Integer;
TickIdle : Integer;
DiffTotal : Integer;
DiffIdle : Integer;
Occupe : Double;
begin
// Primo on demande les information au système
NtQuerySystemInformation(SystemProcessorPerformanceInformation,@Info,SizeOf(Info),Long);
// Conversion du temps 'idle' en millisecondes
TickIdle := Info.IdleTime Div 10000;
// Obtention du temps total
TickTotal := GetTickCount;
// Calcul du pourcentage
DiffIdle := TickIdle - MemTickIdle;
DiffTotal := TickTotal - MemTickTotal;
Occupe := 100-DiffIdle/DiffTotal*100;
If Occupe<0 Then Occupe:=0;
// Affichage des informations
Label1.Caption := FormatDateTime('HH:NN:SS:zzz',Info.IdleTime /CentNanoSecondesParJour);
Label4.Caption := FormatDateTime('HH:NN:SS:zzz',TickTotal /MilliSecondesParJour );
Label5.Caption := IntToStr(Round(Occupe));
ProgressBar1.Position := Trunc(Occupe);
// Mémorisation pour le prochain passage
MemTickIdle := TickIdle;
MemTickTotal := TickTotal;
end;