made all print stuff instance methods;
authorClaus Gittinger <cg@exept.de>
Sat, 22 Mar 1997 16:57:17 +0100
changeset 571 58e603e1ce24
parent 570 9c3efb856ee6
child 572 5b57c4c128af
made all print stuff instance methods; handle spy on a returning blocks.
MessageTally.st
MsgTally.st
--- a/MessageTally.st	Sat Mar 22 16:31:37 1997 +0100
+++ b/MessageTally.st	Sat Mar 22 16:57:17 1997 +0100
@@ -11,7 +11,8 @@
 "
 
 Object subclass:#MessageTally
-	instanceVariableNames:'tree probes ntally theBlock spyInterval executing spyOutStream'
+	instanceVariableNames:'tree probes ntally theBlock spyInterval executing startTime
+		endTime'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'System-Debugging-Support'
@@ -162,122 +163,44 @@
 
 !MessageTally class methodsFor:'spying - private'!
 
-noProbesTo:outStream
-    outStream cr.
-    outStream nextPutLine:'TALLY: No probes - execution time too short;'.
-    outStream nextPutLine:'TALLY: retry using: spyOn:[n timesRepeat:[...]]'.
-
-    "Created: 22.3.1997 / 16:24:25 / cg"
-!
-
 spyLeafOn:aBlock interval:ms to:outStream
     "evaluate aBlock and output leaf method statistics on outStream"
 
-    |runTime aTally nTally err|
+    |aTally|
 
     aTally := self new.
-    runTime := aTally spyLeafOn:aBlock interval:ms.
 
