Skip to content

Commit 3cb0b32

Browse files
committed
Move and cleanup benchmarks
1 parent 18136c2 commit 3cb0b32

4 files changed

Lines changed: 120 additions & 9 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import be.ugent.topl.mio.connections.SerialConnection
44
import be.ugent.topl.mio.debugger.Debugger
55
import java.io.File
66

7-
abstract class EmulatorTestBase {
7+
abstract class DebuggerTestBase {
88
protected val config = DebuggerConfig()
99
protected val wdcliPath: String = config.wdcliPath
1010

@@ -13,7 +13,7 @@ abstract class EmulatorTestBase {
1313
}
1414

1515
protected fun <T> runWithDebugger(file:String, emulator: Boolean = false, action: (Debugger) -> T): T {
16-
val connection = if (emulator) ProcessConnection(wdcliPath, getFile(file).path, "--no-socket") else SerialConnection(config.port)
16+
val connection = if (emulator) ProcessConnection(wdcliPath, getFile(file).path, "--no-socket") else SerialConnection(config.port ?: throw RuntimeException("Port was not configured!"))
1717
val debugger = Debugger(connection)
1818
if (!emulator) {
1919
debugger.updateModule(getFile(file).absolutePath)

src/test/kotlin/DebuggerTests.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import kotlin.math.ceil
1212
import kotlin.random.Random
1313
import kotlin.test.assertEquals
1414

15-
class DebuggerTests : EmulatorTestBase() {
15+
class DebuggerTests : DebuggerTestBase() {
1616
@Test
1717
fun `Test if step back results in the same state`() {
1818
val binaryInfo = getBinaryInfo(config.symbolicWdcliPath, getFile("blink.wasm").absolutePath)
@@ -51,6 +51,8 @@ class DebuggerTests : EmulatorTestBase() {
5151
}
5252
}
5353

54+
// forward-execution-checkpointing.csv
55+
// First graph
5456
@Test
5557
fun `Test continue for operation speed with and without checkpointing`() {
5658
val writer = FileWriter(File("results-forward-execution.csv"))
@@ -253,6 +255,7 @@ class DebuggerTests : EmulatorTestBase() {
253255
}
254256
}
255257

258+
// step-back-reexecute.csv
256259
@Test
257260
fun `Step back test 3`() {
258261
val wasmFile = "prime/prime-no-mem.wasm"
@@ -383,8 +386,3 @@ class DebuggerTests : EmulatorTestBase() {
383386
println(compressRLE(listOf("00", "00", "00", "00", "00"), 3))
384387
}
385388
}
386-
387-
fun main() {
388-
val x = DebuggerTests()
389-
x.`Test stepBack performance 2`()
390-
}

src/test/kotlin/RLETests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import be.ugent.topl.mio.woodstate.compressRLE
55
import kotlin.random.Random
66
import kotlin.test.assertEquals
77

8-
class RLETests : EmulatorTestBase() {
8+
class RLETests : DebuggerTestBase() {
99
private fun loadAndRestore(debugger: Debugger, mutator: (s: WOODDumpResponse) -> Unit) {
1010
val snapshot = debugger.snapshotFull().second
1111
mutator(snapshot)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package benchmarks
2+
3+
import DebuggerTestBase
4+
import be.ugent.topl.mio.debugger.Debugger
5+
import getBinaryInfo
6+
import org.junit.jupiter.api.Test
7+
import java.io.File
8+
import java.io.FileWriter
9+
import java.lang.System.currentTimeMillis
10+
11+
/**
12+
* Benchmarks which use a headless version of MIO to test the performance of various operations. To get accurate
13+
* performance estimates they should be performed with an actual microcontroller since communication latency is an
14+
* important factor.
15+
*/
16+
class Benchmarks : DebuggerTestBase() {
17+
/**
18+
* Executes the code using continueFor over n instructions and measures how much time it takes with different
19+
* checkpointing strategies.
20+
*/
21+
@Test
22+
fun `Measure impact of checkpointing on forward execution`() {
23+
val writer = FileWriter(File("results-forward-execution.csv"))
24+
writer.write("Policy, Instructions executed, Time elapsed\n")
25+
val results = mutableListOf<Triple<Int, Double, Debugger.SnapshotPolicy>>()
26+
for (policy in listOf(
27+
Debugger.SnapshotPolicy.None(),
28+
Debugger.SnapshotPolicy.Checkpointing(1),
29+
Debugger.SnapshotPolicy.Checkpointing(5),
30+
Debugger.SnapshotPolicy.Checkpointing(10),
31+
Debugger.SnapshotPolicy.Checkpointing(50),
32+
Debugger.SnapshotPolicy.Checkpointing(100))) {
33+
34+
for (n in 250 ..< 1500 step 250) {
35+
println("Progress $n/1500")
36+
var totalTime = 0L
37+
val times = 10
38+
repeat(times) {
39+
runWithDebugger("prime/prime-no-mem.wasm", true) {
40+
it.setSnapshotPolicy(policy)
41+
val startTime = currentTimeMillis()
42+
it.continueFor(n)
43+
totalTime += currentTimeMillis() - startTime
44+
}
45+
}
46+
writer.write("$policy, $n, ${totalTime.toDouble() / times}\n")
47+
writer.flush()
48+
}
49+
}
50+
writer.close()
51+
52+
println("Policy, Instructions executed, Time elapsed")
53+
for (result in results) {
54+
println("${result.third}, ${result.first}, ${result.second}")
55+
}
56+
}
57+
58+
/**
59+
* Executes 1000 instructions, then steps back 1, needing 999 instructions to be re-executed. Because checkpoints
60+
* are deleted, it first has to re-execute 999 then 1999 then 2999 and so on. Since it steps back one instruction it
61+
* also needs to step forward.
62+
*/
63+
@Test
64+
fun `Measure re-execution speed when stepping back`() {
65+
val wasmFile = "prime/prime-no-mem.wasm"
66+
val binaryInfo = getBinaryInfo(config.symbolicWdcliPath, getFile(wasmFile).absolutePath)
67+
val results = mutableListOf<List<Pair<Int, Long>>>()
68+
repeat(10) {
69+
runWithDebugger(wasmFile, true) {
70+
var t = 0
71+
val timings = mutableListOf<Pair<Int, Long>>()
72+
it.setSnapshotPolicy(Debugger.SnapshotPolicy.Checkpointing(0xffffff))
73+
it.stepInto()
74+
it.checkpoints[it.checkpoints.size - 1] = null
75+
timings.add(Pair(t, timeElapsed {
76+
it.stepBack(1, binaryInfo) {}
77+
}))
78+
79+
(0..30).forEach { i ->
80+
it.continueFor(1000)
81+
it.checkpoints[it.checkpoints.size - 1] = null
82+
t += 999
83+
timings.add(Pair(t, timeElapsed {
84+
it.stepBack(1, binaryInfo) {}
85+
}))
86+
it.checkpoints[it.checkpoints.size - 1] = null
87+
}
88+
println(timings)
89+
results.add(timings)
90+
}
91+
}
92+
val average = mutableListOf<Pair<Int, Float>>()
93+
for (i in results[0].indices) {
94+
var sum = 0.0
95+
for (run in results.indices) {
96+
sum += results[run][i].second
97+
}
98+
average.add(Pair(results[0][i].first, sum.toFloat() / results.size))
99+
}
100+
val writer = FileWriter(File("results-step-back-re-execution.csv"))
101+
writer.write("t, avg_time\n")
102+
for (pair in average) {
103+
writer.write("${pair.first}, ${pair.second}\n")
104+
}
105+
writer.close()
106+
}
107+
108+
private fun timeElapsed(action: () -> Unit): Long {
109+
val startTime = currentTimeMillis()
110+
action()
111+
return currentTimeMillis() - startTime
112+
}
113+
}

0 commit comments

Comments
 (0)