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 ...@@ -6,6 +6,7 @@ import se.lth.cs.papicounters.PAPICounter
import se.lth.cs.papicounters.PapiBenchmarkAnalyzer import se.lth.cs.papicounters.PapiBenchmarkAnalyzer
import se.lth.cs.papicounters.PapiTracerRunner import se.lth.cs.papicounters.PapiTracerRunner
import se.lth.cs.timing.OperationTypeTable import se.lth.cs.timing.OperationTypeTable
import java.util.stream.Stream
class Experiment(val numberIterations : Int, class Experiment(val numberIterations : Int,
val benchmark : BCBenchmarkPackage<*>, val benchmark : BCBenchmarkPackage<*>,
...@@ -26,7 +27,7 @@ class Experiment(val numberIterations : Int, ...@@ -26,7 +27,7 @@ class Experiment(val numberIterations : Int,
} }
} }
fun getIterations(): List<List<PapiTracerRunner.TraceRecord>> { fun getIterations(): Stream<List<PapiTracerRunner.TraceRecord>> {
val eventSetBuilder = EventSetBuilder() val eventSetBuilder = EventSetBuilder()
eventSetBuilder.visitFeatureSet(features) eventSetBuilder.visitFeatureSet(features)
...@@ -37,17 +38,11 @@ class Experiment(val numberIterations : Int, ...@@ -37,17 +38,11 @@ class Experiment(val numberIterations : Int,
PapiBenchmarkAnalyzer.RunSpec(numberIterations, counters.toList(), evSet, benchmark) PapiBenchmarkAnalyzer.RunSpec(numberIterations, counters.toList(), evSet, benchmark)
) )
return iterations return iterations.stream()
} }
fun run() : List<Result> { private fun runIteration(i : List<PapiTracerRunner.TraceRecord>,
if (features.isEmpty()) { return listOf() } iterationNumber: Int): Result {
val iterations = getIterations()
var iterationNumber = 0
val results = mutableListOf<Result>()
for (i in iterations) {
currentIteration = i currentIteration = i
currentIterationResults = mutableMapOf() currentIterationResults = mutableMapOf()
// We aggregate all our features for that // We aggregate all our features for that
...@@ -55,11 +50,21 @@ class Experiment(val numberIterations : Int, ...@@ -55,11 +50,21 @@ class Experiment(val numberIterations : Int,
features.accept(this) features.accept(this)
val values = currentIterationResults.toMap() val values = currentIterationResults.toMap()
results.add(Result(iterationNumber, benchmark, values)) return Result(iterationNumber, benchmark, values)
iterationNumber++
} }
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() var currentIteration : List<PapiTracerRunner.TraceRecord> = listOf()
......
...@@ -7,6 +7,7 @@ import se.lth.cs.papicounters.PAPICounter ...@@ -7,6 +7,7 @@ import se.lth.cs.papicounters.PAPICounter
import se.lth.cs.papicounters.PapiTracerRunner import se.lth.cs.papicounters.PapiTracerRunner
import se.lth.cs.timing.OperationType import se.lth.cs.timing.OperationType
import se.lth.cs.util.* import se.lth.cs.util.*
import java.util.stream.Collectors
class ExperimentTest { class ExperimentTest {
...@@ -18,7 +19,7 @@ class ExperimentTest { ...@@ -18,7 +19,7 @@ class ExperimentTest {
val exp = Experiment(10, bench, FeatureSet(), runner) val exp = Experiment(10, bench, FeatureSet(), runner)
val results = exp.run() val results = exp.run().collect(Collectors.toList())
Assertions.assertTrue(results.isEmpty()) Assertions.assertTrue(results.isEmpty())
} }
...@@ -30,7 +31,7 @@ class ExperimentTest { ...@@ -30,7 +31,7 @@ class ExperimentTest {
runner runner
) )
val results = exp.run() val results = exp.run().collect(Collectors.toList())
Assertions.assertEquals(10, results.size) Assertions.assertEquals(10, results.size)
Assertions.assertEquals( 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