s/BenchmarkReportJSON.st
changeset 29 00d2eaa41853
child 88 7939ec1b572b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/s/BenchmarkReportJSON.st	Wed Jun 12 14:27:14 2013 +0100
@@ -0,0 +1,88 @@
+"{ Package: 'jv:calipel/s' }"
+
+BenchmarkReport subclass:#BenchmarkReportJSON
+	instanceVariableNames:'json'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'CalipeL-S-Core-Reports'
+!
+
+
+!BenchmarkReportJSON methodsFor:'accessing'!
+
+stream:something
+    stream := something.
+    json := BenchmarkReportJSONWriter on: stream.
+
+    "Created: / 12-06-2013 / 14:22:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BenchmarkReportJSON methodsFor:'writing'!
+
+write
+    json writeDictionaryWith:[
+        json writeKey: 'outcomes' valueWith: [ self writeOutcomes ]
+    ].
+
+    "Created: / 12-06-2013 / 14:03:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+writeBenchmark: benchmark
+    json writeDictionaryWith:[
+        json writeKey: 'class' value: benchmark instance class name.
+        json writeElementSeparator.
+        json writeKey: 'selector' value: benchmark selector.
+    ]
+
+    "Created: / 12-06-2013 / 14:10:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+writeFooter
+    "superclass BenchmarkReport says that I am responsible to implement this method"
+
+    "Modified: / 12-06-2013 / 14:14:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+writeHeader
+    "superclass BenchmarkReport says that I am responsible to implement this method"
+
+    "Modified: / 12-06-2013 / 14:14:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+writeOutcome:outcome
+    json writeDictionaryWith:[
+        json writeKey: 'benchmark' valueWith: [ self writeBenchmark: outcome benchmark ].
+        json writeElementSeparator.
+        json writeKey: 'times' value: outcome times.
+        json writeElementSeparator.        
+        json writeKey: 'parameters' valueWith: [ self writeParameters: outcome ].
+    ]
+
+    "Modified: / 12-06-2013 / 14:10:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+writeOutcomes
+    "raise an error: must be redefined in concrete subclass(es)"
+    json writeArrayWith:[
+        result 
+           outcomesDo: [:outcome| self writeOutcome: outcome] 
+           separatedBy:[json writeElementSeparator]
+    ]
+
+    "Created: / 11-06-2013 / 23:39:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 12-06-2013 / 14:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+writeParameters: outcome
+    json writeDictionaryWith: []
+
+    "Created: / 12-06-2013 / 14:10:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BenchmarkReportJSON class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+