Commit 99b95be3 authored by Noric Couderc's avatar Noric Couderc
Browse files

Optimizations to papi-java

Christoph implemented some optimizations to avoid stopping counters when
it's not needed

I updated the client code to use the new API.
parent a5bf5a0d
...@@ -66,7 +66,9 @@ public class CollectionTimer { ...@@ -66,7 +66,9 @@ public class CollectionTimer {
} }
public long getCycles(OperationType operationType) { public long getCycles(OperationType operationType) {
return getEventSet(operationType).getCounters()[0]; long[] readings = new long[getEventSet(operationType).size()];
getEventSet(operationType).read(readings);
return readings[0];
} }
public long getTotalTime() { return mainStopWatch.getNanoTime(); } public long getTotalTime() { return mainStopWatch.getNanoTime(); }
...@@ -139,8 +141,7 @@ public class CollectionTimer { ...@@ -139,8 +141,7 @@ public class CollectionTimer {
if (isTopLevel()) { if (isTopLevel()) {
suspendStopWatch(operationType); suspendStopWatch(operationType);
EventSet ev = getEventSet(operationType); EventSet ev = getEventSet(operationType);
ev.stop(); cycles += ev.stop()[0];
cycles += ev.getCounters()[0];
} }
} }
} }
...@@ -47,9 +47,8 @@ open class PapiRunner() : PapiBenchmarkAnalyzer { ...@@ -47,9 +47,8 @@ open class PapiRunner() : PapiBenchmarkAnalyzer {
b[i] = acc b[i] = acc
} }
} }
evset.stop()
// Get data // Get data
val currentData = evset.counters val currentData = evset.stop()
current.addAll(currentData.toList()) current.addAll(currentData.toList())
} }
data.set(counter, current) data.set(counter, current)
...@@ -84,14 +83,14 @@ open class PapiRunner() : PapiBenchmarkAnalyzer { ...@@ -84,14 +83,14 @@ open class PapiRunner() : PapiBenchmarkAnalyzer {
var accumulator = 0 var accumulator = 0
evset.start() evset.start()
app.runBenchmark(blackhole) app.runBenchmark(blackhole)
evset.stop() val readings = evset.stop()
val resultDataStructure = app.getDatastructure() val resultDataStructure = app.getDatastructure()
// Write the result somewhere to prevent dead code elimination // Write the result somewhere to prevent dead code elimination
writer.write(accumulator) writer.write(accumulator)
writer.write(resultDataStructure.toString()) writer.write(resultDataStructure.toString())
// We record the data // We record the data
val runSamples = spec.counters().zip(evset.counters.toList()).map { val runSamples = spec.counters().zip(readings.toList()).map {
PapiBenchmarkAnalyzer.BenchmarkRunSample(it.first, it.second.toDouble()) PapiBenchmarkAnalyzer.BenchmarkRunSample(it.first, it.second.toDouble())
} }
val runData = PapiBenchmarkAnalyzer.BenchmarkRunData( val runData = PapiBenchmarkAnalyzer.BenchmarkRunData(
......
...@@ -48,15 +48,19 @@ open class PapiTracerRunner() : PapiRunner() { ...@@ -48,15 +48,19 @@ open class PapiTracerRunner() : PapiRunner() {
fun makeRecords(text : String): List<TraceRecord> { fun makeRecords(text : String): List<TraceRecord> {
val cleanedLines = text.lines().filter { !it.isEmpty() } val header = text.lines().first()
val columnIndex = header.trim().split("\t").mapIndexed { index, column -> Pair(column, index) }
.toMap()
val cleanedLines = text.lines().drop(1).filter { !it.isEmpty() }
return cleanedLines.map { line -> return cleanedLines.map { line ->
val splitted = line.split("\t") val splitted = line.split("\t")
TraceRecord(splitted[0].intern(), TraceRecord(splitted[columnIndex["location"]!!].intern(),
splitted[1].intern(), splitted[columnIndex["feature"]!!].intern(),
Integer.parseInt(splitted[2]), Integer.parseInt(splitted[columnIndex["feature_value"]!!]),
splitted[3].intern(), splitted[columnIndex["collection"]!!].intern(),
splitted[4].intern() splitted[columnIndex["method"]!!].intern()
) )
} }
} }
...@@ -133,7 +137,7 @@ open class PapiTracerRunner() : PapiRunner() { ...@@ -133,7 +137,7 @@ open class PapiTracerRunner() : PapiRunner() {
// We get the output from the run // We get the output from the run
val stream = ByteArrayOutputStream() val stream = ByteArrayOutputStream()
Tracer.printRecords(PrintStream(stream)) Tracer.printRecords(1, PrintStream(stream))
return makeRecords(stream.toString()) return makeRecords(stream.toString())
} }
......
...@@ -316,8 +316,7 @@ public class SyntheticBenchmarkTest { ...@@ -316,8 +316,7 @@ public class SyntheticBenchmarkTest {
} }
// done with the code // done with the code
evset.stop(); long[] data = evset.stop();
long[] data = evset.getCounters();
// only print the 10th run // only print the 10th run
if (warmup == 0) { if (warmup == 0) {
......
...@@ -51,7 +51,7 @@ class TracingCollectionRunnerTest { ...@@ -51,7 +51,7 @@ class TracingCollectionRunnerTest {
b.runBenchmark(blackhole) b.runBenchmark(blackhole)
val s = ByteArrayOutputStream() val s = ByteArrayOutputStream()
Tracer.printRecords(PrintStream(s)) Tracer.printRecords(1, PrintStream(s))
// We're gonna clean up the lines where we have 0 invocations // We're gonna clean up the lines where we have 0 invocations
val partitioned = s.toString().lines().partition { val partitioned = s.toString().lines().partition {
it.contains("invocations\t0") it.contains("invocations\t0")
......
No preview for this file type
No preview for this file type
Subproject commit 16c467d838f2fedcfaa1b51659b98f4c031ab025 Subproject commit 80d072309714821134720a126a46a8bd64ca88f0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment