コード例 #1
0
ファイル: CPUStat.java プロジェクト: camry-wu/tools
    /**
     * statistic sth.
     *
     * <p>implement by subclass.
     *
     * @return statistic data
     */
    protected String statistic() {
      CPUUsage current = currentCPUUsage();
      double usagePercent = current.usagePercent(_last);
      double idlePercent = current.idlePercent(_last);
      _last = current;

      return String.format("%4.2f, %4.2f", usagePercent, idlePercent);
    }
コード例 #2
0
ファイル: CPUStat.java プロジェクト: camry-wu/tools
    /**
     * statistic sth.
     *
     * <p>implement by subclass.
     *
     * @return statistic data
     */
    protected String statistic() {
      CPUUsage currentCPU = currentCPUUsage();
      ProcessUsage currentProcess = currentProcessUsage(_lPid);

      long totalCPU = currentCPU.total() - _lastCPU.total();

      double cpuPercent = currentCPU.usagePercent(_lastCPU);
      double processPercent = currentProcess.usagePercent(_lastProcess, totalCPU) * _iCpuNum;

      _lastCPU = currentCPU;
      _lastProcess = currentProcess;

      return String.format("%4.2f, %4.2f", processPercent, cpuPercent);
    }
コード例 #3
0
ファイル: CPUStat.java プロジェクト: camry-wu/tools
  public double idlePercent(final CPUUsage last) {
    long lastTotal = last.total();
    long thisTotal = total();

    long lastIdle = last._lIdle;
    long thisIdle = this._lIdle;

    double total = (double) (thisTotal - lastTotal);
    double idle = (double) (thisIdle - lastIdle);

    if (total < 0) {
      total = 0.0;
    }
    if (idle < 0) {
      idle = 0.0;
    }

    if (total > 0) {
      return 100 * idle / total;
    } else {
      return 0.0;
    }
  }