@Test public void testDiff() { CpuFrequencyMetrics metricsA = new CpuFrequencyMetrics(); metricsA.timeInStateS[0].put(100, 100); metricsA.timeInStateS[0].put(200, 200); metricsA.timeInStateS[1].put(300, 300); metricsA.timeInStateS[2].put(400, 400); CpuFrequencyMetrics metricsB = new CpuFrequencyMetrics(); metricsB.timeInStateS[0].put(100, 20); metricsB.timeInStateS[1].put(300, 40); CpuFrequencyMetrics output = new CpuFrequencyMetrics(); metricsA.diff(metricsB, output); assertThat(output.timeInStateS[0].size()).isEqualTo(2); assertThat(output.timeInStateS[0].get(100)).isEqualTo(80); assertThat(output.timeInStateS[0].get(200)).isEqualTo(200); assertThat(output.timeInStateS[1].size()).isEqualTo(1); assertThat(output.timeInStateS[1].get(300)).isEqualTo(260); assertThat(output.timeInStateS[2].size()).isEqualTo(1); assertThat(output.timeInStateS[2].get(400)).isEqualTo(400); assertThat(output.timeInStateS[3].size()).isEqualTo(0); }
@Override public CpuFrequencyMetrics diff( @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output) { if (output == null) { output = new CpuFrequencyMetrics(); } if (b == null) { output.set(this); } else { for (int i = 0; i < timeInStateS.length; i++) { SparseIntArray aCore = timeInStateS[i]; SparseIntArray bCore = b.timeInStateS[i]; SparseIntArray outputCore = output.timeInStateS[i]; boolean hasCoreReset = false; for (int j = 0, size = aCore.size(); j < size && !hasCoreReset; j++) { int frequency = aCore.keyAt(j); int difference = aCore.valueAt(j) - bCore.get(frequency, 0); if (difference < 0) { hasCoreReset = true; break; } outputCore.put(frequency, difference); } if (hasCoreReset) { copyArrayInto(aCore, outputCore); } } } return output; }
CpuFrequencyMetrics extends SystemMetrics<CpuFrequencyMetrics> { @Override public CpuFrequencyMetrics diff( @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output) { if (output == null) { output = new CpuFrequencyMetrics(); } if (b == null) { output.set(this); } else { for (int i = 0; i < timeInStateS.length; i++) { SparseIntArray aCore = timeInStateS[i]; SparseIntArray bCore = b.timeInStateS[i]; SparseIntArray outputCore = output.timeInStateS[i]; boolean hasCoreReset = false; for (int j = 0, size = aCore.size(); j < size && !hasCoreReset; j++) { int frequency = aCore.keyAt(j); int difference = aCore.valueAt(j) - bCore.get(frequency, 0); if (difference < 0) { hasCoreReset = true; break; } outputCore.put(frequency, difference); } if (hasCoreReset) { copyArrayInto(aCore, outputCore); } } } return output; } }
CpuFrequencyMetrics extends SystemMetrics<CpuFrequencyMetrics> { @Override public CpuFrequencyMetrics diff( @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output) { if (output == null) { output = new CpuFrequencyMetrics(); } if (b == null) { output.set(this); } else { for (int i = 0; i < timeInStateS.length; i++) { SparseIntArray aCore = timeInStateS[i]; SparseIntArray bCore = b.timeInStateS[i]; SparseIntArray outputCore = output.timeInStateS[i]; boolean hasCoreReset = false; for (int j = 0, size = aCore.size(); j < size && !hasCoreReset; j++) { int frequency = aCore.keyAt(j); int difference = aCore.valueAt(j) - bCore.get(frequency, 0); if (difference < 0) { hasCoreReset = true; break; } outputCore.put(frequency, difference); } if (hasCoreReset) { copyArrayInto(aCore, outputCore); } } } return output; } CpuFrequencyMetrics(); }
CpuFrequencyMetrics extends SystemMetrics<CpuFrequencyMetrics> { @Override public CpuFrequencyMetrics diff( @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output) { if (output == null) { output = new CpuFrequencyMetrics(); } if (b == null) { output.set(this); } else { for (int i = 0; i < timeInStateS.length; i++) { SparseIntArray aCore = timeInStateS[i]; SparseIntArray bCore = b.timeInStateS[i]; SparseIntArray outputCore = output.timeInStateS[i]; boolean hasCoreReset = false; for (int j = 0, size = aCore.size(); j < size && !hasCoreReset; j++) { int frequency = aCore.keyAt(j); int difference = aCore.valueAt(j) - bCore.get(frequency, 0); if (difference < 0) { hasCoreReset = true; break; } outputCore.put(frequency, difference); } if (hasCoreReset) { copyArrayInto(aCore, outputCore); } } } return output; } CpuFrequencyMetrics(); @Override CpuFrequencyMetrics sum(
      @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output); @Override CpuFrequencyMetrics diff(
      @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output); @Override CpuFrequencyMetrics set(CpuFrequencyMetrics b); @Override boolean equals(Object o); static boolean sparseIntArrayEquals(SparseIntArray a, SparseIntArray b); @Override int hashCode(); @Override String toString(); @Nullable JSONObject toJSONObject(); }
CpuFrequencyMetrics extends SystemMetrics<CpuFrequencyMetrics> { @Override public CpuFrequencyMetrics diff( @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output) { if (output == null) { output = new CpuFrequencyMetrics(); } if (b == null) { output.set(this); } else { for (int i = 0; i < timeInStateS.length; i++) { SparseIntArray aCore = timeInStateS[i]; SparseIntArray bCore = b.timeInStateS[i]; SparseIntArray outputCore = output.timeInStateS[i]; boolean hasCoreReset = false; for (int j = 0, size = aCore.size(); j < size && !hasCoreReset; j++) { int frequency = aCore.keyAt(j); int difference = aCore.valueAt(j) - bCore.get(frequency, 0); if (difference < 0) { hasCoreReset = true; break; } outputCore.put(frequency, difference); } if (hasCoreReset) { copyArrayInto(aCore, outputCore); } } } return output; } CpuFrequencyMetrics(); @Override CpuFrequencyMetrics sum(
      @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output); @Override CpuFrequencyMetrics diff(
      @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output); @Override CpuFrequencyMetrics set(CpuFrequencyMetrics b); @Override boolean equals(Object o); static boolean sparseIntArrayEquals(SparseIntArray a, SparseIntArray b); @Override int hashCode(); @Override String toString(); @Nullable JSONObject toJSONObject(); final SparseIntArray[] timeInStateS; }