diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0f6e824 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,39 @@ +# IDE Config and Code Style + +This project has a strictly enforced code style. Code formatting is done by the Eclipse code +formatter, using the config files found in the `build-tools` directory. By +default when you run `mvn install` the code will be formatted automatically. When submitting a +pull request the CI build will fail if running the formatter results in any code changes, so it is +recommended that you always run a full Maven build before submitting a pull request. + +If you want to run the formatting without doing a full build, you can run `mvn process-sources`. + +#### Eclipse Setup + +Open the *Preferences* window, and then navigate to _Java_ -> _Code Style_ -> _Formatter_. Click _ +Import_ and then select the `eclipse-format.xml` file in the `build-tools` +directory. + +Next navigate to _Java_ -> _Code Style_ -> _Organize Imports_. Click _Import_ and select +the `eclipse.importorder` file. + +#### IDEA Setup + +Open the _Preferences_ window (or _Settings_ depending on your edition), navigate to _Plugins_ and +install +the [Eclipse Code Formatter Plugin](https://plugins.jetbrains.com/plugin/6546-eclipse-code-formatter) +from the Marketplace. + +Restart your IDE, open the *Preferences* (or *Settings*) window again and navigate to _Other +Settings_ -> _Eclipse Code Formatter_. + +Select _Use the Eclipse Code Formatter_, then change the _Eclipse Java Formatter Config File_ to +point to the +`eclipse-format.xml` file in the `build-tools` directory. Make sure the _ +Optimize Imports_ box is ticked, and select the `eclipse.importorder` file as the import order +config file. + +Next, disable wildcard imports: +navigate to _Editor_ -> _Code Style_ -> _Java_ -> _Imports_ +and set _Class count to use import with '\*'_ to `999`. Do the same with _Names count to use static +import with '\*'_. \ No newline at end of file diff --git a/build-tools/pom.xml b/build-tools/pom.xml new file mode 100644 index 0000000..20ba661 --- /dev/null +++ b/build-tools/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + + io.github.metacosm + power-server-parent + 1.0.0-SNAPSHOT + + + build-tools + + + \ No newline at end of file diff --git a/build-tools/src/main/resources/eclipse-format.xml b/build-tools/src/main/resources/eclipse-format.xml new file mode 100644 index 0000000..f6e4206 --- /dev/null +++ b/build-tools/src/main/resources/eclipse-format.xml @@ -0,0 +1,322 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build-tools/src/main/resources/eclipse.importorder b/build-tools/src/main/resources/eclipse.importorder new file mode 100644 index 0000000..e432229 --- /dev/null +++ b/build-tools/src/main/resources/eclipse.importorder @@ -0,0 +1,7 @@ +#Organize Import Order +#Wed Jan 23 12:03:29 AEDT 2019 +0=java +1=javax +2=jakarta +3=org +4=com diff --git a/metadata/pom.xml b/metadata/pom.xml index f72c320..c708d97 100644 --- a/metadata/pom.xml +++ b/metadata/pom.xml @@ -12,5 +12,21 @@ power-server-metadata - + + + + + net.revelc.code.formatter + formatter-maven-plugin + + + io.github.metacosm + build-tools + 1.0.0-SNAPSHOT + + + + + + \ No newline at end of file diff --git a/metadata/src/main/java/io/github/metacosm/power/SensorMetadata.java b/metadata/src/main/java/io/github/metacosm/power/SensorMetadata.java index 617e9c0..04db301 100644 --- a/metadata/src/main/java/io/github/metacosm/power/SensorMetadata.java +++ b/metadata/src/main/java/io/github/metacosm/power/SensorMetadata.java @@ -1,16 +1,18 @@ package io.github.metacosm.power; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.Collections; import java.util.Map; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + public class SensorMetadata { - public record ComponentMetadata(String name, int index, String description, boolean isAttributed, String unit){} + public record ComponentMetadata(String name, int index, String description, boolean isAttributed, String unit) { + } @JsonCreator - public SensorMetadata(@JsonProperty("metadata") Map components, @JsonProperty("documentation") String documentation) { + public SensorMetadata(@JsonProperty("metadata") Map components, + @JsonProperty("documentation") String documentation) { this.components = components; this.documentation = documentation; } diff --git a/pom.xml b/pom.xml index 05c51c8..6d924ed 100644 --- a/pom.xml +++ b/pom.xml @@ -17,9 +17,12 @@ 3.7.0.CR1 true 3.1.2 + 2.23.0 + 1.9.0 + build-tools server metadata @@ -110,9 +113,76 @@ + + net.revelc.code.formatter + formatter-maven-plugin + ${formatter-plugin.version} + + + 17 + eclipse-format.xml + LF + ${format.skip} + + + + net.revelc.code + impsort-maven-plugin + ${impsort-plugin.version} + + + 17 + java.,javax.,jakarta.,org.,com. + * + ${format.skip} + true + + + + format + + + + !no-format + + + + + + net.revelc.code.formatter + formatter-maven-plugin + + + format-sources + process-sources + + format + + + + + + net.revelc.code + impsort-maven-plugin + + true + + + + sort-imports + process-sources + + sort + + + + + + + native diff --git a/server/pom.xml b/server/pom.xml index 06e2210..b97c7c0 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -22,5 +22,22 @@ 1.0.0-SNAPSHOT + + + + + net.revelc.code.formatter + formatter-maven-plugin + + + io.github.metacosm + build-tools + 1.0.0-SNAPSHOT + + + + + + \ No newline at end of file diff --git a/server/src/main/java/io/github/metacosm/power/PowerMeasurer.java b/server/src/main/java/io/github/metacosm/power/PowerMeasurer.java index 656e0e9..047d0c6 100644 --- a/server/src/main/java/io/github/metacosm/power/PowerMeasurer.java +++ b/server/src/main/java/io/github/metacosm/power/PowerMeasurer.java @@ -1,13 +1,14 @@ package io.github.metacosm.power; +import java.time.Duration; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + import io.github.metacosm.power.sensors.Measures; import io.github.metacosm.power.sensors.PowerSensor; import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.infrastructure.Infrastructure; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; - -import java.time.Duration; @ApplicationScoped public class PowerMeasurer { diff --git a/server/src/main/java/io/github/metacosm/power/PowerResource.java b/server/src/main/java/io/github/metacosm/power/PowerResource.java index 88c60b6..81a193d 100644 --- a/server/src/main/java/io/github/metacosm/power/PowerResource.java +++ b/server/src/main/java/io/github/metacosm/power/PowerResource.java @@ -1,11 +1,13 @@ package io.github.metacosm.power; -import io.smallrye.mutiny.Multi; import jakarta.inject.Inject; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; + import org.jboss.resteasy.reactive.RestStreamElementType; +import io.smallrye.mutiny.Multi; + @Path("/power") public class PowerResource { @Inject diff --git a/server/src/main/java/io/github/metacosm/power/sensors/Measures.java b/server/src/main/java/io/github/metacosm/power/sensors/Measures.java index d69eb5e..297c3b0 100644 --- a/server/src/main/java/io/github/metacosm/power/sensors/Measures.java +++ b/server/src/main/java/io/github/metacosm/power/sensors/Measures.java @@ -1,11 +1,12 @@ package io.github.metacosm.power.sensors; -import io.github.metacosm.power.SensorMeasure; - import java.util.Set; +import io.github.metacosm.power.SensorMeasure; + public interface Measures { - SensorMeasure missing = new SensorMeasure(new double[]{-1.0}, -1); + SensorMeasure missing = new SensorMeasure(new double[] { -1.0 }, -1); + RegisteredPID register(long pid); void unregister(RegisteredPID registeredPID); diff --git a/server/src/main/java/io/github/metacosm/power/sensors/PowerSensor.java b/server/src/main/java/io/github/metacosm/power/sensors/PowerSensor.java index ee5aab5..9a9cf87 100644 --- a/server/src/main/java/io/github/metacosm/power/sensors/PowerSensor.java +++ b/server/src/main/java/io/github/metacosm/power/sensors/PowerSensor.java @@ -1,10 +1,7 @@ package io.github.metacosm.power.sensors; -import io.github.metacosm.power.SensorMeasure; import io.github.metacosm.power.SensorMetadata; -import java.util.Map; - public interface PowerSensor { default void stop() { diff --git a/server/src/main/java/io/github/metacosm/power/sensors/PowerSensorProducer.java b/server/src/main/java/io/github/metacosm/power/sensors/PowerSensorProducer.java index 61ef83c..4e21c63 100644 --- a/server/src/main/java/io/github/metacosm/power/sensors/PowerSensorProducer.java +++ b/server/src/main/java/io/github/metacosm/power/sensors/PowerSensorProducer.java @@ -1,10 +1,11 @@ package io.github.metacosm.power.sensors; -import io.github.metacosm.power.sensors.linux.rapl.IntelRAPLSensor; -import io.github.metacosm.power.sensors.macos.powermetrics.MacOSPowermetricsSensor; import jakarta.enterprise.inject.Produces; import jakarta.inject.Singleton; +import io.github.metacosm.power.sensors.linux.rapl.IntelRAPLSensor; +import io.github.metacosm.power.sensors.macos.powermetrics.MacOSPowermetricsSensor; + @Singleton public class PowerSensorProducer { private static final String OS_NAME = System.getProperty("os.name").toLowerCase(); diff --git a/server/src/main/java/io/github/metacosm/power/sensors/linux/rapl/IntelRAPLSensor.java b/server/src/main/java/io/github/metacosm/power/sensors/linux/rapl/IntelRAPLSensor.java index 23f613f..1a4b9f2 100644 --- a/server/src/main/java/io/github/metacosm/power/sensors/linux/rapl/IntelRAPLSensor.java +++ b/server/src/main/java/io/github/metacosm/power/sensors/linux/rapl/IntelRAPLSensor.java @@ -1,16 +1,15 @@ package io.github.metacosm.power.sensors.linux.rapl; -import io.github.metacosm.power.SensorMeasure; -import io.github.metacosm.power.SensorMetadata; -import io.github.metacosm.power.sensors.Measures; -import io.github.metacosm.power.sensors.PowerSensor; -import io.github.metacosm.power.sensors.RegisteredPID; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; +import io.github.metacosm.power.SensorMeasure; +import io.github.metacosm.power.SensorMetadata; +import io.github.metacosm.power.sensors.Measures; +import io.github.metacosm.power.sensors.PowerSensor; +import io.github.metacosm.power.sensors.RegisteredPID; public class IntelRAPLSensor implements PowerSensor { private final RAPLFile[] raplFiles; @@ -37,7 +36,8 @@ public IntelRAPLSensor() { for (String name : files.keySet()) { metadata.put(name, new SensorMetadata.ComponentMetadata(name, fileNb++, name, false, "µJ")); } - this.metadata = new SensorMetadata(metadata, "Linux RAPL derived information, see https://www.kernel.org/doc/html/latest/power/powercap/powercap.html"); + this.metadata = new SensorMetadata(metadata, + "Linux RAPL derived information, see https://www.kernel.org/doc/html/latest/power/powercap/powercap.html"); lastMeasuredSensorValues = new double[raplFiles.length]; } @@ -66,7 +66,6 @@ private static boolean isReadable(Path file) { return Files.exists(file) && Files.isReadable(file); } - @Override public void start(long frequency) throws Exception { this.frequency = frequency; diff --git a/server/src/main/java/io/github/metacosm/power/sensors/linux/rapl/SingleMeasureMeasures.java b/server/src/main/java/io/github/metacosm/power/sensors/linux/rapl/SingleMeasureMeasures.java index b946efe..dfe5e16 100644 --- a/server/src/main/java/io/github/metacosm/power/sensors/linux/rapl/SingleMeasureMeasures.java +++ b/server/src/main/java/io/github/metacosm/power/sensors/linux/rapl/SingleMeasureMeasures.java @@ -1,15 +1,16 @@ package io.github.metacosm.power.sensors.linux.rapl; +import java.util.HashSet; +import java.util.Set; + import io.github.metacosm.power.SensorMeasure; import io.github.metacosm.power.sensors.Measures; import io.github.metacosm.power.sensors.RegisteredPID; -import java.util.HashSet; -import java.util.Set; - public class SingleMeasureMeasures implements Measures { private final Set trackedPIDs = new HashSet<>(); private SensorMeasure measure; + void singleMeasure(SensorMeasure sensorMeasure) { this.measure = sensorMeasure; } @@ -38,7 +39,7 @@ public int numberOfTrackerPIDs() { @Override public void record(RegisteredPID pid, SensorMeasure sensorMeasure) { - throw new UnsupportedOperationException("Shouldn't be needed"); + throw new UnsupportedOperationException("Shouldn't be needed"); } @Override diff --git a/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/AppleSiliconCPU.java b/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/AppleSiliconCPU.java index a010439..f83d93e 100644 --- a/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/AppleSiliconCPU.java +++ b/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/AppleSiliconCPU.java @@ -1,17 +1,21 @@ package io.github.metacosm.power.sensors.macos.powermetrics; -import io.github.metacosm.power.SensorMetadata; +import static io.github.metacosm.power.sensors.macos.powermetrics.MacOSPowermetricsSensor.*; import java.util.HashMap; import java.util.Map; -import static io.github.metacosm.power.sensors.macos.powermetrics.MacOSPowermetricsSensor.*; +import io.github.metacosm.power.SensorMetadata; class AppleSiliconCPU extends io.github.metacosm.power.sensors.macos.powermetrics.CPU { - private static final SensorMetadata.ComponentMetadata cpuComponent = new SensorMetadata.ComponentMetadata(CPU, 0, "CPU power", true, "mW"); - private static final SensorMetadata.ComponentMetadata gpuComponent = new SensorMetadata.ComponentMetadata(GPU, 1, "GPU power", true, "mW"); - private static final SensorMetadata.ComponentMetadata aneComponent = new SensorMetadata.ComponentMetadata(ANE, 2, "Apple Neural Engine power", false, "mW"); - private static final SensorMetadata.ComponentMetadata cpuShareComponent = new SensorMetadata.ComponentMetadata(CPU_SHARE, 3, "Computed share of CPU", false, "decimal percentage"); + private static final SensorMetadata.ComponentMetadata cpuComponent = new SensorMetadata.ComponentMetadata(CPU, 0, + "CPU power", true, "mW"); + private static final SensorMetadata.ComponentMetadata gpuComponent = new SensorMetadata.ComponentMetadata(GPU, 1, + "GPU power", true, "mW"); + private static final SensorMetadata.ComponentMetadata aneComponent = new SensorMetadata.ComponentMetadata(ANE, 2, + "Apple Neural Engine power", false, "mW"); + private static final SensorMetadata.ComponentMetadata cpuShareComponent = new SensorMetadata.ComponentMetadata(CPU_SHARE, 3, + "Computed share of CPU", false, "decimal percentage"); private static final String COMBINED = "Combined"; private static final String POWER_INDICATOR = " Power: "; private static final int POWER_INDICATOR_LENGTH = POWER_INDICATOR.length(); diff --git a/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/CPU.java b/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/CPU.java index 6e317dd..487a9fb 100644 --- a/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/CPU.java +++ b/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/CPU.java @@ -1,10 +1,10 @@ package io.github.metacosm.power.sensors.macos.powermetrics; -import io.github.metacosm.power.SensorMetadata; - import java.util.HashMap; import java.util.Map; +import io.github.metacosm.power.SensorMetadata; + abstract class CPU { private SensorMetadata metadata; diff --git a/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/IntelCPU.java b/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/IntelCPU.java index 2d0d17d..068ea15 100644 --- a/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/IntelCPU.java +++ b/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/IntelCPU.java @@ -1,23 +1,25 @@ package io.github.metacosm.power.sensors.macos.powermetrics; -import io.github.metacosm.power.SensorMetadata; +import static io.github.metacosm.power.sensors.macos.powermetrics.MacOSPowermetricsSensor.CPU_SHARE; +import static io.github.metacosm.power.sensors.macos.powermetrics.MacOSPowermetricsSensor.PACKAGE; import java.util.HashMap; import java.util.Map; -import static io.github.metacosm.power.sensors.macos.powermetrics.MacOSPowermetricsSensor.CPU_SHARE; -import static io.github.metacosm.power.sensors.macos.powermetrics.MacOSPowermetricsSensor.PACKAGE; +import io.github.metacosm.power.SensorMetadata; class IntelCPU extends CPU { - private static final SensorMetadata.ComponentMetadata packageComponent = new SensorMetadata.ComponentMetadata(PACKAGE, 0, "Intel energy model derived package power (CPUs+GT+SA)", true, "W"); - private static final SensorMetadata.ComponentMetadata cpuShareComponent = new SensorMetadata.ComponentMetadata(CPU_SHARE, 1, "Computed share of CPU", false, "decimal percentage"); + private static final SensorMetadata.ComponentMetadata packageComponent = new SensorMetadata.ComponentMetadata(PACKAGE, 0, + "Intel energy model derived package power (CPUs+GT+SA)", true, "W"); + private static final SensorMetadata.ComponentMetadata cpuShareComponent = new SensorMetadata.ComponentMetadata(CPU_SHARE, 1, + "Computed share of CPU", false, "decimal percentage"); @Override public boolean doneExtractingPowerComponents(String line, HashMap powerComponents) { // line should look like: Intel energy model derived package power (CPUs+GT+SA): 8.53W final var powerIndex = line.indexOf("Intel "); - if(powerIndex >= 0) { + if (powerIndex >= 0) { final var powerStartIndex = line.indexOf(':') + 1; final float value; try { diff --git a/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/MacOSPowermetricsSensor.java b/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/MacOSPowermetricsSensor.java index 9084650..0ad7575 100644 --- a/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/MacOSPowermetricsSensor.java +++ b/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/MacOSPowermetricsSensor.java @@ -1,11 +1,5 @@ package io.github.metacosm.power.sensors.macos.powermetrics; -import io.github.metacosm.power.SensorMeasure; -import io.github.metacosm.power.SensorMetadata; -import io.github.metacosm.power.sensors.Measures; -import io.github.metacosm.power.sensors.PowerSensor; -import io.github.metacosm.power.sensors.RegisteredPID; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -13,9 +7,14 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; +import io.github.metacosm.power.SensorMeasure; +import io.github.metacosm.power.SensorMetadata; +import io.github.metacosm.power.sensors.Measures; +import io.github.metacosm.power.sensors.PowerSensor; +import io.github.metacosm.power.sensors.RegisteredPID; + public class MacOSPowermetricsSensor implements PowerSensor { public static final String CPU = "CPU"; public static final String GPU = "GPU"; @@ -76,7 +75,8 @@ CPU initMetadata(InputStream inputStream) { throw new IllegalStateException("Couldn't determine CPU family from powermetrics output"); } - final var metadata = new SensorMetadata(components, "macOS powermetrics derived information, see https://firefox-source-docs.mozilla.org/performance/powermetrics.html"); + final var metadata = new SensorMetadata(components, + "macOS powermetrics derived information, see https://firefox-source-docs.mozilla.org/performance/powermetrics.html"); cpu.setMetadata(metadata); return cpu; } catch (IOException e) { @@ -163,7 +163,7 @@ Measures extractPowerMeasure(InputStream powerMeasureInput, Long tick) { // we need an exit condition to break out of the loop, otherwise we'll just keep looping forever since there are always new lines since the process is periodical // fixme: perhaps we should relaunch the process on each update loop instead of keeping it running? Not sure which is more efficient - if(cpu.doneExtractingPowerComponents(line, powerComponents)) { + if (cpu.doneExtractingPowerComponents(line, powerComponents)) { break; } } @@ -204,7 +204,8 @@ public void start(long frequency) throws Exception { if (!isStarted()) { // it takes some time for the external process in addition to the sampling time so adjust the sampling frequency to account for this so that at most one measure occurs during the sampling time window final var freq = Long.toString(frequency - 50); - powermetrics = new ProcessBuilder().command("sudo", "powermetrics", "--samplers", "cpu_power,tasks", "--show-process-samp-norm", "--show-process-gpu", "-i", freq).start(); + powermetrics = new ProcessBuilder().command("sudo", "powermetrics", "--samplers", "cpu_power,tasks", + "--show-process-samp-norm", "--show-process-gpu", "-i", freq).start(); } } diff --git a/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/MapMeasures.java b/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/MapMeasures.java index 2bc9626..db1412b 100644 --- a/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/MapMeasures.java +++ b/server/src/main/java/io/github/metacosm/power/sensors/macos/powermetrics/MapMeasures.java @@ -1,13 +1,13 @@ package io.github.metacosm.power.sensors.macos.powermetrics; -import io.github.metacosm.power.SensorMeasure; -import io.github.metacosm.power.sensors.Measures; -import io.github.metacosm.power.sensors.RegisteredPID; - import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import io.github.metacosm.power.SensorMeasure; +import io.github.metacosm.power.sensors.Measures; +import io.github.metacosm.power.sensors.RegisteredPID; + class MapMeasures implements Measures { private final ConcurrentMap measures = new ConcurrentHashMap<>(); diff --git a/server/src/test/java/io/github/metacosm/PowerResourceTest.java b/server/src/test/java/io/github/metacosm/PowerResourceTest.java index 6c57516..beb9763 100644 --- a/server/src/test/java/io/github/metacosm/PowerResourceTest.java +++ b/server/src/test/java/io/github/metacosm/PowerResourceTest.java @@ -1,16 +1,17 @@ package io.github.metacosm; -import io.github.metacosm.power.SensorMetadata; -import io.quarkus.test.junit.QuarkusTest; +import static io.restassured.RestAssured.given; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Set; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.condition.OS; -import java.util.Set; - -import static io.restassured.RestAssured.given; -import static org.junit.jupiter.api.Assertions.*; +import io.github.metacosm.power.SensorMetadata; +import io.quarkus.test.junit.QuarkusTest; @QuarkusTest public class PowerResourceTest { @@ -86,4 +87,4 @@ public void testLinuxMetadataEndpoint() { assertTrue(metadata.documentation().contains("RAPL")); } -} \ No newline at end of file +} diff --git a/server/src/test/java/io/github/metacosm/power/sensors/macos/powermetrics/MacOSPowermetricsSensorTest.java b/server/src/test/java/io/github/metacosm/power/sensors/macos/powermetrics/MacOSPowermetricsSensorTest.java index 6a704e3..5363477 100644 --- a/server/src/test/java/io/github/metacosm/power/sensors/macos/powermetrics/MacOSPowermetricsSensorTest.java +++ b/server/src/test/java/io/github/metacosm/power/sensors/macos/powermetrics/MacOSPowermetricsSensorTest.java @@ -1,14 +1,15 @@ package io.github.metacosm.power.sensors.macos.powermetrics; -import io.github.metacosm.power.SensorMetadata; -import io.github.metacosm.power.sensors.Measures; -import io.github.metacosm.power.sensors.RegisteredPID; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.io.InputStream; -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; + +import io.github.metacosm.power.SensorMetadata; +import io.github.metacosm.power.sensors.Measures; +import io.github.metacosm.power.sensors.RegisteredPID; class MacOSPowermetricsSensorTest { @@ -59,10 +60,12 @@ private static void checkComponent(SensorMetadata metadata, String name, int ind void extractPowerMeasureForM1Max() { checkPowerMeasure("sonoma-m1max.txt", 211, MacOSPowermetricsSensor.CPU); } + @Test void extractPowerMeasureForM2() { checkPowerMeasure("monterey-m2.txt", 10, MacOSPowermetricsSensor.CPU); } + @Test void extractPowerMeasureForIntel() { checkPowerMeasure("sonoma-intel.txt", 8.53f, MacOSPowermetricsSensor.PACKAGE);