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,17 +38,11 @@ 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() }
val iterations = getIterations()
var iterationNumber = 0
val results = mutableListOf<Result>()
for (i in iterations) {
private fun runIteration(i : List<PapiTracerRunner.TraceRecord>,
iterationNumber: Int): Result {
currentIteration = i
currentIterationResults = mutableMapOf()
// We aggregate all our features for that
......@@ -55,11 +50,21 @@ class Experiment(val numberIterations : Int,
features.accept(this)
val values = currentIterationResults.toMap()
results.add(Result(iterationNumber, benchmark, values))
iterationNumber++
return Result(iterationNumber, benchmark, values)
}
return results.toList()
fun run() : Stream<Result> {
if (features.isEmpty()) { return Stream.empty() }
val iterations = getIterations()
var iterationNumber = 0
return iterations.map {
val r = runIteration(it, iterationNumber)
iterationNumber++
r
}
}
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