Gitlab service upgraded. Please report any problems to dl_gitadmin@cs.lth.se

Commit 15a38332 authored by Noric Couderc's avatar Noric Couderc

Improved CSV printing of SW counters

Added a function "printFunction" for printing method names in a format that Java programmers can understand.

Made the map for functions bi-directional.

Updated tests.
parent cef90dfd
......@@ -44,7 +44,7 @@ class ApplicationDataPrinter(out : Writer) {
size,
baseStructureSize,
application.dataStructureSimpleName,
kvp.first,
printFunction(kvp.first),
kvp.second.toString()
)
}
......
......@@ -2,9 +2,11 @@ package se.lth.cs
import java.lang.IllegalArgumentException
// The table that allows to map from java standard method names to run* names
import org.apache.commons.collections4.BidiMap
import org.apache.commons.collections4.bidimap.DualHashBidiMap
val MethodNameTable = mapOf(
// The table that allows to map from java standard method names to run* names
val MethodNameTable = DualHashBidiMap(mapOf(
Pair("add(Object)", "runAdd"),
Pair("add(int, Object)", "runAdd2"),
Pair("addAll(Collection)", "runAddAll"),
......@@ -37,7 +39,7 @@ val MethodNameTable = mapOf(
Pair("toArray()", "runToArray"),
Pair("toArray(Object[])", "runToArray"),
Pair("values()", "runValues")
)
))
/**
* Converts the name of a method to the run* method that should be run in the application
......@@ -60,3 +62,8 @@ fun matchFunction(methodName : String) : String {
return match
}
}
fun printFunction(runMethodName : String) : String {
return MethodNameTable.getKey(runMethodName)?:
error(String.format("Could not translate method '%s'", runMethodName))
}
......@@ -7,6 +7,7 @@ import org.junit.Test
import se.lth.cs.Application
import se.lth.cs.ApplicationDataPrinter
import se.lth.cs.ListApplication
import se.lth.cs.printFunction
import java.io.*
import java.util.*
import java.util.concurrent.TimeUnit
......@@ -57,6 +58,7 @@ class ApplicationDataPrinterTest {
Pair(it.get("method"), it.get("count").toLong())
}
val targetHistogram = app.methodHistogram()
.mapKeys { printFunction(it.key) }
Assert.assertEquals(
TreeMap(targetHistogram).toString(),
TreeMap(pairs.toMap()).toString()
......@@ -74,14 +76,15 @@ class ApplicationDataPrinterTest {
printer!!.printToCSV(apps)
val expected=
"seed,size,base_structure_size,data_structure,method,count\n" +
"0,10,0,ArrayList,runAdd,1\n" +
"0,10,0,ArrayList,runAddAll,2\n" +
"0,10,0,ArrayList,runAddAll2,2\n" +
"0,10,0,ArrayList,runGet2,1\n" +
"0,10,0,ArrayList,runIterator,1\n" +
"0,10,0,ArrayList,runListIterator2,1\n" +
"0,10,0,ArrayList,runRemove,1\n" +
"0,10,0,ArrayList,runSubList,1\n"
"0,10,0,ArrayList,\"add(int, Object)\",1\n" +
"0,10,0,ArrayList,clear(),1\n" +
"0,10,0,ArrayList,contains(Object),1\n" +
"0,10,0,ArrayList,containsAll(Collection),1\n" +
"0,10,0,ArrayList,equals(Object),1\n" +
"0,10,0,ArrayList,hashCode(),1\n" +
"0,10,0,ArrayList,remove(int),1\n" +
"0,10,0,ArrayList,removeAll(Collection),1\n" +
"0,10,0,ArrayList,toArray(Object[]),2\n"
Assert.assertEquals(
expected, writer.toString()
)
......
Markdown is supported
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