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

Implemented parsing a column about method selection strategy in JMH benchmarks

The column "Param: MethodSelectionStrategy" is parsed and a proper JMH record is created.
parent 812d6f4c
......@@ -4,17 +4,29 @@ import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVParser
import org.apache.commons.csv.CSVPrinter
import org.apache.commons.csv.CSVRecord
import java.io.*
import java.lang.Exception
import se.lth.cs.bcgen.*
import se.lth.cs.bcgen.BCBenchmarkPackage
import java.io.File
import java.io.FileReader
import java.io.Reader
import java.io.Writer
/**
* A Class for processing JMH benchmark data
*/
class JMHProcessor {
fun process(file: File): List<JMHRecord> {
return process(FileReader(file))
}
data class JMHRecord(val seed : Int, val size : Int, val baseStructureSize : Int, val collection : String, val datastructure : String, val best : String) {
data class JMHRecord(val seed : Int,
val size : Int,
val baseStructureSize : Int,
val collection : String,
val datastructure : String,
val best : String,
val methodSelection : String? = null) {
fun toList() : List<String> {
return listOf(collection, seed.toString(), size.toString() , baseStructureSize.toString(), datastructure, best)
}
......@@ -22,6 +34,7 @@ class JMHProcessor {
fun generateSyntheticBenchmark() : BCBenchmarkPackage<*>? {
var syntheticBenchmark : BCBenchmarkPackage<*>? = null
val dataStructure = getClassFromSimpleName(datastructure)
if (collection == "List") {
syntheticBenchmark = BCBenchmarkPackage.LIST(seed, size, baseStructureSize, dataStructure as MutableList<Object>?)
return syntheticBenchmark
......@@ -52,6 +65,9 @@ class JMHProcessor {
"Param: baseStructureSize"
)
/**
* Reads CSV data from a Reader and produces a list of JMH Record data
*/
fun process(reader : Reader): List<JMHRecord> {
var parser = CSVParser(reader, CSVFormat.DEFAULT.withFirstRecordAsHeader())
// We are grouping the parameters by any parameter except the data structure name (which we want)
......@@ -69,10 +85,21 @@ class JMHProcessor {
.let { Integer.parseInt(it)}
val baseStructureSize = records[0].get("Param: baseStructureSize")
.let { Integer.parseInt(it)}
val methodSelection =
if (records[0].isSet("Param: methodSelectionStrategyId")) {
records[0].get("Param: methodSelectionStrategyId")
} else {
null
}
val best = getBestDataStructure(records)
records.map{
JMHRecord(seed, size, baseStructureSize, interfaceName, it.get("Param: datastructureName"), best!!)
records.map{
JMHRecord(seed, size, baseStructureSize,
interfaceName, it.get("Param: datastructureName"), best!!,
methodSelection)
}
}
}
......
......@@ -320,6 +320,76 @@ class JMHProcessorTest {
}
}
/**
* Tests that we can load a benchmark which uses Markov-based method selection
*/
@Test
fun testLoadingMarkovBenchmark() {
val header = listOf<String>(
"Benchmark",
"Mode",
"Threads",
"Samples",
"Score",
"Score Error (99.9%)",
"Unit",
"Param: applicationSize",
"Param: baseStructureSize",
"Param: datastructureName",
"Param: methodSelectionStrategyId",
"Param: seed"
).joinToString(",")
var data = mutableListOf<String>()
var row1 =
listOf(
"\"se.lth.cs.jmh.ListApplicationBenchmark.ListApplicationBenchmark\"",
"\"thrpt\"",
1,
10,
185.524701,
29.416447,
"ops/s",
10,
0,
"LinkedList",
"MARKOV",
0
).joinToString(",")
var row2 =
listOf(
"\"se.lth.cs.jmh.ListApplicationBenchmark.ListApplicationBenchmark\"",
"\"thrpt\"",
1,
10,
414.886418,
200.555845,
"ops/s",
10,
100,
"ArrayList",
"MARKOV",
0
).joinToString(",")
data.add(row1)
data.add(row2)
val text = "$header\n${data.joinToString("\n")}"
val reader = StringReader(text)
val result = processor!!.process(reader)
Assert.assertEquals(
listOf(
JMHProcessor.JMHRecord(0, 10, 0,
"List", "LinkedList", "LinkedList",
"MARKOV"),
JMHProcessor.JMHRecord(0, 10, 100,
"List", "ArrayList", "ArrayList",
"MARKOV")
),
result
)
}
companion object {
/**
* Static method to generate some example data
......
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