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

  • 相关阅读:
    pysam操作sam文件
    NCBI SRA数据库
    通过bed文件获取fasta序列
    利用mysql客户端查询UCSC数据库
    Biopython常用功能模块
    FASTX-Toolkit组件用法
    SQL HAVING用法详解
    jquery获取、改变元素属性值
    《JavaScript DOM编程艺术》
    sublime text3使用心得及个人配置 sublime常用快捷键大全
  • 原文地址:https://www.cnblogs.com/findumars/p/6679994.html
Copyright © 2011-2022 走看看