Skip to content

Workaround for ScalaMeter incorrect report path #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 57 additions & 8 deletions bench/src/test/scala/TestsAsBenchmarks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,54 @@ 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

// 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

Expand All @@ -29,15 +62,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] = {
Expand Down
1 change: 0 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this, because we never run dotty-bench/test, we use dotty-bench/test:run. The latter doesn't require the framework integration.

fork in Test := true,
parallelExecution in Test := false,
Expand Down