Skip to content

Commit 3eb30ad

Browse files
committed
workaround for ScalaMeter incorrect report path
The ScalaMeter issue is reported here: https://github.com/scalameter/scalameter/pull/163/files The issue exists both in v0.7 and v0.6. As dotty uses v0.6 now, use this workaround until we upgrate to a new version of ScalaMeter.
1 parent b56f5c9 commit 3eb30ad

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

bench/src/test/scala/TestsAsBenchmarks.scala

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,48 @@ 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

@@ -29,15 +59,31 @@ abstract class TestsToBenchmarkConverter
2959
(name, Gen.single("test")(name).map(Request.method(targetClass, _).getRunner))}.toMap
3060
//Gen.enumeration("test")(testNames:_*)
3161

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)
62+
def setup =
63+
performance of targetClass.getSimpleName in {
64+
for (test <- testNames)
65+
measure.method(test) in {
66+
using(tests(test)) curve test in {
67+
r =>
68+
val dummy = new RunNotifier()
69+
r.run(dummy)
70+
}
3971
}
40-
}
72+
}
73+
74+
/** workaround to fix problem in ScalaMeter
75+
*
76+
* NOTE: Otherwise, command line options would be ignored by HTMLReporter, as
77+
* the HTMLReporter uses the context of tree node, which is created via
78+
* ScalaMeter DSL before command line option `-CresultDir` takes effect
79+
* in `PerformanceTest.main`.
80+
*
81+
* Following code ensures that the test tree is set up after the `-CresultDir`
82+
* option takes effect.
83+
**/
84+
override def executeTests(): Boolean = {
85+
setup
86+
super.executeTests()
4187
}
4288

4389
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)