Skip to content

Commit 7b73935

Browse files
committed
feat: add file-backed sensor
1 parent fc8317c commit 7b73935

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package net.laprun.sustainability.power.sensors.macos.powermetrics;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.InputStream;
6+
7+
/**
8+
* The aim of this sensor is to only perform one long measure and then read the power information from it once done,
9+
*/
10+
public class FileMacOSPowermetricsSensor extends MacOSPowermetricsSensor {
11+
private final File file;
12+
private boolean started;
13+
14+
public FileMacOSPowermetricsSensor(File file) {
15+
this.file = file;
16+
}
17+
18+
@Override
19+
protected InputStream getInputStream() {
20+
try {
21+
return new FileInputStream(file);
22+
} catch (Exception e) {
23+
throw new RuntimeException(e);
24+
}
25+
}
26+
27+
@Override
28+
public boolean isStarted() {
29+
return started;
30+
}
31+
32+
@Override
33+
public void start(long samplingFrequencyInMillis) {
34+
if (!started) {
35+
started = true;
36+
}
37+
}
38+
39+
@Override
40+
public void stop() {
41+
started = false;
42+
initMetadata(getInputStream());
43+
}
44+
}

0 commit comments

Comments
 (0)