Commit 76121cc4 authored by Noric Couderc's avatar Noric Couderc
Browse files

Implemented using Experiment for printing features

Instead of using the SyntheticBenchmarkFeaturePrinter, we can now use
the new API for printing vectors of features. It uses Experiment to get
the features and aggregate them.
parent bf8a6ad2
package se.lth.cs
import se.lth.cs.bcgen.BCBenchmarkPackage
import se.lth.cs.papicounters.PapiTracerRunner
import se.lth.cs.util.Experiment
import se.lth.cs.util.FeatureSet
import java.io.Writer
class SyntheticBenchmarkExperimentPrinter (out : Writer,
methodPrintFormat : String,
val numberRuns : Int,
val features : FeatureSet,
val papiRunner: PapiTracerRunner):
SyntheticBenchmarkDataPrinter(out, methodPrintFormat) {
override fun printBenchmarkRows(syntheticBenchmark: BCBenchmarkPackage<*>) {
val exp = Experiment(numberRuns, syntheticBenchmark, features, papiRunner)
val results = exp.run()
results.forEach {
it.values.entries.forEach { entry ->
printer.printRecord(
it.benchmark.benchmarkIdentifier,
it.iterationNumber,
entry.key.toCSVFeature(),
entry.key.toCSVFeatureType(),
entry.value)
}
}
}
/**
* Prints the header for benchmark features
* (They are printed in long form)
*/
override fun printHeader() {
printer.printRecord("benchmark_id", "iteration", "feature", "feature_type", "value")
}
}
\ No newline at end of file
......@@ -8,9 +8,10 @@ import com.github.ajalt.clikt.parameters.types.choice
import com.github.ajalt.clikt.parameters.types.int
import se.lth.cs.*
import se.lth.cs.bcgen.BCBenchmarkPackage
import se.lth.cs.papicounters.MockupPapiTracerRunner
import se.lth.cs.papicounters.PAPICounter
import se.lth.cs.papicounters.PapiTracerRunner
import se.lth.cs.timing.StopWatchRunner
import se.lth.cs.util.brainyFeatures
import java.io.File
import java.io.FileReader
import java.io.FileWriter
......@@ -81,17 +82,18 @@ class PapiCommandLine : CliktCommand() {
"SOFTWARE-COUNTERS" -> SyntheticBenchmarkHistPrinter(writer, methodOutputFormat)
"FEATURE-VECTORS" -> {
val runner = if (debugMode) {
MockupPapiRunner(numberRuns,
listOf(PAPICounter("PAPI_TOT_CYC"),
PAPICounter("PAPI_TOT_INS")
))
MockupPapiTracerRunner()
} else {
val spec = CounterSpecification.fromFile(countersFile)
val counters = spec.currentSpec.keys.map { PAPICounter(it) }
PapiTracerRunner(numberRuns, counters)}
SyntheticBenchmarkFeaturePrinter(writer, runner,
methodOutputFormat, normalizeFeatures)
PapiTracerRunner()
}
val spec = CounterSpecification.fromFile(countersFile)
val features = brainyFeatures()
val counters = spec.currentSpec.keys.map { PAPICounter(it) }
SyntheticBenchmarkExperimentPrinter(writer,
methodOutputFormat,
numberRuns, features,
runner)
}
"SUGGESTIONS" -> { // This is different...
// TODO: The options "-it JMH" and "-ot SUGGESTIONS" won't work together.
......
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import se.lth.cs.SyntheticBenchmarkExperimentPrinter
import se.lth.cs.bcgen.BCBenchmarkPackage
import se.lth.cs.matchFunction
import se.lth.cs.methodNameTable2
import se.lth.cs.papicounters.MockupPapiTracerRunner
import se.lth.cs.papicounters.PAPICounter
import se.lth.cs.papicounters.PapiTracerRunner
import se.lth.cs.printFunction
import se.lth.cs.timing.OperationType
import se.lth.cs.util.CostFeature
import se.lth.cs.util.FeatureSet
import se.lth.cs.util.MethodInvocations
import java.io.StringWriter
class SyntheticBenchmarkExperimentPrinterTest {
@Test
fun testNoBenchmarks() {
val writer = StringWriter()
val features = FeatureSet(
listOf(
PAPICounter("PAPI_TOT_CYC"),
MethodInvocations("java.util.List.add", "JAVA-STANDARD-FORMAT")
)
)
val printer = SyntheticBenchmarkExperimentPrinter(writer,
"",
10,
features,
MockupPapiTracerRunner())
printer.printToCSV(listOf())
Assertions.assertEquals("benchmark_id,iteration,feature,feature_type,value\n",
writer.toString())
}
@Test
fun testListBenchmarks() {
val writer = StringWriter()
val features = FeatureSet(
listOf(
PAPICounter("PAPI_TOT_CYC"),
CostFeature(OperationType.INSERT),
MethodInvocations("runAdd", "JAVA-STANDARD-FORMAT")
)
)
val printer = SyntheticBenchmarkExperimentPrinter(writer,
"",
10,
features, MockupPapiTracerRunner())
val benchmarks = listOf(
BCBenchmarkPackage.LIST(1234L, 100, 0, ArrayList<Integer>())
)
printer.printToCSV(benchmarks)
val expected = """
benchmark_id,iteration,feature,feature_type,value
Synth:POLYA:1234:100:List:0:ArrayList,0,PAPI_TOT_CYC,hardware,100000.0
Synth:POLYA:1234:100:List:0:ArrayList,0,cyclesInsertions,hardware,21000.0
Synth:POLYA:1234:100:List:0:ArrayList,0,add(java.lang.Object),software,4.0
Synth:POLYA:1234:100:List:0:ArrayList,1,PAPI_TOT_CYC,hardware,100000.0
Synth:POLYA:1234:100:List:0:ArrayList,1,cyclesInsertions,hardware,21000.0
Synth:POLYA:1234:100:List:0:ArrayList,1,add(java.lang.Object),software,4.0
Synth:POLYA:1234:100:List:0:ArrayList,2,PAPI_TOT_CYC,hardware,100000.0
Synth:POLYA:1234:100:List:0:ArrayList,2,cyclesInsertions,hardware,21000.0
Synth:POLYA:1234:100:List:0:ArrayList,2,add(java.lang.Object),software,4.0
Synth:POLYA:1234:100:List:0:ArrayList,3,PAPI_TOT_CYC,hardware,100000.0
Synth:POLYA:1234:100:List:0:ArrayList,3,cyclesInsertions,hardware,21000.0
Synth:POLYA:1234:100:List:0:ArrayList,3,add(java.lang.Object),software,4.0
Synth:POLYA:1234:100:List:0:ArrayList,4,PAPI_TOT_CYC,hardware,100000.0
Synth:POLYA:1234:100:List:0:ArrayList,4,cyclesInsertions,hardware,21000.0
Synth:POLYA:1234:100:List:0:ArrayList,4,add(java.lang.Object),software,4.0
Synth:POLYA:1234:100:List:0:ArrayList,5,PAPI_TOT_CYC,hardware,100000.0
Synth:POLYA:1234:100:List:0:ArrayList,5,cyclesInsertions,hardware,21000.0
Synth:POLYA:1234:100:List:0:ArrayList,5,add(java.lang.Object),software,4.0
Synth:POLYA:1234:100:List:0:ArrayList,6,PAPI_TOT_CYC,hardware,100000.0
Synth:POLYA:1234:100:List:0:ArrayList,6,cyclesInsertions,hardware,21000.0
Synth:POLYA:1234:100:List:0:ArrayList,6,add(java.lang.Object),software,4.0
Synth:POLYA:1234:100:List:0:ArrayList,7,PAPI_TOT_CYC,hardware,100000.0
Synth:POLYA:1234:100:List:0:ArrayList,7,cyclesInsertions,hardware,21000.0
Synth:POLYA:1234:100:List:0:ArrayList,7,add(java.lang.Object),software,4.0
Synth:POLYA:1234:100:List:0:ArrayList,8,PAPI_TOT_CYC,hardware,100000.0
Synth:POLYA:1234:100:List:0:ArrayList,8,cyclesInsertions,hardware,21000.0
Synth:POLYA:1234:100:List:0:ArrayList,8,add(java.lang.Object),software,4.0
Synth:POLYA:1234:100:List:0:ArrayList,9,PAPI_TOT_CYC,hardware,100000.0
Synth:POLYA:1234:100:List:0:ArrayList,9,cyclesInsertions,hardware,21000.0
Synth:POLYA:1234:100:List:0:ArrayList,9,add(java.lang.Object),software,4.0
""".trimIndent()
Assertions.assertEquals(expected, writer.toString())
}
}
\ 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