Skip to content

Commit 9df76d4

Browse files
committed
feat: initial power command implementation
1 parent 1735c3d commit 9df76d4

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

cli/pom.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>net.laprun.sustainability</groupId>
6+
<artifactId>power-server-parent</artifactId>
7+
<version>0.3.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>power-server-cli</artifactId>
11+
<name>power-server : cli</name>
12+
<description>A CLI command to measure power consumption of the specified process</description>
13+
<dependencies>
14+
<dependency>
15+
<groupId>net.laprun.sustainability</groupId>
16+
<artifactId>power-server-backend</artifactId>
17+
<version>${project.version}</version>
18+
</dependency>
19+
<dependency>
20+
<groupId>io.quarkus</groupId>
21+
<artifactId>quarkus-picocli</artifactId>
22+
</dependency>
23+
</dependencies>
24+
25+
<build>
26+
<plugins>
27+
<plugin>
28+
<groupId>net.revelc.code.formatter</groupId>
29+
<artifactId>formatter-maven-plugin</artifactId>
30+
<configuration>
31+
<configFile>../contributing/eclipse-format.xml</configFile>
32+
</configuration>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
37+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package net.laprun.sustainability.cli;
2+
3+
import java.util.List;
4+
5+
import net.laprun.sustainability.power.PowerMeasurer;
6+
import picocli.CommandLine;
7+
8+
@CommandLine.Command
9+
public class Power implements Runnable {
10+
11+
@CommandLine.Parameters(hidden = true)
12+
List<String> cmd;
13+
14+
@CommandLine.Option(names = { "-n",
15+
"--name" }, description = "Optional name for the application, defaults to passed command line")
16+
String name;
17+
18+
private final PowerMeasurer measurer;
19+
20+
public Power(PowerMeasurer measurer) {
21+
this.measurer = measurer;
22+
}
23+
24+
@Override
25+
public void run() {
26+
final var command = new ProcessBuilder().command(cmd);
27+
final var start = System.nanoTime();
28+
try {
29+
final var process = command.start();
30+
var duration = System.nanoTime() - start;
31+
System.out.println("start duration: " + duration);
32+
final var processTracker = measurer.startTrackingProcess(process);
33+
process.onExit().thenAccept(unused -> processTracker.cancel());
34+
} catch (Exception e) {
35+
throw new RuntimeException(e);
36+
}
37+
}
38+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
quarkus.datasource.jdbc.url=jdbc:sqlite:${power-server.db.backup.location}
2+
quarkus.datasource.db-kind=sqlite
3+
quarkus.datasource.jdbc.min-size=1
4+
5+
power-server.db.backup.period=5m
6+
power-server.db.backup.location=${HOME}/.power-server/db.sqlite
7+
8+
# Only use this property once to create the initial database
9+
# quarkus.hibernate-orm.database.generation=create

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<module>backend</module>
7575
<module>analysis</module>
7676
<module>server</module>
77+
<module>cli</module>
7778
<module>if-manifest-export</module>
7879
</modules>
7980

0 commit comments

Comments
 (0)