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: adapt Linux support to new architecture #21

Merged
merged 4 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ power consumption, currently:
- /sys/class/powercap/intel-rapl/intel-rapl:0/intel-rapl:0:2/energy_uj

For the extension to work properly, these files need to be readable by the current user, which you can accomplish by
running `sudo chmod +r` on these files. Note that this change will only persist until the next restart.
running the provided `make_power_readable.sh` script. Note that this change will only persist until the next restart.

## Usage

Expand Down
4 changes: 4 additions & 0 deletions make_power_readable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

sudo find /sys/class/powercap/**/energy_uj -exec chmod +r {} \;

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static PowerMeasurer<? extends SensorMeasure> instance() {

public PowerMeasurer(PowerSensor<M> sensor) {
this.sensor = sensor;
this.onError(null);
}

public double cpuShareOfJVMProcess() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ public void startNewMeasure() {
}

public void setComponent(int index, double value) {
if (current == null) {
throw new IllegalStateException("A new measure must be started before recording components");
}
current[index] = value;
}

public double[] stopMeasure() {
if (current == null) {
throw new IllegalStateException("Measure was not started so cannot be stopped");
}
final var recorded = new double[current.length];
System.arraycopy(current, 0, recorded, 0, current.length);
measures.add(recorded);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ private double computeNewComponentValue(int componentIndex, long sensorValue, do

@Override
public void update(OngoingPowerMeasure ongoingMeasure) {
ongoingMeasure.startNewMeasure();
double cpuShare = PowerMeasurer.instance().cpuShareOfJVMProcess();
for (int i = 0; i < raplFiles.length; i++) {
final var value = raplFiles[i].extractPowerMeasure();
final var newComponentValue = computeNewComponentValue(i, value, cpuShare);
ongoingMeasure.setComponent(i, newComponentValue);
lastMeasuredSensorValues[i] = newComponentValue;
}
ongoingMeasure.stopMeasure();
}

@Override
Expand Down