Skip to content

Commit

Permalink
refactor: use more precise method names, add javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Mar 29, 2024
1 parent 42bc0e5 commit e99e729
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static RAPLFile createFrom(Path file) {
}
}

public long extractPowerMeasure() {
public long extractEnergyInMicroJoules() {
try {
channel.read(buffer);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ public void start(long frequency) {
update(0L);
}

private double computeNewComponentValue(int componentIndex, long sensorValue) {
/**
* Computes the power in mW based on the current, previous energy (in micro Joules) measures and sampling frequency.
* @param componentIndex the index of the component being measured
* @param sensorValue the micro Joules energy reading
* @return the power over the interval defined by the sampling frequency in mW
*/
private double computePowerInMilliWatt(int componentIndex, long sensorValue) {
return (sensorValue - lastMeasuredSensorValues[componentIndex]) / frequency / 1000;
}

Expand All @@ -103,8 +109,8 @@ public RegisteredPID register(long pid) {
public Measures update(Long tick) {
final var measure = new double[raplFiles.length];
for (int i = 0; i < raplFiles.length; i++) {
final var value = raplFiles[i].extractPowerMeasure();
final var newComponentValue = computeNewComponentValue(i, value);
final var value = raplFiles[i].extractEnergyInMicroJoules();
final var newComponentValue = computePowerInMilliWatt(i, value);
measure[i] = newComponentValue;
lastMeasuredSensorValues[i] = newComponentValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.nio.file.Path;

interface RAPLFile {
long extractPowerMeasure();
long extractEnergyInMicroJoules();

static RAPLFile createFrom(Path file) {
return ByteBufferRAPLFile.createFrom(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static void writeThenRead() throws IOException, InterruptedException {
Thread.sleep(50);

final var raplFile = ByteBufferRAPLFile.createFrom(file);
final var measure = raplFile.extractPowerMeasure();
final var measure = raplFile.extractEnergyInMicroJoules();
assertEquals(value, measure);
}
}

0 comments on commit e99e729

Please sign in to comment.