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

Made experiment return a stream

I /think/ this helps with a memory leak, you can garbage collect the
results of an experiment as soon as you have consumed it, instead of
keeping it in memory. I'm not certain that's very important, though,
cause we don't store that many elements...
parent 8117311f
......@@ -6,6 +6,7 @@ import se.lth.cs.papicounters.PAPICounter
import se.lth.cs.papicounters.PapiBenchmarkAnalyzer
import se.lth.cs.papicounters.PapiTracerRunner
import se.lth.cs.timing.OperationTypeTable
import java.util.stream.Stream
class Experiment(val numberIterations : Int,
val benchmark : BCBenchmarkPackage<*>,
......@@ -26,7 +27,7 @@ class Experiment(val numberIterations : Int,
}
}
fun getIterations(): List<List<PapiTracerRunner.TraceRecord>> {
fun getIterations(): Stream<List<PapiTracerRunner.TraceRecord>> {
val eventSetBuilder = EventSetBuilder()
eventSetBuilder.visitFeatureSet(features)
......@@ -37,29 +38,33 @@ class Experiment(val numberIterations : Int,
PapiBenchmarkAnalyzer.RunSpec(numberIterations, counters.toList(), evSet, benchmark)
)
return iterations
return iterations.stream()
}
fun run() : List<Result> {
if (features.isEmpty()) { return listOf() }
private fun runIteration(i : List<PapiTracerRunner.TraceRecord>,
iterationNumber: Int): Result {
currentIteration = i
currentIterationResults = mutableMapOf()
// We aggregate all our features for that
// specific iteration!
features.accept(this)
val values = currentIterationResults.toMap()
return Result(iterationNumber, benchmark, values)
}
fun run() : Stream<Result> {
if (features.isEmpty()) { return Stream.empty() }
val iterations = getIterations()
var iterationNumber = 0
val results = mutableListOf<Result>()
for (i in iterations) {
currentIteration = i
currentIterationResults = mutableMapOf()
// We aggregate all our features for that
// specific iteration!
features.accept(this)
val values = currentIterationResults.toMap()
results.add(Result(iterationNumber, benchmark, values))
return iterations.map {
val r = runIteration(it, iterationNumber)
iterationNumber++
r
}
return results.toList()
}
var currentIteration : List<PapiTracerRunner.TraceRecord> = listOf()
......
......@@ -7,6 +7,7 @@ import se.lth.cs.papicounters.PAPICounter
import se.lth.cs.papicounters.PapiTracerRunner
import se.lth.cs.timing.OperationType
import se.lth.cs.util.*
import java.util.stream.Collectors
class ExperimentTest {
......@@ -18,7 +19,7 @@ class ExperimentTest {
val exp = Experiment(10, bench, FeatureSet(), runner)
val results = exp.run()
val results = exp.run().collect(Collectors.toList())
Assertions.assertTrue(results.isEmpty())
}
......@@ -30,7 +31,7 @@ class ExperimentTest {
runner
)
val results = exp.run()
val results = exp.run().collect(Collectors.toList())
Assertions.assertEquals(10, results.size)
Assertions.assertEquals(
......
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