Tools__Profiler.st
changeset 12023 db541e9a6fc1
parent 10060 cb3aa9c7ad8f
child 12024 d9abe8cde031
--- a/Tools__Profiler.st	Sun Nov 04 15:02:58 2012 +0100
+++ b/Tools__Profiler.st	Sun Nov 04 22:14:49 2012 +0100
@@ -28,7 +28,7 @@
 "{ NameSpace: Tools }"
 
 MessageTally subclass:#Profiler
-	instanceVariableNames:'startTimestamp notes'
+	instanceVariableNames:'startTimestamp notes retVal'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-Browsers-New-Profiler'
@@ -64,15 +64,20 @@
 "
 !
 
-example1
+examples
+"
+                                                                    [exBegin]
+    | profiler |
 
-    | profiler |
-    profiler := Tools::Profiler spyOn:[1 to: 1000 do:[:i|i factorial]] interval: 10.
+    profiler := Tools::Profiler profileOn:[1 to: 1000 do:[:i|i factorial]] interval: 10.
     Tools::NewSystemBrowser browseProfilerStatistics: profiler
+                                                                    [exEnd]
 
-    "
-        Profiler example1
-    "
+                                                                    [exBegin]
+    Tools::Profiler spyOn:[1 to: 1000 do:[:i|i factorial]] interval: 10.
+                                                                    [exEnd]
+
+"
 ! !
 
 !Profiler class methodsFor:'instance creation'!
@@ -84,19 +89,48 @@
     "Created: / 24-11-2007 / 09:24:12 / janfrog"
 ! !
 
+!Profiler class methodsFor:'messageTally compatible interface'!
+
+spyDetailOn: aBlock
+    "execute a Block; then open a visual profiler.
+     Return the value from aBlock"
+
+    ^ self spyOn:aBlock interval:(self detailedSamplingIntervalMS)
+!
+
+spyOn: aBlock
+    "execute a Block; then open a visual profiler.
+     Return the value from aBlock"
+
+    ^ self spyOn:aBlock interval:(self normalSamplingIntervalMS)
+!
+
+spyOn: aBlock interval: interval
+    "execute a Block; then open a visual profiler.
+     Return the value from aBlock"
+
+    | profiler |
+
+    profiler := self new.
+    profiler profileOn:aBlock interval: interval.
+    Tools::NewSystemBrowser browseProfilerStatistics: profiler.
+    ^ profiler retVal
+! !
+
 !Profiler class methodsFor:'profiling'!
 
 profile: aBlock
+    "run aBlock, return profile information"
 
-    ^self spyOn: aBlock
+    ^self profileOn: aBlock
 
     "Created: / 18-02-2008 / 20:24:08 / janfrog"
 !
 
 profileAndOpenBrowser: aBlock
+    "run aBlock, open a browser on the profile information; sample tick is 10ms"
 
-    Tools::NewSystemBrowser browseProfilerStatistics: 
-                (self profile: aBlock)
+    Tools::NewSystemBrowser browseProfilerStatistics: (self profile: aBlock)
 
     "
         Tools::Profiler profileAndOpenBrowser:[ 10000 timesRepeat:[100 factorial] ] 
@@ -106,17 +140,28 @@
     "Modified: / 18-02-2008 / 22:16:29 / janfrog"
 !
 
-spyOn: aBlock
+profileDetailedOn: aBlock
+    "run aBlock, return profile information; sample tick is 1ms"
 
-    ^self spyOn: aBlock interval: 1
+    ^self profileOn: aBlock interval:(self detailedSamplingIntervalMS)
 
     "Created: / 24-11-2007 / 08:31:22 / janfrog"
     "Modified: / 25-12-2008 / 20:39:33 / Jan Vrany <vranyj1@fel.cvut.cz>"
 !
 
-spyOn: aBlock interval: interval
+profileOn: aBlock
+    "run aBlock, return profile information; sample tick is 10ms"
+
+    ^self profileOn: aBlock interval:(self normalSamplingIntervalMS)
 
-    ^self new spyOn: aBlock interval: interval
+    "Created: / 24-11-2007 / 08:31:22 / janfrog"
+    "Modified: / 25-12-2008 / 20:39:33 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+profileOn: aBlock interval: interval
+    "run aBlock, return profile information; sample tick is interval (ms)"
+
+    ^self new profileOn: aBlock interval: interval
 
     "Created: / 24-11-2007 / 08:25:37 / janfrog"
 ! !
@@ -150,6 +195,10 @@
     "Created: / 24-11-2007 / 09:24:50 / janfrog"
 !
 
+retVal
+    ^ retVal
+!
+
 startTimestamp
     ^ startTimestamp
 
@@ -158,12 +207,11 @@
 
 !Profiler methodsFor:'profiling'!
 
-spyOn: aBlock interval: interval
-
+profileOn: aBlock interval: interval
     startTimestamp := Timestamp now.
-    super spyOn: aBlock interval: interval.
+    retVal := super spyOn: aBlock interval: interval.
     self nTally isZero ifFalse:[self tree computePercentage: self nTally].
-    ^self
+    ^ self
 
     "Created: / 24-11-2007 / 08:21:28 / janfrog"
 ! !
@@ -171,7 +219,7 @@
 !Profiler class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__Profiler.st,v 1.2 2011-07-03 17:46:43 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__Profiler.st,v 1.3 2012-11-04 21:14:49 cg Exp $'
 !
 
 version_SVN