From 784b4d1c58229453a154d429fc056d7046fb0bd1 Mon Sep 17 00:00:00 2001 From: Mirko Stocker Date: Tue, 6 Aug 2024 14:27:25 +0200 Subject: [PATCH 1/4] allow to set the config.properties through system property --- README.md | 2 +- .../java/org/noureddine/joularjx/utils/AgentProperties.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7f665f8..ea55950 100755 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ JoularJX can be configured by modifying the ```config.properties``` files: - ```vm-power-format```: power format of the shared VM power file. We currently support two formats: ```watts``` (a file containing one float value which is the power consumption of the VM), and ```powerjoular``` (a csv file generated by [PowerJoular](https://github.com/joular/powerjoular) in the host, containing 3 columns: timestamp, CPU utilization of the VM and CPU power of the VM). You can install the jar package (and the PowerMonitor.exe on Windows) wherever you want, and call it in the ```javaagent``` with the full path. -However, ```config.properties``` must be copied to the same folder as where you run the Java command. +However, ```config.properties``` must either be copied to the same folder as where you run the Java command or its location must be set with the ```-Djoularjx.config=/path/to/config.properties``` property when running your program. In virtual machines, JoularJX requires two steps: - Installing a power monitoring tool in the host machine, which will monitor the virtual machine power consumption every second and writing it to a file (to be shared with the guest VM). diff --git a/src/main/java/org/noureddine/joularjx/utils/AgentProperties.java b/src/main/java/org/noureddine/joularjx/utils/AgentProperties.java index b2b276d..fba9628 100644 --- a/src/main/java/org/noureddine/joularjx/utils/AgentProperties.java +++ b/src/main/java/org/noureddine/joularjx/utils/AgentProperties.java @@ -232,7 +232,7 @@ public int loadStackMonitoringSampleRate() { } private Optional getPropertiesPathIfExists(FileSystem fileSystem) { - Path path = fileSystem.getPath("config.properties"); + Path path = fileSystem.getPath(System.getProperty("joularjx.config", "config.properties")); if (Files.notExists(path)) { logger.log(Level.INFO, "Could not locate config.properties, will use default values"); From 2ed592c480aec54084eba0781fc47b181ae68684 Mon Sep 17 00:00:00 2001 From: Adel Noureddine Date: Wed, 13 Nov 2024 18:37:13 +0100 Subject: [PATCH 2/4] Show severe log but don't exit when one of RAPL files cannot be read --- src/main/java/org/noureddine/joularjx/cpu/RaplLinux.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/noureddine/joularjx/cpu/RaplLinux.java b/src/main/java/org/noureddine/joularjx/cpu/RaplLinux.java index 06bbe52..b33333c 100644 --- a/src/main/java/org/noureddine/joularjx/cpu/RaplLinux.java +++ b/src/main/java/org/noureddine/joularjx/cpu/RaplLinux.java @@ -138,7 +138,7 @@ public double getCurrentPower(final double cpuLoad) { try { energyData += Double.parseDouble(Files.readString(raplFile)); } catch (IOException exception) { - logger.throwing(getClass().getName(), "getCurrentPower", exception); + logger.log(Level.SEVERE, "Failed to read one of RAPL files: " + raplFile, exception); } } From 2e0201560e2f5c7e4a4d9188689b94bcdac111fd Mon Sep 17 00:00:00 2001 From: Adel Noureddine Date: Tue, 19 Nov 2024 09:49:18 +0100 Subject: [PATCH 3/4] Don't exit when DRAM energy is not read --- .../noureddine/joularjx/cpu/RaplLinux.java | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/noureddine/joularjx/cpu/RaplLinux.java b/src/main/java/org/noureddine/joularjx/cpu/RaplLinux.java index b33333c..cba519d 100644 --- a/src/main/java/org/noureddine/joularjx/cpu/RaplLinux.java +++ b/src/main/java/org/noureddine/joularjx/cpu/RaplLinux.java @@ -79,30 +79,51 @@ public void initialize() { final Path psysFile = fileSystem.getPath(RAPL_PSYS); final Path psysMaxFile = fileSystem.getPath(RAPL_PSYS_MAX); if (Files.exists(psysFile)) { - checkFileReadable(psysFile); - checkFileReadable(psysMaxFile); // psys exists, so use this for energy readings - raplFilesToRead.add(psysFile); - maxRaplFilesToRead.add(psysMaxFile); + if (Files.isReadable(psysFile)) { + raplFilesToRead.add(psysFile); + if (Files.isReadable(psysMaxFile)) { + maxRaplFilesToRead.add(psysMaxFile); + } else { + logger.log(Level.SEVERE, "Failed to get read" + psysMaxFile + " file. Exiting... Did you run JoularJX with elevated privileges (sudo)?"); + System.exit(1); + } + } else { + logger.log(Level.SEVERE, "Failed to get RAPL energy readings from" + psysFile + " file. Exiting... Did you run JoularJX with elevated privileges (sudo)?"); + System.exit(1); + } } else { // No psys supported, then check for pkg and dram final Path pkgFile = fileSystem.getPath(RAPL_PKG); final Path pkgMaxFile = fileSystem.getPath(RAPL_PKG_MAX); if (Files.exists(pkgFile)) { - checkFileReadable(pkgFile); - checkFileReadable(pkgMaxFile); - // pkg exists, check also for dram - raplFilesToRead.add(pkgFile); - maxRaplFilesToRead.add(pkgMaxFile); + if (Files.isReadable(pkgFile)) { + raplFilesToRead.add(pkgFile); + if (Files.isReadable(pkgMaxFile)) { + maxRaplFilesToRead.add(pkgMaxFile); + } else { + logger.log(Level.SEVERE, "Failed to get read" + pkgMaxFile + " file. Exiting... Did you run JoularJX with elevated privileges (sudo)?"); + System.exit(1); + } + } else { + logger.log(Level.SEVERE, "Failed to get RAPL energy readings from" + pkgFile + " file. Exiting... Did you run JoularJX with elevated privileges (sudo)?"); + System.exit(1); + } final Path dramFile = fileSystem.getPath(RAPL_DRAM); final Path dramMaxFile = fileSystem.getPath(RAPL_DRAM_MAX); if (Files.exists(dramFile)) { - checkFileReadable(dramFile); - checkFileReadable(dramMaxFile); - // dram and pkg exists, then get sum of both - raplFilesToRead.add(dramFile); - maxRaplFilesToRead.add(dramMaxFile); + if (Files.isReadable(dramFile)) { + raplFilesToRead.add(dramFile); + if (Files.isReadable(dramMaxFile)) { + maxRaplFilesToRead.add(dramMaxFile); + } else { + logger.log(Level.SEVERE, "Failed to get read" + dramMaxFile + " file. Exiting... Did you run JoularJX with elevated privileges (sudo)?"); + System.exit(1); + } + } else { + logger.log(Level.WARNING, "Failed to get RAPL energy readings from" + dramFile + " file. Continuing without it."); + } } } } @@ -113,18 +134,6 @@ public void initialize() { } } - /** - * Check that the passed file can be read by the program. Log error message and exit if reading the file is not - * possible. - * @param file the file to check the read access - */ - private void checkFileReadable(final Path file) { - if (!Files.isReadable(file)) { - logger.log(Level.SEVERE, "Failed to get RAPL energy readings. Did you run JoularJX with elevated privileges (sudo)?"); - System.exit(1); - } - } - /** * Get energy readings from RAPL through powercap * Calculates the best energy reading as supported by CPU (psys, or pkg+dram, or pkg) @@ -138,7 +147,7 @@ public double getCurrentPower(final double cpuLoad) { try { energyData += Double.parseDouble(Files.readString(raplFile)); } catch (IOException exception) { - logger.log(Level.SEVERE, "Failed to read one of RAPL files: " + raplFile, exception); + logger.throwing(getClass().getName(), "getCurrentPower", exception); } } From 3740fa7b4cd51c69a4cde48d271c8443c22d7c6c Mon Sep 17 00:00:00 2001 From: Adel Noureddine Date: Tue, 19 Nov 2024 11:16:37 +0100 Subject: [PATCH 4/4] Prepare 3.0.1 release --- config.properties | 2 +- pom.xml | 8 ++++---- src/main/java/org/noureddine/joularjx/Agent.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config.properties b/config.properties index 7946548..e3f9c39 100644 --- a/config.properties +++ b/config.properties @@ -77,7 +77,7 @@ powermonitor-path=C:\\joularjx\\PowerMonitor.exe # Monitoring inside virtual machines # Values: true, false -vm-monitoring=true +vm-monitoring=false # Path for power consumption of the virtual machine # Inside a virtual machine, indicate the file containing power consumption of the VM diff --git a/pom.xml b/pom.xml index 9c4a1d5..6dd07a2 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ org.noureddine joularjx - 3.0.0 + 3.0.1 jar ${project.artifactId} @@ -61,7 +61,7 @@ com.github.marschall memoryfilesystem - 2.8.0 + 2.8.1 test @@ -71,7 +71,7 @@ org.junit junit-bom - 5.10.2 + 5.11.3 import pom @@ -110,7 +110,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.3.0 + 3.5.2 diff --git a/src/main/java/org/noureddine/joularjx/Agent.java b/src/main/java/org/noureddine/joularjx/Agent.java index 9a14ab9..29b5ae7 100644 --- a/src/main/java/org/noureddine/joularjx/Agent.java +++ b/src/main/java/org/noureddine/joularjx/Agent.java @@ -46,7 +46,7 @@ public static void premain(String args, Instrumentation inst) { JoularJXLogging.updateLevel(properties.getLoggerLevel()); logger.info("+---------------------------------+"); - logger.info("| JoularJX Agent Version 3.0.0 |"); + logger.info("| JoularJX Agent Version 3.0.1 |"); logger.info("+---------------------------------+"); ThreadMXBean threadBean = createThreadBean();