Tools__Profiler.st
branchjv
changeset 12308 5d9291c0fc27
parent 12128 a7ff7d66ee85
child 12401 4714b9640528
--- a/Tools__Profiler.st	Fri Nov 30 14:25:59 2012 +0000
+++ b/Tools__Profiler.st	Fri Nov 30 17:23:39 2012 +0000
@@ -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,29 @@
 "
 !
 
-example1
+documentation
+"
+    a visual profiler;
+    provides the same interface as a MessageTally, but does not show the
+    sample data on a stream, instead a browser is opened, allowing easy
+    navigation through the sampled code.
+"
+!
 
+examples
+"
+                                                                    [exBegin]
     | 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 +98,48 @@
     "Created: / 24-11-2007 / 09:24:12 / janfrog"
 ! !
 
+!Profiler class methodsFor:'messageTally compatible interface'!
+
+spyDetailedOn: 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 +149,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 +204,10 @@
     "Created: / 24-11-2007 / 09:24:50 / janfrog"
 !
 
+retVal
+    ^ retVal
+!
+
 startTimestamp
     ^ startTimestamp
 
@@ -158,22 +216,25 @@
 
 !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"
 ! !
 
 !Profiler class methodsFor:'documentation'!
 
+version
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__Profiler.st,v 1.5 2012/11/04 21:42:25 cg Exp $'
+!
+
 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.5 2012/11/04 21:42:25 cg Exp §'
 !
 
 version_SVN
-    ^ '$Id: Tools__Profiler.st 7854 2012-01-30 17:49:41Z vranyj1 $'
+    ^ '$Id: Tools__Profiler.st 8074 2012-11-30 17:23:39Z vranyj1 $'
 ! !
\ No newline at end of file