joular / joularjx

JoularJX is a Java-based agent for software power monitoring at the source code level.
https://www.noureddine.org/research/joular/joularjx
GNU General Public License v3.0
71 stars 17 forks source link

JoularJX does not save the energy consumption data for the java code running for JMH becnchmark. #64

Closed ankitkumarsindhu closed 2 months ago

ankitkumarsindhu commented 6 months ago

I have been running some test on java code with JMH and getting the details of energy consumption with JoularJX but for a specifc example it does not record the energy consumption details for anything instead it creates the similar folder structure as it creates for any test running with Joular, and the total-method energy file is empty even though the number of forks are set to 5 and the measurement iterations are 15. The sample I am using:

Is it because of vector operations used in the sample code? or something else.

Sample: @Benchmark @Warmup(iterations = 4) @Measurement(iterations = 6) @BenchmarkMode({ Mode.AverageTime }) @OutputTimeUnit(TimeUnit.MICROSECONDS) @Fork(jvmArgs = "--add-modules=jdk.incubator.vector", value = 2) public void testVectorMultiply(ArraysState state, Blackhole blackhole) { int[] result2 = multiply(state.a, state.b); blackhole.consume(result2); }

private static int[] multiply(int[] array1, int[] array2) {
    int[] multiplication = new int[array1.length];
    int vectorSize = SPECIES.length();
    int vectorCount = array1.length / vectorSize;
    for (int i = 0; i < vectorCount; i++) {
        IntVector vector1 = IntVector.fromArray(SPECIES, array1, i * vectorSize);
        IntVector vector2 = IntVector.fromArray(SPECIES, array2, i * vectorSize);
        IntVector resultVector = vector1.mul(vector2);
        resultVector.intoArray(multiplication, i * vectorSize);
    }
    // Perform remaining scalar multiplication
    for (int i = vectorCount * vectorSize; i < array1.length; i++) {
        multiplication[i] = array1[i] * array2[i];
    }
    return multiplication;
}
adelnoureddine commented 6 months ago

Could you provide me with a minimal working example (a jar for instance), I can test on my machine?

We had issues in some cases where the monitoring loop for JoularJX ends prematurely, and therefore no energy data are recorded. It's mostly in some application servers as JoularJX tries to destroy the VM on shutdown. The tentative fix (in issue #42) ended up with side effects on regular Java applications where the loop never ends. You could try to apply that change (commit 1dd0a64) and see if that fix your issue.

ankitkumarsindhu commented 6 months ago

Hi! Below is the working example:

import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.OutputTimeUnit;

import jdk.incubator.vector.IntVector; import jdk.incubator.vector.VectorSpecies;

/**

adelnoureddine commented 5 months ago

Could you try the proposed fix in issue #66, in this comment.