delphi 获取当前进程的cpu占用率
来源:互联网 发布:淘宝好评返现短信模板 编辑:程序博客网 时间:2024/05/16 18:10
type
TProcessCpuUsage = record
private
FLastUsed, FLastTime: Int64;
FCpuCount:Integer;
public
class function Create: TProcessCpuUsage; static;
function Current: Single;
end;
TProcessCpuUsage = record
private
FLastUsed, FLastTime: Int64;
FCpuCount:Integer;
public
class function Create: TProcessCpuUsage; static;
function Current: Single;
end;
var
ProcessCpuUsage: TProcessCpuUsage = (FLastUsed: 0; FLastTime: 0;FCpuCount:0);
class function TProcessCpuUsage.Create: TProcessCpuUsage;
begin
Result.FLastTime := 0;
Result.FLastUsed := 0;
Result.FCpuCount := 0;
end;
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;
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;
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
begin
............................
end
0 0
- delphi 获取当前进程的cpu占用率
- 如何计算当前进程的CPU占用率
- 获取进程CPU占用率 -- NtQuerySystemInformation
- 获得进程的CPU占用率
- linux获取当前进程的CPU使用率
- 取特定进程的CPU占用率
- 取特定进程的CPU占用率
- solaris下查看进程的cpu占用率
- 如何得到本进程的CPU占用率?
- BES - 控制进程的CPU占用率
- solaris下查看进程的cpu占用率
- JAVA 进程异常高的 CPU 占用率
- 查看进程CPU占用率的方法
- 如何得到本进程的CPU占用率?
- windows平台进程CPU占用率的计算
- 如何控制一个进程CPU的占用率
- windows平台进程CPU占用率的计算
- windows平台进程CPU占用率的计算
- Java 定时任务
- jqGrid 学习笔记整理——基础篇
- 献给初学iOS的小盆友们——微博app项目开发之十三微博时间和来源处理
- Bitmap image and image mask 位图 图片遮罩
- hdu 2822(BFS+优先队列)
- delphi 获取当前进程的cpu占用率
- 热部署原理和实例
- android Bitmap 处理
- FILE文件流的中fopen、fread、fseek、fclose的使用
- iOS 菜单显示一种方式
- Eclipse搭建Maven工程集成Spring4+Hibernate5
- Android应用程序内存优化
- IONIC 竖屏显示(屏幕不旋转)
- file_get_contents & curl mark一下