Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ nb-configuration.xml

# Plugin directory
/.quarkus/cli/plugins/

/output.txt
cli/output.txt
53 changes: 53 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.laprun.sustainability</groupId>
<artifactId>power-server-parent</artifactId>
<version>0.3.0-SNAPSHOT</version>
</parent>

<artifactId>power-server-backend</artifactId>
<name>power-server : backend</name>
<description>Power consumption measuring backend</description>

<dependencies>
<dependency>
<groupId>net.laprun.sustainability</groupId>
<artifactId>power-server-metadata</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-scheduler</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.jdbc</groupId>
<artifactId>quarkus-jdbc-sqlite4j</artifactId>
<version>${sqlite4j.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<configuration>
<configFile>../contributing/eclipse-format.xml</configFile>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public Security(SmallRyeConfig config) {
pwd = config.getConfigValue(SECRET_PROPERTY_KEY).getValue();
if (pwd == null && !isRunningAsAdministrator()) {
throw new IllegalStateException(
"This application requires sudo access. Either provide a sudo secret using the 'power-server.sudo.secret' property or run using sudo.");
"This application requires sudo access. Either provide a sudo secret using the '" +
SECRET_PROPERTY_KEY + "' property or run using sudo.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void scheduled() {

// Execute a backup during shutdown
public void onShutdown(@Observes ShutdownEvent event) {
Log.info("Persisting database on shutdown");
backup();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.quarkus.logging.Log;

public abstract class AbstractPowerSensor<M extends Measures> implements PowerSensor {
// private static final Logger log = Logger.getLogger(AbstractPowerSensor.class);
protected final M measures;

public AbstractPowerSensor(M measures) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.laprun.sustainability.power.sensors.macos.powermetrics;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
* The aim of this sensor is to only perform one long measure and then read the power information from it once done,
*/
public class FileMacOSPowermetricsSensor extends MacOSPowermetricsSensor {
private final File file;
private boolean started;

public FileMacOSPowermetricsSensor(File file) {
this.file = file;
}

@Override
protected InputStream getInputStream() {
try {
return new FileInputStream(file);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public boolean isStarted() {
return started;
}

@Override
public void start(long samplingFrequencyInMillis) {
if (!started) {
started = true;
}
}

@Override
public void stop() {
started = false;
initMetadata(getInputStream());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ Measures extractPowerMeasure(InputStream powerMeasureInput, Long tick) {
pidsToProcess.remove(pid);
break;
}

// todo? if pid is not found, this will loop forever and we should break if ALL_TASKS is reached without draining the pids to process
}
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public ProcessMacOSPowermetricsSensor(Security security) {
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);
frequency = Math.min(0, frequency - 50);
final var freq = Long.toString(frequency);
powermetrics = security.execPowermetrics("cpu_power,tasks", "--show-process-samp-norm", "--show-process-gpu", "-i",
freq);
}
Expand Down
Empty file.
Loading