From 3eb30ade5c85250535ee2fbac7208b114255ccdd Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Thu, 14 Apr 2016 22:16:48 +0200 Subject: [PATCH 1/2] 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. --- bench/src/test/scala/TestsAsBenchmarks.scala | 62 +++++++++++++++++--- project/Build.scala | 1 - 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/bench/src/test/scala/TestsAsBenchmarks.scala b/bench/src/test/scala/TestsAsBenchmarks.scala index a078c9f787e0..95c8197ee17d 100644 --- a/bench/src/test/scala/TestsAsBenchmarks.scala +++ b/bench/src/test/scala/TestsAsBenchmarks.scala @@ -5,18 +5,48 @@ import java.lang.reflect.Method import org.junit.runner.Request import org.junit.runner.notification.RunNotifier +import org.scalameter.Key.reports._ import org.scalameter.PerformanceTest.OnlineRegressionReport import org.scalameter.api._ +import org.scalameter.{Context, History, persistence, currentContext} import org.scalameter.reporting.RegressionReporter.Tester import scala.collection.mutable.ListBuffer +// decorator of persitor to expose info for debugging +class DecoratorPersistor(p: Persistor) extends SerializationPersistor { + + override def load(context: Context): History = { + val resultdir = currentContext(resultDir) + val scope = context.scope + val curve = context.curve + val fileName = s"$resultdir$sep$scope.$curve.dat" + + println(s"load file $fileName") + + p.load(context) + } + + override def save(context: Context, h: History) = { + val resultdir = currentContext(resultDir) + val scope = context.scope + val curve = context.curve + val fileName = s"$resultdir$sep$scope.$curve.dat" + + println(s"save file $fileName") + + p.save(context, h) + } +} abstract class TestsToBenchmarkConverter (targetClass: Class[_], filterAnnot: Class[_ <: java.lang.annotation.Annotation] = classOf[org.junit.Test].asInstanceOf[Class[_ <: java.lang.annotation.Annotation]]) extends OnlineRegressionReport { + // NOTE: use `val persistor = ...` would cause persistor ignore command line options for `resultDir` + override def persistor = new DecoratorPersistor(super.persistor) + // accept all the results, do not fail override def tester: Tester = new Tester.Accepter @@ -29,15 +59,31 @@ abstract class TestsToBenchmarkConverter (name, Gen.single("test")(name).map(Request.method(targetClass, _).getRunner))}.toMap //Gen.enumeration("test")(testNames:_*) - performance of targetClass.getSimpleName config (Context(reports.resultDir -> "./tmp")) in { - for (test <- testNames) - measure.method(test) in { - using(tests(test)) curve test in { - r => - val dummy = new RunNotifier() - r.run(dummy) + def setup = + performance of targetClass.getSimpleName in { + for (test <- testNames) + measure.method(test) in { + using(tests(test)) curve test in { + r => + val dummy = new RunNotifier() + r.run(dummy) + } } - } + } + + /** workaround to fix problem in ScalaMeter + * + * NOTE: Otherwise, command line options would be ignored by HTMLReporter, as + * the HTMLReporter uses the context of tree node, which is created via + * ScalaMeter DSL before command line option `-CresultDir` takes effect + * in `PerformanceTest.main`. + * + * Following code ensures that the test tree is set up after the `-CresultDir` + * option takes effect. + **/ + override def executeTests(): Boolean = { + setup + super.executeTests() } def getMethodsAnnotatedWith(clazz: Class[_], annotation: Class[_ <: java.lang.annotation.Annotation]): List[Method] = { diff --git a/project/Build.scala b/project/Build.scala index 723a7e129d2d..f6141844d768 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -239,7 +239,6 @@ object DottyBuild extends Build { libraryDependencies ++= Seq("com.storm-enroute" %% "scalameter" % "0.6" % Test, "com.novocode" % "junit-interface" % "0.11"), - testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework"), fork in Test := true, parallelExecution in Test := false, From 2cd72de0cfe7c24726cdabd1783740e20b366328 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Fri, 15 Apr 2016 11:42:22 +0200 Subject: [PATCH 2/2] store all benchmark results instead of doing expoential backoff --- bench/src/test/scala/TestsAsBenchmarks.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bench/src/test/scala/TestsAsBenchmarks.scala b/bench/src/test/scala/TestsAsBenchmarks.scala index 95c8197ee17d..cac34640fc26 100644 --- a/bench/src/test/scala/TestsAsBenchmarks.scala +++ b/bench/src/test/scala/TestsAsBenchmarks.scala @@ -50,6 +50,9 @@ abstract class TestsToBenchmarkConverter // accept all the results, do not fail override def tester: Tester = new Tester.Accepter + // store all results + override def historian: RegressionReporter.Historian = RegressionReporter.Historian.Complete() + override def executor: Executor = LocalExecutor(warmer, aggregator, measurer) val testNames = getMethodsAnnotatedWith(targetClass, filterAnnot).map(_.getName).sorted