-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: RAPL sensor now properly use CPU share instead of full measure (#13
- Loading branch information
Showing
11 changed files
with
259 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 50 additions & 10 deletions
60
runtime/src/main/java/io/quarkiverse/power/runtime/sensors/linux/rapl/IntelRAPLMeasure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,67 @@ | ||
package io.quarkiverse.power.runtime.sensors.linux.rapl; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import io.quarkiverse.power.runtime.SensorMeasure; | ||
import io.quarkiverse.power.runtime.sensors.IncrementableMeasure; | ||
|
||
public class IntelRAPLMeasure implements IncrementableMeasure { | ||
private final long initial; | ||
private long cpu; | ||
private final long startedAt = System.currentTimeMillis(); | ||
private final Map<String, Accumulator> values = new HashMap<>(); | ||
|
||
static class Accumulator { | ||
private final AtomicLong previous = new AtomicLong(0); | ||
private double accumulated; | ||
|
||
private Accumulator recordNewValue(long currentValue, double share, long duration) { | ||
accumulated += (currentValue - previous.getAndSet(currentValue)) * share / duration; | ||
return this; | ||
} | ||
|
||
public double accumulated() { | ||
return accumulated; | ||
} | ||
} | ||
|
||
double getValue(String name) { | ||
final var value = values.get(name); | ||
return value == null ? 0.0 : value.accumulated() / 1000; | ||
} | ||
|
||
public IntelRAPLMeasure(long initial) { | ||
this.initial = initial; | ||
void updateValue(String name, long current, double cpuShare, long duration) { | ||
values.computeIfAbsent(name, k -> new Accumulator()).recordNewValue(current, cpuShare, duration); | ||
} | ||
|
||
@Override | ||
public double cpu() { | ||
return ((double) cpu / durationSinceStart()) / 1_000; | ||
return getValue("package-0"); | ||
} | ||
|
||
@Override | ||
public void addCPU(double v) { | ||
cpu += ((long) v - initial); | ||
public Optional<Double> gpu() { | ||
return Optional.ofNullable(values.get(SensorMeasure.GPU)).map(value -> value.accumulated() / 1000); | ||
} | ||
|
||
private long durationSinceStart() { | ||
return System.currentTimeMillis() - startedAt; | ||
@Override | ||
public Optional<Double> byKey(String key) { | ||
final var v = IncrementableMeasure.super.byKey(key); // first get from default implementation | ||
if (v.isEmpty()) { | ||
// try local keys | ||
return Optional.ofNullable(values.get(key)).map(value -> value.accumulated() / 1000); | ||
} else { | ||
return v; | ||
} | ||
} | ||
|
||
@Override | ||
public double total() { | ||
return values.values().stream().map(Accumulator::accumulated).reduce(Double::sum).orElse(0.0) / 1000; | ||
} | ||
|
||
@Override | ||
public void addCPU(double v) { | ||
throw new IllegalStateException("Shouldn't be called"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.