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

Refactoring: Automatically build eventSet

No need to manually call "accept" on the features, that's kinda ugly
parent b8261e9f
package se.lth.cs.papicounters
import papi.EventSet
import papi.Papi
import se.lth.cs.util.*
import java.lang.RuntimeException
/**
* Creates an eventSet from a FeatureSet
*/
class EventSetBuilder : FeatureVisitor {
class EventSetBuilder(val features : FeatureSet) : FeatureVisitor {
private var counterSet : LinkedHashSet<PAPICounter> = java.util.LinkedHashSet()
init {
features.accept(this)
}
override fun visitPAPICounter(c: PAPICounter) {
// If the counter is de-activated we skip it
if (!c.isSupported()) {
......
......@@ -11,10 +11,10 @@ interface PapiBenchmarkAnalyzer {
val features : FeatureSet,
val syntheticBenchmark: BCBenchmarkPackage<*>) {
val eventSetBuilder = EventSetBuilder(features)
fun eventSet(): EventSet {
val eb = EventSetBuilder()
features.accept(eb)
return eb.getEventSet()
return eventSetBuilder.getEventSet()
}
/**
......@@ -26,9 +26,7 @@ interface PapiBenchmarkAnalyzer {
}
fun counters() : List<PAPICounter> {
val eb = EventSetBuilder()
features.accept(eb)
return eb.getCounterSet().toList()
return eventSetBuilder.getCounterSet().toList()
}
}
......
......@@ -27,8 +27,7 @@ open class PapiRunner() : PapiBenchmarkAnalyzer {
// For each counter,
// we store the values for each run (10 runs)
var data: MutableMap<PAPICounter, List<Long>> = mutableMapOf()
val eb = EventSetBuilder()
counters.accept(eb)
val eb = EventSetBuilder(counters)
for (counter in eb.getCounterSet()) {
val evset = eb.getEventSet()
......
......@@ -37,8 +37,7 @@ class EventSetBuilderTest {
val spec = FeatureSet(*counters.toTypedArray())
val builder = EventSetBuilder()
spec.accept(builder)
val builder = EventSetBuilder(spec)
Assertions.assertEquals(counters.toSet(), builder.getCounterSet())
}
......@@ -52,8 +51,7 @@ class EventSetBuilderTest {
val spec = FeatureSet(*features)
val builder = EventSetBuilder()
spec.accept(builder)
val builder = EventSetBuilder(spec)
val expected = setOf(
PAPICounter("PAPI_TOT_CYC"), // For Costs!
......@@ -80,8 +78,7 @@ class EventSetBuilderTest {
val spec = FeatureSet(*features)
val builder = EventSetBuilder()
spec.accept(builder)
val builder = EventSetBuilder(spec)
val expected = listOf(
PAPICounter("PAPI_L2_DCM"),
......@@ -95,14 +92,9 @@ class EventSetBuilderTest {
// @Disabled("PAPI_L1_DCA is not available on the machine")
@Test
fun testEventBuildInvalidEvents() {
val features = listOf(
PAPICounter("PAPI_L1_DCM"),
PAPICounter("PAPI_L1_DCA")).toTypedArray()
val spec = FeatureSet(*features)
val spec = FeatureSet()
// Oh no! empty list of PAPI events!
val builder = EventSetBuilder()
val builder = EventSetBuilder(spec)
Assertions.assertThrows(RuntimeException::class.java) { spec.accept(builder) }
}
}
\ No newline at end of file
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