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

Added class for processing of JMH Generated CSV files

The class has methods to read JMH generated files and produce the training set
with applications (seed and size) and the winning data structure.
parent f217ab75
......@@ -64,6 +64,9 @@ dependencies {
compile 'org.slf4j:slf4j-simple:1.7.13'
compile 'org.eclipse.jgit:org.eclipse.jgit:5.2.1.201812262042-r'
// Reading CSV files
compile 'org.apache.commons:commons-csv:1.6'
implementation 'com.google.code.gson:gson:2.8.5'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
......
package se.lth.cs
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVParser
import java.io.File
import java.io.FileReader
import java.io.Reader
class JMHProcessor {
fun processFile(filename: String): List<String?> {
return processReader(FileReader(File(filename)))
}
fun processReader(reader: Reader): List<String?> {
var parser = CSVParser(reader, CSVFormat.DEFAULT.withFirstRecordAsHeader())
// We are grouping the parameters by any parameter excep the data structure name (which we want)
val columns = parser.headerMap.keys
val selectedColumns = columns
.filter { it -> it.contains("Param") }
.minus("Param: datastructureName")
val seedsToRecords = parser.records.groupBy { record ->
selectedColumns.map { column -> record.get(column) }
}
return seedsToRecords.values.map { records ->
val seed = records[0].get("Param: seed")
val size = records[0].get("Param: applicationSize")
val bestScore = records.maxBy { it.get("Score") }
return listOf(seed, size, bestScore?.get("Param: datastructureName"))
}
}
}
import org.junit.Assert
import org.junit.Test
import se.lth.cs.JMHProcessor
import java.io.StringReader
class JMHProcessorTest {
@Test
fun Test() {
val processor = JMHProcessor()
val header =
listOf(
"Benchmark",
"Mode",
"Threads",
"Samples",
"Score",
"Score Error (99.9%)",
"Unit",
"Param: applicationSize",
"Param: baseStructureSize",
"Param: datastructureName",
"Param: seed"
).map { "\"$it\""}.joinToString(",")
val data =
listOf(
"\"se.lth.cs.jmh.ListApplicationBenchmark.ListApplicationBenchmark\"",
"\"thrpt\"",
1,
10,
185.524701,
29.416447,
"ops/s",
10,
0,
"LinkedList",
0
).joinToString(",")
val text = "$header\n$data"
val reader = StringReader(text)
val result = processor.processReader(reader)
Assert.assertEquals(
listOf("0","10","LinkedList")
, result
)
}
}
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