type
  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;
 
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
  begin

............................

end

http://blog.csdn.net/y281252548/article/details/50600028

最新文章

  1. 向ES6靠齐的Class.js
  2. SIP模块版本错误问题:the sip module implements API v??? but XXX module requires API v???
  3. 磁盘、分区及Linux文件系统 [Disk, Partition, Linux File System]
  4. [MSSQL2012]CUME_DIST函数
  5. 简述Mesos API–files
  6. Objective-C:Foundation框架-常用类-NSDate
  7. 关于获取目录的N种方法 的汇总
  8. Linux 2.4.x内核软中断机制
  9. FIREDAC调用中间件远程方法查询数据示例
  10. MySQL与NoSQL——SQL与NoSQL的融合
  11. mysql-5.6.27源码安装及错误解决办法
  12. JS对象创建常用方式及原理分析
  13. DevExpress控件安装破解和汉化使用教程
  14. codeblock 恢复默认字体设置
  15. Maven学习 五 Maven项目创建(1)jar项目
  16. jquery之源码
  17. Java核心技术之基础知识
  18. sencha touch list(列表) item(单行)单击事件触发顺序
  19. [py]django上线部署-uwsgi+nginx+py3/django1.10
  20. 获取字符串中某个指定的子串出现的开始位置(CHARINDEX用法)

热门文章

  1. window.load和ready的差别
  2. 有奖试读&amp;amp;征文--当青春遇上互联网,是否能点燃你的创业梦
  3. Android实现手机拍照功能
  4. 怎样获取android手机联系人并按字母展示(三)
  5. Docker Xshell
  6. 关于Vuex可直接修改state问题
  7. vue: 关于多路由公用模板,导致组件内数组缓存问题
  8. Msg DisPatch
  9. quick-cocos2d-x游戏开发【8】——动画与动作
  10. 简明Python3教程 6.基础