Ejemplo n.º 1
0
    /**
     * 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);
    }
Ejemplo n.º 2
0
    /**
     * 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);
    }
Ejemplo n.º 3
0
  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;
    }
  }