Skip to content

Commit

Permalink
fix: adjust sampling frequency to account for processing time
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Nov 12, 2023
1 parent 06ab18c commit c0f645a
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ AppleSiliconMeasure extractPowerMeasure(InputStream powerMeasureInput, long pid)
true);
}

AppleSiliconMeasure extractPowerMeasure(OngoingPowerMeasure ongoingMeasure,
InputStream powerMeasureInput,
AppleSiliconMeasure extractPowerMeasure(OngoingPowerMeasure ongoingMeasure, InputStream powerMeasureInput,
String paddedPIDAsString, boolean returnCurrent) {
try {
// Should not be closed since it closes the process
Expand Down Expand Up @@ -124,10 +123,10 @@ private static double extractAttributedMeasure(String line, double attributionRa

@Override
public OngoingPowerMeasure start(long duration, long frequency) throws Exception {
final var freq = Long.toString(Math.round(frequency));
// it takes some time for the external process in addition to the sampling time so adjust the sampling frequency to account for this so that at most one measure occurs during the sampling time window
final var freq = Long.toString(frequency - 50);
powermetrics = Runtime.getRuntime()
.exec("sudo powermetrics --samplers cpu_power,tasks --show-process-samp-norm --show-process-gpu -i "
+ freq);
.exec("sudo powermetrics --samplers cpu_power,tasks --show-process-samp-norm --show-process-gpu -i " + freq);
accumulatedCPUShareDiff = 0.0;
return new OngoingPowerMeasure(AppleSiliconMeasure.METADATA);
}
Expand Down

0 comments on commit c0f645a

Please sign in to comment.