Tools__Profiler.st
author Claus Gittinger <cg@exept.de>
Fri, 01 Jul 2011 15:27:21 +0200
changeset 9991 5d0495aa2e5e
child 10060 cb3aa9c7ad8f
permissions -rw-r--r--
initial checkin

"
 COPYRIGHT (c) 2006 by eXept Software AG
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ 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) 2006 by eXept Software AG
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

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.1 2011-07-01 13:27:21 cg Exp $'
!

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