-    nTally := aTally nTally.
-    nTally == 0 ifTrue:[
-        self noProbesTo:outStream.
-        ^ self.
+    [
+        [
+            aTally spyLeafOn:aBlock interval:ms.
+        ] valueOnUnwindDo:[
+            outStream nextPutLine:'TALLY: block returned'.
+        ]
+    ] valueNowOrOnUnwindDo:[
+        aTally printLeafStatisticOn:outStream
     ].
 
-    "/ aTally probes inspect.
-
-    outStream cr.
-    err := (1000 // nTally / 10.0).
-    err > 0 ifTrue:[
-        outStream nextPutLine:('total execution time: '
-                           , runTime printString , ' ms '
-                           , '(' , nTally printString , ' probes ;'
-                           , ' error >= ' 
-                           , (1000 // nTally / 10.0) printString
-                           , '%)'
-                          ).
-    ] ifFalse:[
-        outStream nextPutLine:('total execution time: '
-                           , runTime printString , ' ms '
-                           , '(' , nTally printString , ' probes)'
-                          ).
-    ].
-
-    outStream nextPutLine:'method leafs of calling tree:'.
-    outStream cr.
-    aTally printFlatMethodLeafsOn:outStream.
-    outStream cr; cr.
-
-    "Modified: 20.3.1997 / 21:01:29 / cg"
-    "Created: 22.3.1997 / 16:24:09 / cg"
+    "Modified: 22.3.1997 / 16:50:47 / cg"
 !
 
 spyOn:aBlock interval:ms to:outStream
     "evaluate aBlock and output full statistics on outstream"
 
-    |runTime aTally nTally err tree|
+    |aTally|
 
     aTally := self new.
-    runTime := aTally spyOn:aBlock interval:ms.
 
-    aTally nTally == 0 ifTrue:[
-        self noProbesTo:outStream.
-        ^ self
-    ].
-
-    "/ aTally tree inspect.
-    nTally := aTally nTally.
-    outStream cr.
-    err := (1000 // nTally / 10.0).
-    err > 0 ifTrue:[
-        outStream nextPutLine:('total execution time: '
-                           , runTime printString , ' ms '
-                           , '(' , nTally printString , ' probes ;'
-                           , ' error >= ' 
-                           , (1000 // nTally / 10.0) printString
-                           , '%)'
-                          ).
-    ] ifFalse:[
-        outStream nextPutLine:('total execution time: '
-                           , runTime printString , ' ms '
-                           , '(' , nTally printString , ' probes)'
-                          ).
+    [
+        [
+            aTally spyOn:aBlock interval:ms.
+        ] valueOnUnwindDo:[
+            outStream nextPutLine:'TALLY: block returned'.
+        ]
+    ] valueNowOrOnUnwindDo:[
+        aTally printFullStatisticOn:outStream
     ].
 
-    tree := aTally tree.
-
-    outStream cr.
-    tree printOn:outStream.
-    outStream cr; cr.
-
-    outStream nextPutLine:'leafs of calling tree (by receiver & implementing method):'.
-    outStream cr.
-    tree printLeafsOn:outStream.
-    outStream cr; cr.
-
-    outStream nextPutLine:'method leafs of calling tree (by implementing method only):'.
-    outStream cr.
-    tree printMethodLeafsOn:outStream.
-    outStream cr; cr.
-
-    "
-    aTally statistics.
-    "
-
-    "
-     MessageTally spyOn:[ #(6 5 4 3 2 1) sort ]
-     MessageTally spyOn:[100 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-     MessageTally spyOn:[1000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-     MessageTally spyOn:[10000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-     MessageTally spyOn:[100000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-     MessageTally spyOn:[500000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-     MessageTally spyOn:[SystemBrowser open ]
-     MessageTally spyDetailedOn:[SystemBrowser open ]
-     Time millisecondsToRun:[500000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-    "
-
-    "Modified: 20.3.1997 / 21:00:57 / cg"
-    "Created: 22.3.1997 / 16:25:59 / cg"
+    "Modified: 22.3.1997 / 16:54:36 / cg"
 ! !
 
 !MessageTally class methodsFor:'spying - public interface'!
@@ -324,6 +247,15 @@
 
 !MessageTally methodsFor:'accessing'!
 
+endTime
+    "return the endTime of the run"
+
+    ^ endTime
+
+    "Modified: 18.5.1996 / 18:47:47 / cg"
+    "Created: 22.3.1997 / 16:44:29 / cg"
+!
+
 nTally 
     "return the number of accumulated probes"
 
@@ -341,6 +273,15 @@
     "Created: 20.3.1997 / 20:54:19 / cg"
 !
 
+startTime
+    "return the startTime of the run"
+
+    ^ startTime
+
+    "Modified: 18.5.1996 / 18:47:47 / cg"
+    "Created: 22.3.1997 / 16:44:33 / cg"
+!
+
 tree
     "return the accumulated calling tree"
 
@@ -369,6 +310,108 @@
 
     "Created: 20.3.1997 / 20:56:13 / cg"
     "Modified: 21.3.1997 / 10:18:31 / cg"
+!
+
+printFullStatisticOn:outStream
+    "output full statistics on outstream"
+
+    |runTime aTally err|
+
+    ntally == 0 ifTrue:[
+        self printNoProbesOn:outStream.
+        ^ self
+    ].
+
+    tree computePercentage:ntally.
+
+    runTime := endTime - startTime.
+
+    "/ aTally tree inspect.
+    outStream cr.
+    err := (1000 // ntally / 10.0).
+    err > 0 ifTrue:[
+        outStream nextPutLine:('total execution time: '
+                           , runTime printString , ' ms '
+                           , '(' , ntally printString , ' probes ;'
+                           , ' error >= ' 
+                           , (1000 // ntally / 10.0) printString
+                           , '%)'
+                          ).
+    ] ifFalse:[
+        outStream nextPutLine:('total execution time: '
+                           , runTime printString , ' ms '
+                           , '(' , ntally printString , ' probes)'
+                          ).
+    ].
+
+    outStream cr.
+    tree printOn:outStream.
+    outStream cr; cr.
+
+    outStream nextPutLine:'leafs of calling tree (by receiver & implementing method):'.
+    outStream cr.
+    tree printLeafsOn:outStream.
+    outStream cr; cr.
+
+    outStream nextPutLine:'method leafs of calling tree (by implementing method only):'.
+    outStream cr.
+    tree printMethodLeafsOn:outStream.
+    outStream cr; cr.
+
+    "Created: 22.3.1997 / 16:52:09 / cg"
+    "Modified: 22.3.1997 / 16:53:38 / cg"
+!
+
+printLeafStatisticOn:outStream
+    "output leaf statistics on outstream"
+
+    |runTime err|
+
+    ntally == 0 ifTrue:[
+        self printNoProbesOn:outStream.
+        ^ self.
+    ].
+
+    runTime := endTime - startTime.
+
+    probes do:[:aProbe |
+        aProbe computePercentage:ntally
+    ].
+
+    outStream cr.
+    err := (1000 // ntally / 10.0).
+    err > 0 ifTrue:[
+        outStream nextPutLine:('total execution time: '
+                           , runTime printString , ' ms '
+                           , '(' , ntally printString , ' probes ;'
+                           , ' error >= ' 
+                           , (1000 // ntally / 10.0) printString
+                           , '%)'
+                          ).
+    ] ifFalse:[
+        outStream nextPutLine:('total execution time: '
+                           , runTime printString , ' ms '
+                           , '(' , ntally printString , ' probes)'
+                          ).
+    ].
+
+    outStream nextPutLine:'method leafs of calling tree:'.
+    outStream cr.
+    self printFlatMethodLeafsOn:outStream.
+    outStream cr; cr.
+
+    "Created: 22.3.1997 / 16:50:06 / cg"
+    "Modified: 22.3.1997 / 16:53:15 / cg"
+!
+
+printNoProbesOn:outStream
+    "output a message that no probes are present"
+
+    outStream cr.
+    outStream nextPutLine:'TALLY: No probes - execution time too short;'.
+    outStream nextPutLine:'TALLY: retry using: spyOn:[n timesRepeat:[...]]'.
+
+    "Created: 22.3.1997 / 16:53:23 / cg"
 ! !
 
 !MessageTally methodsFor:'private'!
@@ -528,13 +571,14 @@
     ].
 
     "Modified: 20.3.1997 / 21:34:05 / cg"
-!
+! !
+
+!MessageTally methodsFor:'spy setup'!
 
 spyLeafOn:aBlock interval:ms
     "spy on execution time; generate information on leaf nodes only"
 
-    |startTime endTime probing
-     delay probingProcess probedProcess|
+    |probing delay probingProcess probedProcess|
 
     theBlock := aBlock.
 
@@ -570,25 +614,18 @@
         ] valueNowOrOnUnwindDo:[
             probing := executing := false.
             theBlock := nil.
+            endTime := OperatingSystem getMillisecondTime.
         ].
-
-        endTime := OperatingSystem getMillisecondTime.
-    ].    
-
-    probes do:[:aProbe |
-        aProbe computePercentage:ntally
     ].
-    ^ endTime - startTime
 
     "Created: 20.3.1997 / 20:15:07 / cg"
-    "Modified: 20.3.1997 / 21:45:11 / cg"
+    "Modified: 22.3.1997 / 16:46:42 / cg"
 !
 
 spyOn:aBlock interval:ms
     "spy on execution time, generate a hierarchical call information"
 
-    |startTime endTime probing
-     delay probingProcess probedProcess|
+    |probing delay probingProcess probedProcess|
 
     theBlock := aBlock.
 
@@ -629,20 +666,16 @@
         ] valueNowOrOnUnwindDo:[
             probing := executing := false.
             theBlock := nil.
+            endTime := OperatingSystem getMillisecondTime.
         ].
-
-        endTime := OperatingSystem getMillisecondTime.
-    ].    
-
-    ntally ~~ 0 ifTrue:[tree computePercentage:ntally].
-    ^ endTime - startTime
+    ].
 
     "Created: 20.3.1997 / 20:14:44 / cg"
-    "Modified: 20.3.1997 / 21:45:02 / cg"
+    "Modified: 22.3.1997 / 16:45:42 / cg"
 ! !
 
 !MessageTally class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic3/MessageTally.st,v 1.32 1997-03-22 15:31:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic3/MessageTally.st,v 1.33 1997-03-22 15:57:17 cg Exp $'
 ! !
--- a/MsgTally.st	Sat Mar 22 16:31:37 1997 +0100
+++ b/MsgTally.st	Sat Mar 22 16:57:17 1997 +0100
@@ -11,7 +11,8 @@
 "
 
 Object subclass:#MessageTally
-	instanceVariableNames:'tree probes ntally theBlock spyInterval executing spyOutStream'
+	instanceVariableNames:'tree probes ntally theBlock spyInterval executing startTime
+		endTime'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'System-Debugging-Support'
@@ -162,122 +163,44 @@
 
 !MessageTally class methodsFor:'spying - private'!
 
-noProbesTo:outStream
-    outStream cr.
-    outStream nextPutLine:'TALLY: No probes - execution time too short;'.
-    outStream nextPutLine:'TALLY: retry using: spyOn:[n timesRepeat:[...]]'.
-
-    "Created: 22.3.1997 / 16:24:25 / cg"
-!
-
 spyLeafOn:aBlock interval:ms to:outStream
     "evaluate aBlock and output leaf method statistics on outStream"
 
-    |runTime aTally nTally err|
+    |aTally|
 
     aTally := self new.
-    runTime := aTally spyLeafOn:aBlock interval:ms.
 
-    nTally := aTally nTally.
-    nTally == 0 ifTrue:[
-        self noProbesTo:outStream.
-        ^ self.
+    [
+        [
+            aTally spyLeafOn:aBlock interval:ms.
+        ] valueOnUnwindDo:[
+            outStream nextPutLine:'TALLY: block returned'.
+        ]
+    ] valueNowOrOnUnwindDo:[
+        aTally printLeafStatisticOn:outStream
     ].
 
-    "/ aTally probes inspect.
-
-    outStream cr.
-    err := (1000 // nTally / 10.0).
-    err > 0 ifTrue:[
-        outStream nextPutLine:('total execution time: '
-                           , runTime printString , ' ms '
-                           , '(' , nTally printString , ' probes ;'
-                           , ' error >= ' 
-                           , (1000 // nTally / 10.0) printString
-                           , '%)'
-                          ).
-    ] ifFalse:[
-        outStream nextPutLine:('total execution time: '
-                           , runTime printString , ' ms '
-                           , '(' , nTally printString , ' probes)'
-                          ).
-    ].
-
-    outStream nextPutLine:'method leafs of calling tree:'.
-    outStream cr.
-    aTally printFlatMethodLeafsOn:outStream.
-    outStream cr; cr.
-
-    "Modified: 20.3.1997 / 21:01:29 / cg"
-    "Created: 22.3.1997 / 16:24:09 / cg"
+    "Modified: 22.3.1997 / 16:50:47 / cg"
 !
 
 spyOn:aBlock interval:ms to:outStream
     "evaluate aBlock and output full statistics on outstream"
 
-    |runTime aTally nTally err tree|
+    |aTally|
 
     aTally := self new.
-    runTime := aTally spyOn:aBlock interval:ms.
 
-    aTally nTally == 0 ifTrue:[
-        self noProbesTo:outStream.
-        ^ self
-    ].
-
-    "/ aTally tree inspect.
-    nTally := aTally nTally.
-    outStream cr.
-    err := (1000 // nTally / 10.0).
-    err > 0 ifTrue:[
-        outStream nextPutLine:('total execution time: '
-                           , runTime printString , ' ms '
-                           , '(' , nTally printString , ' probes ;'
-                           , ' error >= ' 
-                           , (1000 // nTally / 10.0) printString
-                           , '%)'
-                          ).
-    ] ifFalse:[
-        outStream nextPutLine:('total execution time: '
-                           , runTime printString , ' ms '
-                           , '(' , nTally printString , ' probes)'
-                          ).
+    [
+        [
+            aTally spyOn:aBlock interval:ms.
+        ] valueOnUnwindDo:[
+            outStream nextPutLine:'TALLY: block returned'.
+        ]
+    ] valueNowOrOnUnwindDo:[
+        aTally printFullStatisticOn:outStream
     ].
 
-    tree := aTally tree.
-
-    outStream cr.
-    tree printOn:outStream.
-    outStream cr; cr.
-
-    outStream nextPutLine:'leafs of calling tree (by receiver & implementing method):'.
-    outStream cr.
-    tree printLeafsOn:outStream.
-    outStream cr; cr.
-
-    outStream nextPutLine:'method leafs of calling tree (by implementing method only):'.
-    outStream cr.
-    tree printMethodLeafsOn:outStream.
-    outStream cr; cr.
-
-    "
-    aTally statistics.
-    "
-
-    "
-     MessageTally spyOn:[ #(6 5 4 3 2 1) sort ]
-     MessageTally spyOn:[100 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-     MessageTally spyOn:[1000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-     MessageTally spyOn:[10000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-     MessageTally spyOn:[100000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-     MessageTally spyOn:[500000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-     MessageTally spyOn:[SystemBrowser open ]
-     MessageTally spyDetailedOn:[SystemBrowser open ]
-     Time millisecondsToRun:[500000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
-    "
-
-    "Modified: 20.3.1997 / 21:00:57 / cg"
-    "Created: 22.3.1997 / 16:25:59 / cg"
+    "Modified: 22.3.1997 / 16:54:36 / cg"
 ! !
 
 !MessageTally class methodsFor:'spying - public interface'!
@@ -324,6 +247,15 @@
 
 !MessageTally methodsFor:'accessing'!
 
+endTime
+    "return the endTime of the run"
+
+    ^ endTime
+
+    "Modified: 18.5.1996 / 18:47:47 / cg"
+    "Created: 22.3.1997 / 16:44:29 / cg"
+!
+
 nTally 
     "return the number of accumulated probes"
 
@@ -341,6 +273,15 @@
     "Created: 20.3.1997 / 20:54:19 / cg"
 !
 
+startTime
+    "return the startTime of the run"
+
+    ^ startTime
+
+    "Modified: 18.5.1996 / 18:47:47 / cg"
+    "Created: 22.3.1997 / 16:44:33 / cg"
+!
+
 tree
     "return the accumulated calling tree"
 
@@ -369,6 +310,108 @@
 
     "Created: 20.3.1997 / 20:56:13 / cg"
     "Modified: 21.3.1997 / 10:18:31 / cg"
+!
+
+printFullStatisticOn:outStream
+    "output full statistics on outstream"
+
+    |runTime aTally err|
+
+    ntally == 0 ifTrue:[
+        self printNoProbesOn:outStream.
+        ^ self
+    ].
+
+    tree computePercentage:ntally.
+
+    runTime := endTime - startTime.
+
+    "/ aTally tree inspect.
+    outStream cr.
+    err := (1000 // ntally / 10.0).
+    err > 0 ifTrue:[
+        outStream nextPutLine:('total execution time: '
+                           , runTime printString , ' ms '
+                           , '(' , ntally printString , ' probes ;'
+                           , ' error >= ' 
+                           , (1000 // ntally / 10.0) printString
+                           , '%)'
+                          ).
+    ] ifFalse:[
+        outStream nextPutLine:('total execution time: '
+                           , runTime printString , ' ms '
+                           , '(' , ntally printString , ' probes)'
+                          ).
+    ].
+
+    outStream cr.
+    tree printOn:outStream.
+    outStream cr; cr.
+
+    outStream nextPutLine:'leafs of calling tree (by receiver & implementing method):'.
+    outStream cr.
+    tree printLeafsOn:outStream.
+    outStream cr; cr.
+
+    outStream nextPutLine:'method leafs of calling tree (by implementing method only):'.
+    outStream cr.
+    tree printMethodLeafsOn:outStream.
+    outStream cr; cr.
+
+    "Created: 22.3.1997 / 16:52:09 / cg"
+    "Modified: 22.3.1997 / 16:53:38 / cg"
+!
+
+printLeafStatisticOn:outStream
+    "output leaf statistics on outstream"
+
+    |runTime err|
+
+    ntally == 0 ifTrue:[
+        self printNoProbesOn:outStream.
+        ^ self.
+    ].
+
+    runTime := endTime - startTime.
+
+    probes do:[:aProbe |
+        aProbe computePercentage:ntally
+    ].
+
+    outStream cr.
+    err := (1000 // ntally / 10.0).
+    err > 0 ifTrue:[
+        outStream nextPutLine:('total execution time: '
+                           , runTime printString , ' ms '
+                           , '(' , ntally printString , ' probes ;'
+                           , ' error >= ' 
+                           , (1000 // ntally / 10.0) printString
+                           , '%)'
+                          ).
+    ] ifFalse:[
+        outStream nextPutLine:('total execution time: '
+                           , runTime printString , ' ms '
+                           , '(' , ntally printString , ' probes)'
+                          ).
+    ].
+
+    outStream nextPutLine:'method leafs of calling tree:'.
+    outStream cr.
+    self printFlatMethodLeafsOn:outStream.
+    outStream cr; cr.
+
+    "Created: 22.3.1997 / 16:50:06 / cg"
+    "Modified: 22.3.1997 / 16:53:15 / cg"
+!
+
+printNoProbesOn:outStream
+    "output a message that no probes are present"
+
+    outStream cr.
+    outStream nextPutLine:'TALLY: No probes - execution time too short;'.
+    outStream nextPutLine:'TALLY: retry using: spyOn:[n timesRepeat:[...]]'.
+
+    "Created: 22.3.1997 / 16:53:23 / cg"
 ! !
 
 !MessageTally methodsFor:'private'!
@@ -528,13 +571,14 @@
     ].
 
     "Modified: 20.3.1997 / 21:34:05 / cg"
-!
+! !
+
+!MessageTally methodsFor:'spy setup'!
 
 spyLeafOn:aBlock interval:ms
     "spy on execution time; generate information on leaf nodes only"
 
-    |startTime endTime probing
-     delay probingProcess probedProcess|
+    |probing delay probingProcess probedProcess|
 
     theBlock := aBlock.
 
@@ -570,25 +614,18 @@
         ] valueNowOrOnUnwindDo:[
             probing := executing := false.
             theBlock := nil.
+            endTime := OperatingSystem getMillisecondTime.
         ].
-
-        endTime := OperatingSystem getMillisecondTime.
-    ].    
-
-    probes do:[:aProbe |
-        aProbe computePercentage:ntally
     ].
-    ^ endTime - startTime
 
     "Created: 20.3.1997 / 20:15:07 / cg"
-    "Modified: 20.3.1997 / 21:45:11 / cg"
+    "Modified: 22.3.1997 / 16:46:42 / cg"
 !
 
 spyOn:aBlock interval:ms
     "spy on execution time, generate a hierarchical call information"
 
-    |startTime endTime probing
-     delay probingProcess probedProcess|
+    |probing delay probingProcess probedProcess|
 
     theBlock := aBlock.
 
@@ -629,20 +666,16 @@
         ] valueNowOrOnUnwindDo:[
             probing := executing := false.
             theBlock := nil.
+            endTime := OperatingSystem getMillisecondTime.
         ].
-
-        endTime := OperatingSystem getMillisecondTime.
-    ].    
-
-    ntally ~~ 0 ifTrue:[tree computePercentage:ntally].
-    ^ endTime - startTime
+    ].
 
     "Created: 20.3.1997 / 20:14:44 / cg"
-    "Modified: 20.3.1997 / 21:45:02 / cg"
+    "Modified: 22.3.1997 / 16:45:42 / cg"
 ! !
 
 !MessageTally class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic3/Attic/MsgTally.st,v 1.32 1997-03-22 15:31:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic3/Attic/MsgTally.st,v 1.33 1997-03-22 15:57:17 cg Exp $'
 ! !