zoukankan      html  css  js  c++  java
  • delphi 获取当前进程的cpu占用率

    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

  • 相关阅读:
    归并排序
    数据组合求值
    轨道周期
    类及对象构建
    日期改写
    排列组合去重
    库存更新
    Java性能测试从入门到放弃-详解篇
    Java性能测试从入门到放弃-概述篇
    cocos2d-x安装教程
  • 原文地址:https://www.cnblogs.com/findumars/p/6679994.html
Copyright © 2011-2022 走看看