Skip to content

Commit 90e8d8c

Browse files
committed
fix: make sure sampling period is not negative
1 parent 6d04758 commit 90e8d8c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

backend/src/main/java/net/laprun/sustainability/power/sensors/macos/powermetrics/ProcessMacOSPowermetricsSensor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public ProcessMacOSPowermetricsSensor(Security security) {
3737
public void start(long frequency) throws Exception {
3838
if (!isStarted()) {
3939
// 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
40-
final var freq = Long.toString(frequency - 50);
40+
frequency = Math.min(0, frequency - 50);
41+
final var freq = Long.toString(frequency);
4142
powermetrics = security.execPowermetrics("cpu_power,tasks", "--show-process-samp-norm", "--show-process-gpu", "-i",
4243
freq);
4344
}

0 commit comments

Comments
 (0)