Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust sampling frequency to account for processing time #20

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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