在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
type
TProcessCpuUsage = record private FLastUsed, FLastTime: Int64; FCpuCount:Integer; public class function Create: TProcessCpuUsage; static; function Current: Single; end; var
class function TProcessCpuUsage.Create: TProcessCpuUsage;
begin Result.FLastTime := 0; Result.FLastUsed := 0; Result.FCpuCount := 0; end; function TProcessCpuUsage.Current: Single;
var Usage, ACurTime: UInt64; CreateTime, ExitTime, IdleTime, UserTime, KernelTime: TFileTime; function FileTimeToI64(const ATime: TFileTime): Int64; begin Result := (Int64(ATime.dwHighDateTime) shl 32) + ATime.dwLowDateTime; end; function GetCPUCount: Integer; var SysInfo: TSystemInfo; begin GetSystemInfo(SysInfo); Result := SysInfo.dwNumberOfProcessors; end; begin
Result := 0; if GetProcessTimes(GetCurrentProcess, CreateTime, ExitTime, KernelTime, UserTime) then begin ACurTime := GetTickCount; Usage := FileTimeToI64(UserTime) + FileTimeToI64(KernelTime); if FLastTime <> 0 then Result := (Usage - FLastUsed) / (ACurTime - FLastTime) / FCpuCount / 100 else FCpuCount:=GetCpuCount; FLastUsed := Usage; FLastTime := ACurTime; end; end;
if ProcessCpuUsage.Current >= 25 then ............................ end http://blog.csdn.net/y281252548/article/details/50600028 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论