File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
backend/src/main/java/net/laprun/sustainability/power/sensors/macos/powermetrics Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments