From 5b4b6bde235e47fcc7074578673dfea1077771a7 Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Thu, 21 May 2026 16:52:31 +1000 Subject: Added Benchmarking tools (#413) Added files for the smaller workload benchmarks Added benchmark examples Started implementing benchmarking functions --- .../opendc-experiments-base/build.gradle.kts | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'opendc-experiments/opendc-experiments-base/build.gradle.kts') diff --git a/opendc-experiments/opendc-experiments-base/build.gradle.kts b/opendc-experiments/opendc-experiments-base/build.gradle.kts index 8a77f0c4..b22e4d41 100644 --- a/opendc-experiments/opendc-experiments-base/build.gradle.kts +++ b/opendc-experiments/opendc-experiments-base/build.gradle.kts @@ -29,10 +29,48 @@ plugins { `jacoco-conventions` distribution kotlin("plugin.serialization") version "1.9.22" + id("me.champeau.jmh") +} + +jmh { + resultFormat.set("JSON") + includes.add(".*WorkloadNoExportBenchmark.*") +} + +tasks.named("jmh") { + doLast { + val resultsFile = layout.buildDirectory.file("results/jmh/results.json").get().asFile + val heapFile = layout.buildDirectory.file("heap-stats.csv").get().asFile + if (!resultsFile.exists() || !heapFile.exists()) return@doLast + + val heapByBenchmark = + heapFile.readLines().associate { line -> + val cols = line.split(",") + cols[0].trim('"') to + mapOf( + "avgMb" to cols[1].toDouble(), + "avgStdMb" to cols[2].toDouble(), + "maxMb" to cols[3].toDouble(), + "maxStdMb" to cols[4].toDouble(), + ) + } + heapFile.delete() + + @Suppress("UNCHECKED_CAST") + val results = groovy.json.JsonSlurper().parse(resultsFile) as List> + for (entry in results) { + val benchmark = entry["benchmark"] as String + heapByBenchmark[benchmark]?.let { entry["heapMetric"] = it } + } + + resultsFile.writeText(groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(results))) + } } dependencies { + implementation(kotlin("stdlib")) + api(projects.opendcCompute.opendcComputeSimulator) implementation(libs.clikt) -- cgit v1.2.3