Commit dac2d70c authored by Noric Couderc's avatar Noric Couderc
Browse files

Implemented runSpec for PapiTracerRunner

Works similarly to how runSpec runs for a regular PapiRunner.

Updated smrt.jar because there are some methods we needed to reset the
tracer and set it's counters dynamically.
parent 31019c1c
......@@ -8,7 +8,7 @@ import se.lth.cs.bcgen.BCBenchmarkPackage
import se.lth.cs.papicounters.PapiBenchmarkAnalyzer
import java.io.FileWriter
open class PapiRunner(private val numRuns: Int, counters: CounterSpecification) : PapiBenchmarkAnalyzer {
open class PapiRunner(val numRuns: Int, counters: CounterSpecification) : PapiBenchmarkAnalyzer {
init {
Papi.init()
......
package se.lth.cs.papicounters
import com.google.common.graph.GraphBuilder
import com.google.common.graph.MutableGraph
import com.google.common.graph.MutableValueGraph
import com.google.common.graph.ValueGraph
import com.google.common.graph.ValueGraphBuilder
import se.lth.cs.CounterSpecification
import se.lth.cs.PapiRunner
import se.lth.cs.bcgen.BCBenchmarkPackage
import se.lth.cs.smartmodules.tracer.Tracer
import se.lth.util.ArrayListTracer
import se.lth.util.*
import java.io.ByteArrayOutputStream
import java.io.PrintStream
......@@ -19,12 +18,22 @@ import java.io.PrintStream
* instead of each run)
*/
class PapiTracerRunner(numRuns : Int, counters : CounterSpecification) : PapiRunner(numRuns, counters) {
private fun createTracerCollection(bench: BCBenchmarkPackage<*>): Any? {
val collectionName = bench.dataStructureName
val fakeLocation = bench.benchmarkIdentifier
// Sometimes we used a tracer collection, we want to replace it anyway.
val collectionName = bench.dataStructureSimpleName.removeSuffix("Tracer")
val fakeLocation = bench.benchmarkIdentifier.removeSuffix("Tracer")
return when (collectionName) {
"java.util.ArrayList" -> ArrayListTracer<Int>(fakeLocation)
"ArrayList" -> ArrayListTracer<Int>(fakeLocation)
"LinkedList" -> LinkedListTracer<Int>(fakeLocation)
"Vector" -> VectorTracer<Int>(fakeLocation)
"TreeSet" -> TreeSetTracer<Int>(fakeLocation)
"HashSet" -> HashSetTracer<Int>(fakeLocation)
"LinkedHashSet" -> LinkedHashSetTracer<Int>(fakeLocation)
"TreeMap" -> TreeMapTracer<Int, Int>(fakeLocation)
"HashMap" -> HashMapTracer<Int, Int>(fakeLocation)
"LinkedHashMap" -> LinkedHashMapTracer<Int, Int>(fakeLocation)
else -> null
}
}
......@@ -39,22 +48,8 @@ class PapiTracerRunner(numRuns : Int, counters : CounterSpecification) : PapiRun
// We get the results, which are in Tracer
val stream = ByteArrayOutputStream()
Tracer.printRecords(PrintStream(stream))
val g: ValueGraph<String, Int> = analyzeOutput(stream)
// We can analyze the output to get what we want.
val g : MutableValueGraph<String, Int> = ValueGraphBuilder.directed().build()
for (line in stream.toString().lines()) {
if (line.isEmpty()) { continue }
val splitted = line.split("\t")
val source = splitted[0] // Allocation site / Benchmark ID.
val target = splitted[1] // Feature
val counterValue = Integer.parseInt(splitted[2])
val value = g.edgeValueOrDefault(source, target, 0)?.plus(counterValue) // Number
// There will be many edges from an alloc-site
// to a feature, one for each method call.
g.putEdgeValue(source, target, value)
}
val result = mutableListOf<Triple<BCBenchmarkPackage<*>, String, List<Long>>>()
......@@ -70,7 +65,60 @@ class PapiTracerRunner(numRuns : Int, counters : CounterSpecification) : PapiRun
return result
}
private fun analyzeOutput(stream: ByteArrayOutputStream): ValueGraph<String, Int> {
// We can analyze the output to get what we want.
val g: MutableValueGraph<String, Int> = ValueGraphBuilder.directed().build()
for (line in stream.toString().lines()) {
if (line.isEmpty()) {
continue
}
val splitted = line.split("\t")
val source = splitted[0] // Allocation site / Benchmark ID.
val feature = splitted[1]
val target = feature
val counterValue = Integer.parseInt(splitted[2])
val value = g.edgeValueOrDefault(source, target, 0)?.plus(counterValue) // Number
g.putEdgeValue(source, target, value)
}
return g
}
override fun runSpec(spec: PapiBenchmarkAnalyzer.RunSpec): List<Long> {
return listOf()
val result = mutableListOf<Long>()
val counter = counterSpec.getCounter(spec.counter)
Tracer.setCounters(counter!!.toInt())
for (i in 0 until spec.numRuns) {
Tracer.reset()
val collection = createTracerCollection(spec.syntheticBenchmark)
spec.syntheticBenchmark.datastructure = collection
val app = spec.syntheticBenchmark
app.reset()
Tracer.JPAPI = true
app.runBenchmark(blackhole)
// We get the output and analyze it
val stream = ByteArrayOutputStream()
Tracer.printRecords(PrintStream(stream))
val g: ValueGraph<String, Int> = analyzeOutput(stream)
// We lookup the benchmarks with an edge
// to that counter (there should be only one)
// We get the feature in number form '0x800...'
val featureNumber = String.format("0x%x", counterSpec.getCounter(spec.counter))
g.predecessors(featureNumber).forEach {
val value = g.edgeValue(it, featureNumber)
result.add(value.get().toLong())
}
}
return result
}
}
\ No newline at end of file
......@@ -5,9 +5,11 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.openjdk.jmh.infra.Blackhole
import papi.Constants
import papi.EventSet
import papi.Papi
import se.lth.cs.CounterSpecification.Companion.fromFile
import se.lth.cs.bcgen.BCBenchmarkPackage
import se.lth.cs.papicounters.PapiBenchmarkAnalyzer
import se.lth.cs.papicounters.PapiTracerRunner
import se.lth.cs.smartmodules.tracer.Tracer
import se.lth.util.ArrayListTracer
......@@ -127,8 +129,30 @@ class TracingCollectionRunnerTest {
val benches = listOf(
BCBenchmarkPackage.LIST(10, 10, 0, ArrayList<Int>())
)
val res = runner!!.runApplicationsMedian(benches)
val res = runner!!.runApplications(benches)
Assertions.assertFalse(res.isEmpty())
// We only tried one benchmark, but we should get several counters.
Assertions.assertEquals(1, res.size)
for (t in res) {
Assertions.assertEquals(runner!!.numRuns, t.third.size)
}
}
@Test
fun testRunSpec() {
val benches = listOf(
BCBenchmarkPackage.LIST(10, 10, 0, ArrayList<Int>())
)
val samples = runner!!.runSpec(PapiBenchmarkAnalyzer.RunSpec(10,
"PAPI_TOT_CYC",
EventSet.create(Constants.PAPI_TOT_CYC),
benches.get(0)))
Assertions.assertEquals(10, samples.size)
for (sample in samples) {
Assertions.assertTrue(sample > 80000)
Assertions.assertTrue(sample < 250000)
}
}
}
\ No newline at end of file
No preview for this file type
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