Skip to content

Commit 16b90f7

Browse files
committed
Merge pull request #1218 from dotty-staging/benchmarks
Workaround for ScalaMeter incorrect report path
2 parents b98e6bf + 2cd72de commit 16b90f7

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

bench/src/test/scala/TestsAsBenchmarks.scala

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,54 @@ import java.lang.reflect.Method
55

66
import org.junit.runner.Request
77
import org.junit.runner.notification.RunNotifier
8+
import org.scalameter.Key.reports._
89
import org.scalameter.PerformanceTest.OnlineRegressionReport
910
import org.scalameter.api._
11+
import org.scalameter.{Context, History, persistence, currentContext}
1012
import org.scalameter.reporting.RegressionReporter.Tester
1113

1214
import scala.collection.mutable.ListBuffer
1315

16+
// decorator of persitor to expose info for debugging
17+
class DecoratorPersistor(p: Persistor) extends SerializationPersistor {
18+
19+
override def load(context: Context): History = {
20+
val resultdir = currentContext(resultDir)
21+
val scope = context.scope
22+
val curve = context.curve
23+
val fileName = s"$resultdir$sep$scope.$curve.dat"
24+
25+
println(s"load file $fileName")
26+
27+
p.load(context)
28+
}
29+
30+
override def save(context: Context, h: History) = {
31+
val resultdir = currentContext(resultDir)
32+
val scope = context.scope
33+
val curve = context.curve
34+
val fileName = s"$resultdir$sep$scope.$curve.dat"
35+
36+
println(s"save file $fileName")
37+
38+
p.save(context, h)
39+
}
40+
}
1441

1542
abstract class TestsToBenchmarkConverter
1643
(targetClass: Class[_],
1744
filterAnnot: Class[_ <: java.lang.annotation.Annotation] = classOf[org.junit.Test].asInstanceOf[Class[_ <: java.lang.annotation.Annotation]])
1845
extends OnlineRegressionReport {
1946

47+
// NOTE: use `val persistor = ...` would cause persistor ignore command line options for `resultDir`
48+
override def persistor = new DecoratorPersistor(super.persistor)
49+
2050
// accept all the results, do not fail
2151
override def tester: Tester = new Tester.Accepter
2252

53+
// store all results
54+
override def historian: RegressionReporter.Historian = RegressionReporter.Historian.Complete()
55+
2356
override def executor: Executor = LocalExecutor(warmer, aggregator, measurer)
2457
val testNames = getMethodsAnnotatedWith(targetClass, filterAnnot).map(_.getName).sorted
2558

@@ -29,15 +62,31 @@ abstract class TestsToBenchmarkConverter
2962
(name, Gen.single("test")(name).map(Request.method(targetClass, _).getRunner))}.toMap
3063
//Gen.enumeration("test")(testNames:_*)
3164

32-
performance of targetClass.getSimpleName config (Context(reports.resultDir -> "./tmp")) in {
33-
for (test <- testNames)
34-
measure.method(test) in {
35-
using(tests(test)) curve test in {
36-
r =>
37-
val dummy = new RunNotifier()
38-
r.run(dummy)
65+
def setup =
66+
performance of targetClass.getSimpleName in {
67+
for (test <- testNames)
68+
measure.method(test) in {
69+
using(tests(test)) curve test in {
70+
r =>
71+
val dummy = new RunNotifier()
72+
r.run(dummy)
73+
}
3974
}
40-
}
75+
}
76+
77+
/** workaround to fix problem in ScalaMeter
78+
*
79+
* NOTE: Otherwise, command line options would be ignored by HTMLReporter, as
80+
* the HTMLReporter uses the context of tree node, which is created via
81+
* ScalaMeter DSL before command line option `-CresultDir` takes effect
82+
* in `PerformanceTest.main`.
83+
*
84+
* Following code ensures that the test tree is set up after the `-CresultDir`
85+
* option takes effect.
86+
**/
87+
override def executeTests(): Boolean = {
88+
setup
89+
super.executeTests()
4190
}
4291

4392
def getMethodsAnnotatedWith(clazz: Class[_], annotation: Class[_ <: java.lang.annotation.Annotation]): List[Method] = {

project/Build.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ object DottyBuild extends Build {
239239

240240
libraryDependencies ++= Seq("com.storm-enroute" %% "scalameter" % "0.6" % Test,
241241
"com.novocode" % "junit-interface" % "0.11"),
242-
testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework"),
243242

244243
fork in Test := true,
245244
parallelExecution in Test := false,

0 commit comments

Comments
 (0)