Tools__Profiler.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 16 Mar 2012 17:08:17 +0000
branchjv
changeset 12179 47f98e7d6de1
parent 12128 a7ff7d66ee85
child 12308 5d9291c0fc27
permissions -rw-r--r--
Improvments towards merge tool

"
 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 7854 2012-01-30 17:49:41Z vranyj1 $'
! !