Skip to content

Commit

Permalink
Pass measurement unit via JSON to HTML report
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Sep 18, 2020
1 parent 4e8c0e1 commit e3c729b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private <T extends BuildInvocationResult> JsonObject serializeScenarioResult(Bui
private JsonObject serializeSample(BuildScenarioResult<? extends BuildInvocationResult> scenarioResult, Sample<?> sample) {
JsonObject json = new JsonObject();
json.addProperty("name", sample.getName());
json.addProperty("unit", sample.getUnit());
return json;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/gradle/profiler/result/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public interface Sample<T extends BuildInvocationResult> {
String getName();

String getUnit();

double extractFrom(T result);
}
5 changes: 5 additions & 0 deletions src/main/java/org/gradle/profiler/result/TimeSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

public abstract class TimeSample<T extends BuildInvocationResult> implements Sample<T> {

@Override
public String getUnit() {
return "ms";
}

@Override
public double extractFrom(T result) {
return getDuration(result).toNanos() / 1000000d;
Expand Down
1 change: 0 additions & 1 deletion src/main/js/org/gradle/profiler/report/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ new Vue({
sample.color = `hsl(${scenarioIndex * 360 / scenarios.length}, ${100 - 80 * sampleIndex / samples.length}%, ${30 + 40 * sampleIndex / samples.length}%)`;
sample.thickness = sampleIndex === 0 ? 3 : 2;
sample.selected = sampleIndex === 0;
sample.unit = "ms";
const data = measuredIterations(scenario).map(iteration => iteration.values[sample.name]);
OPERATIONS.forEach(operation => sample[operation.name] = operation.apply(data));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ class JsonResultWriterTest extends Specification {
},
"samples": [
{
"name": "execution"
"name": "execution",
"unit": "ms"
},
{
"name": "Test sample"
"name": "Test sample",
"unit": "ms"
}
],
"iterations": [
Expand Down Expand Up @@ -236,10 +238,12 @@ class JsonResultWriterTest extends Specification {
},
"samples": [
{
"name": "execution"
"name": "execution",
"unit": "ms"
},
{
"name": "Test sample"
"name": "Test sample",
"unit": "ms"
}
],
"iterations": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"samples": [
{
"name": "execution",
"confidence": 0.0
"unit": "ms"
}
],
"iterations": [
Expand Down Expand Up @@ -289,7 +289,7 @@
"samples": [
{
"name": "execution",
"confidence": 0.9991642831782728
"unit": "ms"
}
],
"iterations": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"samples": [
{
"name": "execution",
"confidence": 0.0
"unit": "ms"
}
],
"iterations": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,39 @@
"samples": [
{
"name": "execution",
"confidence": 0.0
"unit": "ms"
},
{
"name": "ResolveConfigurationDependenciesBuildOperationType",
"confidence": 0.0
"unit": "ms"
},
{
"name": "DefaultTransformer$FingerprintTransformInputsOperation",
"confidence": 0.0
"unit": "ms"
},
{
"name": "CaptureStateBeforeExecutionStep$Operation",
"confidence": 0.0
"unit": "ms"
},
{
"name": "BuildCacheArchivePackBuildOperationType",
"confidence": 0.0
"unit": "ms"
},
{
"name": "BuildCacheArchiveUnpackBuildOperationType",
"confidence": 0.0
"unit": "ms"
},
{
"name": "SnapshotOutputsStep$Operation",
"confidence": 0.0
"unit": "ms"
},
{
"name": "ExecuteTaskActionBuildOperationType",
"confidence": 0.0
"unit": "ms"
},
{
"name": "ExecuteTaskBuildOperationType",
"confidence": 0.0
"unit": "ms"
}
],
"iterations": [
Expand Down Expand Up @@ -497,39 +497,39 @@
"samples": [
{
"name": "execution",
"confidence": 0.9991642831782728
"unit": "ms"
},
{
"name": "ResolveConfigurationDependenciesBuildOperationType",
"confidence": 0.7023232455278197
"unit": "ms"
},
{
"name": "DefaultTransformer$FingerprintTransformInputsOperation",
"confidence": 0.13956902626472267
"unit": "ms"
},
{
"name": "CaptureStateBeforeExecutionStep$Operation",
"confidence": 0.9999999011729629
"unit": "ms"
},
{
"name": "BuildCacheArchivePackBuildOperationType",
"confidence": 0.0
"unit": "ms"
},
{
"name": "BuildCacheArchiveUnpackBuildOperationType",
"confidence": 0.0
"unit": "ms"
},
{
"name": "SnapshotOutputsStep$Operation",
"confidence": 0.10758613603151901
"unit": "ms"
},
{
"name": "ExecuteTaskActionBuildOperationType",
"confidence": 0.18185053861180012
"unit": "ms"
},
{
"name": "ExecuteTaskBuildOperationType",
"confidence": 0.9999987143919465
"unit": "ms"
}
],
"iterations": [
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/org/gradle/profiler/report/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"samples": [
{
"name": "execution",
"confidence": 0.0
"unit": "ms"
}
],
"iterations": [
Expand Down Expand Up @@ -289,7 +289,7 @@
"samples": [
{
"name": "execution",
"confidence": 0.9991642831782728
"unit": "ms"
}
],
"iterations": [
Expand Down

0 comments on commit e3c729b

Please sign in to comment.