@@ -5,21 +5,54 @@ 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
53
+ // store all results
54
+ override def historian : RegressionReporter .Historian = RegressionReporter .Historian .Complete ()
55
+
23
56
override def executor : Executor = LocalExecutor (warmer, aggregator, measurer)
24
57
val testNames = getMethodsAnnotatedWith(targetClass, filterAnnot).map(_.getName).sorted
25
58
@@ -29,15 +62,31 @@ abstract class TestsToBenchmarkConverter
29
62
(name, Gen .single(" test" )(name).map(Request .method(targetClass, _).getRunner))}.toMap
30
63
// Gen.enumeration("test")(testNames:_*)
31
64
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
+ }
39
74
}
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()
41
90
}
42
91
43
92
def getMethodsAnnotatedWith (clazz : Class [_], annotation : Class [_ <: java.lang.annotation.Annotation ]): List [Method ] = {
0 commit comments