getCpuUsagePercentage static method

Stream<double> getCpuUsagePercentage()

Get a Stream for handling the total cpu usage in percentage as a double

Implementation

static Stream<double> getCpuUsagePercentage() async* {
  var idleTotalPrev = <int>[0, 0];

  while (true) {
    var idleTotal = load();
    var dTotal = idleTotal[0] - idleTotalPrev[0];
    var dLoad = idleTotal[1] - idleTotalPrev[1];
    idleTotalPrev = idleTotal;

    var percent = 100.0 * (1.0 - dTotal / dLoad);
    yield percent;

    sleep(Duration(seconds: 1));
  }
}