-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support individual measure recording, separate measure from met…
…adata
- Loading branch information
Showing
20 changed files
with
305 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 2 additions & 22 deletions
24
runtime/src/main/java/io/quarkiverse/power/runtime/SensorMeasure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,8 @@ | ||
package io.quarkiverse.power.runtime; | ||
|
||
import java.util.Optional; | ||
|
||
public interface SensorMeasure { | ||
String CPU = "cpu"; | ||
String GPU = "gpu"; | ||
String TOTAL = "total"; | ||
|
||
double cpu(); | ||
|
||
default Optional<Double> gpu() { | ||
return Optional.empty(); | ||
} | ||
|
||
default Optional<Double> byKey(String key) { | ||
return switch (key) { | ||
case CPU -> Optional.of(cpu()); | ||
case GPU -> gpu(); | ||
case TOTAL -> Optional.of(total()); | ||
default -> Optional.empty(); | ||
}; | ||
} | ||
double total(); | ||
|
||
default double total() { | ||
return cpu() + gpu().orElse(0.0); | ||
} | ||
SensorMetadata metadata(); | ||
} |
7 changes: 7 additions & 0 deletions
7
runtime/src/main/java/io/quarkiverse/power/runtime/SensorMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.quarkiverse.power.runtime; | ||
|
||
public interface SensorMetadata { | ||
int indexFor(String component); | ||
|
||
int componentCardinality(); | ||
} |
11 changes: 0 additions & 11 deletions
11
runtime/src/main/java/io/quarkiverse/power/runtime/sensors/IncrementableMeasure.java
This file was deleted.
Oops, something went wrong.
71 changes: 37 additions & 34 deletions
71
runtime/src/main/java/io/quarkiverse/power/runtime/sensors/OngoingPowerMeasure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,67 @@ | ||
package io.quarkiverse.power.runtime.sensors; | ||
|
||
import java.util.Optional; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import io.quarkiverse.power.runtime.PowerMeasure; | ||
import io.quarkiverse.power.runtime.SensorMetadata; | ||
|
||
public class OngoingPowerMeasure<M extends IncrementableMeasure> | ||
implements IncrementableMeasure, PowerMeasure<M> { | ||
private final M measure; | ||
public class OngoingPowerMeasure implements PowerMeasure { | ||
private final SensorMetadata sensorMetadata; | ||
private final long startedAt; | ||
private int samplesNb; | ||
private final List<double[]> measures = new ArrayList<>(); | ||
private double[] current; | ||
private double total; | ||
|
||
public OngoingPowerMeasure(M measure) { | ||
public OngoingPowerMeasure(SensorMetadata sensorMetadata) { | ||
startedAt = System.currentTimeMillis(); | ||
samplesNb = 0; | ||
this.measure = measure; | ||
this.sensorMetadata = sensorMetadata; | ||
} | ||
|
||
public void incrementSamples() { | ||
samplesNb++; | ||
public void startNewMeasure() { | ||
if (current != null) { | ||
throw new IllegalStateException("A new measure cannot be started while one is still ongoing"); | ||
} | ||
current = new double[sensorMetadata.componentCardinality()]; | ||
} | ||
|
||
@Override | ||
public double cpu() { | ||
return measure.cpu(); | ||
public void setComponent(int index, double value) { | ||
current[index] = value; | ||
} | ||
|
||
@Override | ||
public Optional<Double> gpu() { | ||
return measure.gpu(); | ||
public double[] stopMeasure() { | ||
final var recorded = new double[current.length]; | ||
System.arraycopy(current, 0, recorded, 0, current.length); | ||
measures.add(recorded); | ||
var currentMeasureTotal = 0.0; | ||
for (double value : recorded) { | ||
currentMeasureTotal += value; | ||
} | ||
total += currentMeasureTotal; | ||
current = null; | ||
return recorded; | ||
} | ||
|
||
@Override | ||
public Optional<Double> byKey(String key) { | ||
return measure.byKey(key); | ||
public List<double[]> measures() { | ||
return measures; | ||
} | ||
|
||
@Override | ||
public double total() { | ||
return measure.total(); | ||
} | ||
|
||
public int numberOfSamples() { | ||
return samplesNb; | ||
} | ||
|
||
public long duration() { | ||
return System.currentTimeMillis() - startedAt; | ||
return total; | ||
} | ||
|
||
@Override | ||
public void addCPU(double v) { | ||
measure.addCPU(v); | ||
public SensorMetadata metadata() { | ||
return sensorMetadata; | ||
} | ||
|
||
@Override | ||
public void addGPU(double v) { | ||
measure.addGPU(v); | ||
public int numberOfSamples() { | ||
return measures.size(); | ||
} | ||
|
||
public M sensorMeasure() { | ||
return measure; | ||
public long duration() { | ||
return System.currentTimeMillis() - startedAt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 19 additions & 25 deletions
44
runtime/src/main/java/io/quarkiverse/power/runtime/sensors/StoppedPowerMeasure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,47 @@ | ||
package io.quarkiverse.power.runtime.sensors; | ||
|
||
import java.util.Optional; | ||
import java.util.List; | ||
|
||
import io.quarkiverse.power.runtime.PowerMeasure; | ||
import io.quarkiverse.power.runtime.SensorMeasure; | ||
import io.quarkiverse.power.runtime.SensorMetadata; | ||
|
||
public class StoppedPowerMeasure<M extends SensorMeasure> implements SensorMeasure, PowerMeasure<M> { | ||
private final M measure; | ||
public class StoppedPowerMeasure implements PowerMeasure { | ||
private final SensorMetadata metadata; | ||
private final long duration; | ||
private final int samples; | ||
private final List<double[]> measures; | ||
private final double total; | ||
|
||
public StoppedPowerMeasure(PowerMeasure<M> powerMeasure) { | ||
this.measure = powerMeasure.sensorMeasure(); | ||
public StoppedPowerMeasure(PowerMeasure powerMeasure) { | ||
this.metadata = powerMeasure.metadata(); | ||
this.duration = powerMeasure.duration(); | ||
this.samples = powerMeasure.numberOfSamples(); | ||
this.measures = powerMeasure.measures(); | ||
this.total = powerMeasure.total(); | ||
} | ||
|
||
@Override | ||
public double cpu() { | ||
return measure.cpu(); | ||
public int numberOfSamples() { | ||
return samples; | ||
} | ||
|
||
@Override | ||
public Optional<Double> gpu() { | ||
return measure.gpu(); | ||
public long duration() { | ||
return duration; | ||
} | ||
|
||
@Override | ||
public Optional<Double> byKey(String key) { | ||
return measure.byKey(key); | ||
public List<double[]> measures() { | ||
return measures; | ||
} | ||
|
||
@Override | ||
public double total() { | ||
return measure.total(); | ||
} | ||
|
||
@Override | ||
public int numberOfSamples() { | ||
return samples; | ||
} | ||
|
||
@Override | ||
public long duration() { | ||
return duration; | ||
return total; | ||
} | ||
|
||
@Override | ||
public M sensorMeasure() { | ||
return measure; | ||
public SensorMetadata metadata() { | ||
return metadata; | ||
} | ||
} |
Oops, something went wrong.