Tools__Profiler.st
author vrany
Sat, 09 Jul 2011 15:53:19 +0200
changeset 10300 5ed6f3d35cbb
parent 10060 cb3aa9c7ad8f
child 12023 db541e9a6fc1
child 12123 4bde08cebd48
permissions -rw-r--r--
changed: #enterActionFor: fix for UNIX symlinks

"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
"{ Package: 'stx:libtool' }"

"{ NameSpace: Tools }"

MessageTally subclass:#Profiler
	instanceVariableNames:'startTimestamp notes'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Browsers-New-Profiler'
!

!Profiler class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
!

example1

    | profiler |
    profiler := Tools::Profiler spyOn:[1 to: 1000 do:[:i|i factorial]] interval: 10.
    Tools::NewSystemBrowser browseProfilerStatistics: profiler

    "
        Profiler example1
    "
! !

!Profiler class methodsFor:'instance creation'!

readStatisticsFrom: stream

    ^BinaryInputManager readFrom: stream

    "Created: / 24-11-2007 / 09:24:12 / janfrog"
! !

!Profiler class methodsFor:'profiling'!

profile: aBlock

    ^self spyOn: aBlock

    "Created: / 18-02-2008 / 20:24:08 / janfrog"
!

profileAndOpenBrowser: aBlock

    Tools::NewSystemBrowser browseProfilerStatistics: 
                (self profile: aBlock)

    "
        Tools::Profiler profileAndOpenBrowser:[ 10000 timesRepeat:[100 factorial] ] 
    "

    "Created: / 18-02-2008 / 20:24:56 / janfrog"
    "Modified: / 18-02-2008 / 22:16:29 / janfrog"
!

spyOn: aBlock

    ^self spyOn: aBlock interval: 1

    "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

    ^self new spyOn: aBlock interval: interval

    "Created: / 24-11-2007 / 08:25:37 / janfrog"
! !

!Profiler methodsFor:'I/O'!

storeStatisticsOn: stream

    ^BinaryOutputManager store: self on: stream

    "Created: / 24-11-2007 / 09:23:11 / janfrog"
! !

!Profiler methodsFor:'accessing'!

computationTime
    ^ endTime - startTime

    "Created: / 24-11-2007 / 08:41:33 / janfrog"
!

notes
    ^ notes

    "Created: / 24-11-2007 / 09:24:50 / janfrog"
!

notes:something
    notes := something.

    "Created: / 24-11-2007 / 09:24:50 / janfrog"
!

startTimestamp
    ^ startTimestamp

    "Created: / 24-11-2007 / 09:01:12 / janfrog"
! !

!Profiler methodsFor:'profiling'!

spyOn: aBlock interval: interval

    startTimestamp := Timestamp now.
    super spyOn: aBlock interval: interval.
    self nTally isZero ifFalse:[self tree computePercentage: self nTally].
    ^self

    "Created: / 24-11-2007 / 08:21:28 / janfrog"
! !

!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 $'
!

version_SVN
    ^ '§Id: Tools__Profiler.st 7486 2009-10-26 22:06:24Z vranyj1 §'
! !