--- a/s/BenchmarkExecutor.st Mon Mar 10 11:29:09 2014 +0000
+++ b/s/BenchmarkExecutor.st Wed May 21 12:32:17 2014 +0100
@@ -135,6 +135,82 @@
"Created: / 12-08-2013 / 00:11:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 10-03-2014 / 10:23:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+spy: aBenchmarkInstance result: aBenchmarkResult defines: aDictionary
+ "
+ Takes a benchmark instance and a set of parameter defines,
+ then executes the benchmark under MessageTally profiler.
+ Given defines must define only one combination, otherwise
+ and error is thrown.
+
+ This can be used for rough in-image profiling
+ "
+
+ | parameters combinator |
+
+ aBenchmarkResult initializeTimestampIfNotAlready.
+ parameters := aBenchmarkInstance parameters collect:[:parameter|
+ | key1 key2 valuesString values defined |
+
+ key1 := aBenchmarkInstance instance class name , '#' , parameter name.
+ key2 := parameter name.
+ defined := true.
+ valuesString := aDictionary at: key1 ifAbsent:[aDictionary at: key2 ifAbsent:[defined := false]].
+ defined ifTrue:[
+ values := BenchmarkPlatform current isSmalltalkX
+ ifTrue:[valuesString tokensBasedOn: $,]
+ ifFalse:[valuesString subStrings:','].
+ values := values collect:[:each|
+
+ (parameter type includesBehavior: String) ifTrue:[
+ each
+ ] ifFalse:[
+ | s v |
+
+ s := each readStream.
+ v := parameter type readFrom: s onError:[
+ "JV: Note for Smalltalk/X: #signal: is actually an ANSI 1.9 protocol!!"
+ BenchmarkParameterError new signal: 'Cannot read parameter value for ' , parameter name , ' (parse error)'
+ ].
+ s atEnd ifFalse:[
+ "JV: Note for Smalltalk/X: #signal: is actually an ANSI 1.9 protocol!!"
+ BenchmarkParameterError new signal: 'Cannot read parameter value for ' , parameter name , ' (parse error)'
+ ].
+ v.
+ ].
+ ]
+
+ ] ifFalse:[
+ parameter default == BenchmarkParameter undefinedValue ifTrue:[
+ BenchmarkParameterError new signal: 'Parameter value for ' , parameter name , ' not specified and parameter has no default value'.
+ ].
+ values := Array with: parameter default.
+ ].
+ values size > 1 ifTrue:[
+ BenchmarkParameterError new signal: 'Multiple parameter values for param ', parameter name , '. No parameter combinating allowed when running under profiler!!'.
+ ].
+ parameter -> values
+ ].
+
+ parameters := parameters asOrderedCollection sort:[:a :b | a key name < b key name ].
+
+ combinator := [:parametersAndValues |
+ parametersAndValues size = parameters size ifTrue:[
+ self spy: aBenchmarkInstance result: aBenchmarkResult parameters: parametersAndValues.
+ ] ifFalse:[
+ | parameter |
+
+ parameter := parameters at: parametersAndValues size + 1.
+ parameter value do:[:value |
+ combinator value: (parametersAndValues copyWith: (parameter key -> value)).
+ ]
+ ]
+ ].
+
+ combinator value: #().
+
+ "Created: / 21-05-2014 / 10:44:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!BenchmarkExecutor methodsFor:'executing-private'!
@@ -197,6 +273,18 @@
"Modified: / 01-08-2013 / 19:14:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+spyIt: aBenchmarkInstance
+ | t |
+ [
+ t := aBenchmarkInstance spyIt.
+ ] on: Error do:[:ex|
+ BenchmarkExecutionError new signal:'Error during measurement: ', ex description.
+ ].
+ ^t
+
+ "Created: / 21-05-2014 / 10:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
tearDown: aBenchmarkInstance
[
aBenchmarkInstance tearDown.
@@ -232,6 +320,33 @@
"Modified: / 31-07-2013 / 01:04:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!BenchmarkExecutor methodsFor:'profiling-private'!
+
+spy: aBenchmarkInstance result: aBenchmarkResult parameters: aCollection
+ "
+ Takes a benchmark instance and a set of parameter defines,
+ runs it under MessageTally profiler and show profiling results.
+ "
+
+ | times outcome |
+
+ [
+ self setUp:aBenchmarkInstance parameters: aCollection .
+ self warmUp: aBenchmarkInstance.
+ times := Array with: (self spyIt: aBenchmarkInstance).
+ aBenchmarkResult addOutcome:
+ (outcome := BenchmarkOutcome
+ benchmark: aBenchmarkInstance
+ times: times
+ parameters: aCollection)
+ ] ensure:[
+ self tearDown: aBenchmarkInstance
+ ].
+ ^ outcome
+
+ "Created: / 21-05-2014 / 10:44:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!BenchmarkExecutor class methodsFor:'documentation'!
version_HG