SyntheticBenchmarkExperimentPrinterTest.kt 5.2 KB
Newer Older
1
2
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
3
4
import papi.Constants
import papi.EventSet
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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(
25
26
            PAPICounter("PAPI_TOT_CYC"),
            MethodInvocations("java.util.List.add", "JAVA-STANDARD-FORMAT")
27
28
29
30
31
32
33
34
35
36
37
38
39
        )
        val printer = SyntheticBenchmarkExperimentPrinter(writer,
            "",
            10,
            features,
            MockupPapiTracerRunner())

        printer.printToCSV(listOf())

        Assertions.assertEquals("benchmark_id,iteration,feature,feature_type,value\n",
            writer.toString())
    }

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    @Test
    fun testTracingAfterPrinting() {
        val writer = StringWriter()
        val features = FeatureSet(
            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)

        // We check we can still gather counters after that
        val eventSet = EventSet.create(Constants.PAPI_TOT_CYC)
        eventSet.start()
        eventSet.stop()
    }

65
66
67
68
    @Test
    fun testListBenchmarks() {
        val writer = StringWriter()
        val features = FeatureSet(
69
70
71
            PAPICounter("PAPI_TOT_CYC"),
            CostFeature(OperationType.INSERT),
            MethodInvocations("runAdd", "JAVA-STANDARD-FORMAT")
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
        )
        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())
    }
}