Skip to content

Commit 386a0e1

Browse files
authored
Add elapsed and start time to json summary output (#394)
Closes #393
1 parent c2170a7 commit 386a0e1

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

src/main/java/com/oltpbenchmark/Results.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
public final class Results {
3030

31+
private final long startTimestampMs;
3132
private final long nanoseconds;
3233
private final int measuredRequests;
3334
private final DistributionStatistics distributionStatistics;
@@ -40,8 +41,9 @@ public final class Results {
4041
private final Histogram<TransactionType> retryDifferent = new Histogram<>(false);
4142
private final Map<TransactionType, Histogram<String>> abortMessages = new HashMap<>();
4243

43-
public Results(long nanoseconds, int measuredRequests, DistributionStatistics distributionStatistics, final List<LatencyRecord.Sample> latencySamples) {
44-
this.nanoseconds = nanoseconds;
44+
public Results(long startTimestampMs, long elapsedNanoseconds, int measuredRequests, DistributionStatistics distributionStatistics, final List<LatencyRecord.Sample> latencySamples) {
45+
this.startTimestampMs = startTimestampMs;
46+
this.nanoseconds = elapsedNanoseconds;
4547
this.measuredRequests = measuredRequests;
4648
this.distributionStatistics = distributionStatistics;
4749

@@ -98,6 +100,10 @@ public List<Sample> getLatencySamples() {
98100
return latencySamples;
99101
}
100102

103+
public long getStartTimestampMs() {
104+
return startTimestampMs;
105+
}
106+
101107
public long getNanoseconds() {
102108
return nanoseconds;
103109
}

src/main/java/com/oltpbenchmark/ThreadBench.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ private Results runRateLimitedMultiPhase() {
113113

114114
// long measureStart = start;
115115

116+
long start_ts = System.currentTimeMillis();
116117
long start = System.nanoTime();
117118
long warmupStart = System.nanoTime();
118119
long warmup = warmupStart;
@@ -314,7 +315,7 @@ private Results runRateLimitedMultiPhase() {
314315
}
315316
DistributionStatistics stats = DistributionStatistics.computeStatistics(latencies);
316317

317-
Results results = new Results(measureEnd - start, requests, stats, samples);
318+
Results results = new Results(start_ts, measureEnd - start, requests, stats, samples);
318319

319320
// Compute transaction histogram
320321
Set<TransactionType> txnTypes = new HashSet<>();

src/main/java/com/oltpbenchmark/util/JSONUtil.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,27 @@ public static Field[] getSerializableFields(Class<?> clazz, String... fieldsToEx
8282
*/
8383
public static String format(String json) {
8484
try {
85-
return (JSONUtil.format(new JSONObject(json)));
85+
return (JSONUtil.format(new JSONObject(json){
86+
/**
87+
* changes the value of JSONObject.map to a LinkedHashMap in order to maintain
88+
* order of keys.
89+
* See Also: https://stackoverflow.com/a/62476486
90+
*/
91+
@Override
92+
public JSONObject put(String key, Object value) throws JSONException {
93+
try {
94+
Field map = JSONObject.class.getDeclaredField("map");
95+
map.setAccessible(true);
96+
Object mapValue = map.get(this);
97+
if (!(mapValue instanceof LinkedHashMap)) {
98+
map.set(this, new LinkedHashMap<>());
99+
}
100+
} catch (NoSuchFieldException | IllegalAccessException e) {
101+
throw new RuntimeException(e);
102+
}
103+
return super.put(key, value);
104+
}
105+
}));
86106
} catch (RuntimeException ex) {
87107
throw ex;
88108
} catch (Exception ex) {

src/main/java/com/oltpbenchmark/util/ResultWriter.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,22 @@ public void writeConfig(PrintStream os) throws ConfigurationException {
9999
}
100100

101101
public void writeSummary(PrintStream os) {
102-
Map<String, Object> summaryMap = new TreeMap<>();
102+
Map<String, Object> summaryMap = new LinkedHashMap<>();
103103
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
104104
Date now = new Date();
105+
summaryMap.put("Start timestamp (milliseconds)", results.getStartTimestampMs());
105106
summaryMap.put("Current Timestamp (milliseconds)", now.getTime());
107+
summaryMap.put("Elapsed Time (nanoseconds)", results.getNanoseconds());
106108
summaryMap.put("DBMS Type", dbType);
107109
summaryMap.put("DBMS Version", collector.collectVersion());
108110
summaryMap.put("Benchmark Type", benchType);
109-
summaryMap.put("Latency Distribution", results.getDistributionStatistics().toMap());
110-
summaryMap.put("Throughput (requests/second)", results.requestsPerSecondThroughput());
111-
summaryMap.put("Goodput (requests/second)", results.requestsPerSecondGoodput());
111+
summaryMap.put("Measured Requests", results.getMeasuredRequests());
112112
for (String field : BENCHMARK_KEY_FIELD) {
113113
summaryMap.put(field, expConf.getString(field));
114114
}
115+
summaryMap.put("Latency Distribution", results.getDistributionStatistics().toMap());
116+
summaryMap.put("Throughput (requests/second)", results.requestsPerSecondThroughput());
117+
summaryMap.put("Goodput (requests/second)", results.requestsPerSecondGoodput());
115118
os.println(JSONUtil.format(JSONUtil.toJSONString(summaryMap)));
116119
}
117120

0 commit comments

Comments
 (0)