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

  • 相关阅读:
    Minimum Sum of Array(map迭代器)
    stl库中的map (反向迭代器)以及例题
    stl库中反转的函数
    如何使用java中的对象
    java中的成员变量和局部变量
    java中的构造方法
    static使用之静态变量
    什么是类和对象
    如何定义java中的类
    css让图片作为按钮的背景并且大小合适
  • 原文地址:https://www.cnblogs.com/findumars/p/6679994.html
Copyright © 2011-2022 走看看