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

Fix: Fixed errors in tests for PapiTracerRunner

Some tests failed because the way we handle counters wasn't correct.
parent 6b6c07c7
...@@ -74,6 +74,8 @@ open class PapiTracerRunner() : PapiRunner() { ...@@ -74,6 +74,8 @@ open class PapiTracerRunner() : PapiRunner() {
*/ */
private fun analyzeOutput(records : List<TraceRecord>): ValueGraph<String, Int> { private fun analyzeOutput(records : List<TraceRecord>): ValueGraph<String, Int> {
// We can analyze the output to get what we want. // We can analyze the output to get what we want.
assert(!records.isEmpty())
val g: MutableValueGraph<String, Int> = ValueGraphBuilder.directed().build() val g: MutableValueGraph<String, Int> = ValueGraphBuilder.directed().build()
for (r in records) { for (r in records) {
...@@ -137,7 +139,8 @@ open class PapiTracerRunner() : PapiRunner() { ...@@ -137,7 +139,8 @@ 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(1, PrintStream(stream)) Tracer.printRecords(0, PrintStream(stream))
return makeRecords(stream.toString()) return makeRecords(stream.toString())
} }
...@@ -181,6 +184,7 @@ open class PapiTracerRunner() : PapiRunner() { ...@@ -181,6 +184,7 @@ open class PapiTracerRunner() : PapiRunner() {
fun getCyclesPerOpType(iteration : List<TraceRecord>): Map<OperationType, Double> { fun getCyclesPerOpType(iteration : List<TraceRecord>): Map<OperationType, Double> {
// There should be only one allocation site for all records // There should be only one allocation site for all records
// Because we only record one iteration of one benchmark. // Because we only record one iteration of one benchmark.
assert(!iteration.isEmpty())
assert(iteration.map { it.allocationSite }.toSet().size == 1) assert(iteration.map { it.allocationSite }.toSet().size == 1)
val result = OperationType.values().associate { val result = OperationType.values().associate {
...@@ -229,6 +233,8 @@ class MockupPapiTracerRunner() : PapiTracerRunner() { ...@@ -229,6 +233,8 @@ class MockupPapiTracerRunner() : PapiTracerRunner() {
val collection = createTracerCollection(syntheticBenchmark) val collection = createTracerCollection(syntheticBenchmark)
syntheticBenchmark.datastructure = collection syntheticBenchmark.datastructure = collection
Tracer.stopAll()
return syntheticBenchmark.trace.flatMap { method -> return syntheticBenchmark.trace.flatMap { method ->
val methodOtherFormat = methodNameTable2.inverseBidiMap()[method] val methodOtherFormat = methodNameTable2.inverseBidiMap()[method]
counters.map { counter -> counters.map { counter ->
......
...@@ -7,7 +7,7 @@ import org.junit.jupiter.params.provider.ValueSource ...@@ -7,7 +7,7 @@ import org.junit.jupiter.params.provider.ValueSource
import org.openjdk.jmh.infra.Blackhole import org.openjdk.jmh.infra.Blackhole
import papi.Constants import papi.Constants
import papi.EventSet import papi.EventSet
import se.lth.cs.average import papi.Papi
import se.lth.cs.bcgen.BCBenchmarkPackage import se.lth.cs.bcgen.BCBenchmarkPackage
import se.lth.cs.papicounters.PAPICounter import se.lth.cs.papicounters.PAPICounter
import se.lth.cs.papicounters.PapiBenchmarkAnalyzer import se.lth.cs.papicounters.PapiBenchmarkAnalyzer
...@@ -15,17 +15,19 @@ import se.lth.cs.papicounters.PapiTracerRunner ...@@ -15,17 +15,19 @@ import se.lth.cs.papicounters.PapiTracerRunner
import se.lth.cs.smartmodules.tracer.Tracer import se.lth.cs.smartmodules.tracer.Tracer
import se.lth.cs.timing.OperationType import se.lth.cs.timing.OperationType
import se.lth.cs.util.FeatureSet import se.lth.cs.util.FeatureSet
import se.lth.cs.variance
import se.lth.util.ArrayListTracer import se.lth.util.ArrayListTracer
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.File import java.io.File
import java.io.PrintStream import java.io.PrintStream
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.collections.HashSet
import kotlin.system.measureTimeMillis import kotlin.system.measureTimeMillis
class TracingCollectionRunnerTest { class TracingCollectionRunnerTest {
// In this file, we will test running benchmarks with tracing collections // In this file, we will test running benchmarks with tracing collections
// We create a benchmark, run it with tracing collections, and obtain the counters afterwards // We create a benchmark, run it with tracing collections, and obtain the counters afterwards
companion object { companion object {
val blackhole = Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous.") val blackhole = Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous.")
...@@ -34,11 +36,15 @@ class TracingCollectionRunnerTest { ...@@ -34,11 +36,15 @@ class TracingCollectionRunnerTest {
@BeforeAll() @BeforeAll()
@JvmStatic @JvmStatic
fun initTracer() { fun initTracer() {
System.out.println("Initialize PAPI") // EventSet.logCalls = false
Tracer.JPAPI = true }
Tracer.addCounter(Constants.PAPI_TOT_CYC)
Tracer.addCounter(Constants.PAPI_TOT_INS)
} }
@BeforeEach
fun setup() {
val papiAvailableCounters = File("../papi_avail")
Assertions.assertTrue(papiAvailableCounters.exists())
runner = PapiTracerRunner()
} }
@Test @Test
...@@ -120,12 +126,7 @@ class TracingCollectionRunnerTest { ...@@ -120,12 +126,7 @@ class TracingCollectionRunnerTest {
// What we need: A drop-in replacement for PapiRunner, which uses these collections instead. // What we need: A drop-in replacement for PapiRunner, which uses these collections instead.
@BeforeEach
fun setup() {
val papiAvailableCounters = File("../papi_avail")
Assertions.assertTrue(papiAvailableCounters.exists())
runner = PapiTracerRunner()
}
@Test @Test
fun testRunner() { fun testRunner() {
...@@ -209,6 +210,7 @@ class TracingCollectionRunnerTest { ...@@ -209,6 +210,7 @@ class TracingCollectionRunnerTest {
val results = runner!!.runApplications(10, FeatureSet(), listOf(bench)) val results = runner!!.runApplications(10, FeatureSet(), listOf(bench))
// We reset numberRuns for each iteration, so the benchmarks is run "once".
for (r in results) { for (r in results) {
Assertions.assertEquals(1, r.benchmark.numberRuns) Assertions.assertEquals(1, r.benchmark.numberRuns)
} }
......
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