@@ -5,18 +5,48 @@ import java.lang.reflect.Method
5
5
6
6
import org .junit .runner .Request
7
7
import org .junit .runner .notification .RunNotifier
8
+ import org .scalameter .Key .reports ._
8
9
import org .scalameter .PerformanceTest .OnlineRegressionReport
9
10
import org .scalameter .api ._
11
+ import org .scalameter .{Context , History , persistence , currentContext }
10
12
import org .scalameter .reporting .RegressionReporter .Tester
11
13
12
14
import scala .collection .mutable .ListBuffer
13
15
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
+ }
14
41
15
42
abstract class TestsToBenchmarkConverter
16
43
(targetClass : Class [_],
17
44
filterAnnot : Class [_ <: java.lang.annotation.Annotation ] = classOf [org.junit.Test ].asInstanceOf [Class [_ <: java.lang.annotation.Annotation ]])
18
45
extends OnlineRegressionReport {
19
46
47
+ // NOTE: use `val persistor = ...` would cause persistor ignore command line options for `resultDir`
48
+ override def persistor = new DecoratorPersistor (super .persistor)
49
+
20
50
// accept all the results, do not fail
21
51
override def tester : Tester = new Tester .Accepter
22
52
@@ -29,15 +59,31 @@ abstract class TestsToBenchmarkConverter
29
59
(name, Gen .single(" test" )(name).map(Request .method(targetClass, _).getRunner))}.toMap
30
60
// Gen.enumeration("test")(testNames:_*)
31
61
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
+ }
39
71
}
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()
41
87
}
42
88
43
89
def getMethodsAnnotatedWith (clazz : Class [_], annotation : Class [_ <: java.lang.annotation.Annotation ]): List [Method ] = {
0 commit comments