--- a/MessageTracer.st Mon Mar 05 11:26:12 2007 +0100
+++ b/MessageTracer.st Mon Mar 05 16:21:17 2007 +0100
@@ -9,7 +9,6 @@
other person. No title to or ownership of the software is
hereby transferred.
"
-
"{ Package: 'stx:libbasic3' }"
Object subclass:#MessageTracer
@@ -29,6 +28,13 @@
privateIn:MessageTracer
!
+Object subclass:#MethodTimingInfo
+ instanceVariableNames:'count minTime maxTime sumTimes avgTime'
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:MessageTracer
+!
+
MessageTracer subclass:#PrintingMessageTracer
instanceVariableNames:''
classVariableNames:''
@@ -990,54 +996,19 @@
executionTimesOfMethod:aMethod
"return the current gathered execution time statistics"
- |count info minT maxT avg ret|
-
- count := 0.
- minT := maxT := avg := nil.
+ |info|
+
MethodTiming notNil ifTrue:[
aMethod isWrapped ifTrue:[
- info := MethodTiming at:aMethod originalMethod ifAbsent:nil.
- info notNil ifTrue:[
- count := info at:1.
- count ~~ 0 ifTrue:[
- minT := info at:2.
- maxT := info at:3.
- avg := (info at:4) / count
- ]
- ].
+ info := ( MethodTiming at:(aMethod originalMethod) ifAbsent:nil ) copy.
].
].
- minT notNil ifTrue:[
- minT > 10 ifTrue:[
- minT := minT roundTo:0.1
- ] ifFalse:[
- minT := minT roundTo:0.01
- ]
- ].
- maxT notNil ifTrue:[
- maxT > 10 ifTrue:[
- maxT := maxT roundTo:0.1
- ] ifFalse:[
- maxT := maxT roundTo:0.01
- ].
- ].
- avg notNil ifTrue:[
- avg > 10 ifTrue:[
- avg := avg roundTo:0.1
- ] ifFalse:[
- avg := avg roundTo:0.01
- ].
- ].
- ret := IdentityDictionary new.
- ret at:#count put:count.
- ret at:#minTime put:minT.
- ret at:#maxTime put:maxT.
- ret at:#avgTime put:avg.
- ^ ret
-
- "Created: / 17.6.1996 / 17:07:30 / cg"
- "Modified: / 30.7.1998 / 18:20:45 / cg"
+ info isNil ifTrue:[ info := MethodTimingInfo new ].
+ ^ info
+
+ "Created: / 17-06-1996 / 17:07:30 / cg"
+ "Modified: / 05-03-2007 / 15:46:17 / cg"
!
resetExecutionTimesOfMethod:aMethod
@@ -1045,16 +1016,14 @@
the method remains wrapped."
MethodTiming notNil ifTrue:[
+ MethodTiming removeKey:aMethod.
aMethod isWrapped ifTrue:[
- MethodTiming at:aMethod put:(Array with:0
- with:0
- with:0
- with:0).
+ MethodTiming removeKey:aMethod originalMethod.
].
].
- "Created: / 30.7.1998 / 17:12:35 / cg"
- "Modified: / 31.7.1998 / 00:42:50 / cg"
+ "Created: / 30-07-1998 / 17:12:35 / cg"
+ "Modified: / 05-03-2007 / 15:36:59 / cg"
!
stopTimingMethod:aMethod
@@ -1076,10 +1045,6 @@
MethodTiming := IdentityDictionary new.
].
MethodTiming removeKey:aMethod ifAbsent:nil.
- MethodTiming at:aMethod put:(Array with:0
- with:0
- with:0
- with:0).
TimeForWrappers isNil ifTrue:[
self getTimeForWrappers
@@ -1099,30 +1064,9 @@
info := MethodTiming at:aMethod ifAbsent:nil.
info isNil ifTrue:[
- MethodTiming at:aMethod put:(Array with:1
- with:t
- with:t
- with:t)
+ MethodTiming at:aMethod put:(info := MethodTimingInfo new)
] ifFalse:[
- cnt := info at:1.
- sumTimes := info at:4.
-
- cnt == 0 ifTrue:[
- info at:2 put:t.
- info at:3 put:t.
- ] ifFalse:[
- minT := info at:2.
- maxT := info at:3.
- t < minT ifTrue:[
- info at:2 put:t.
- ] ifFalse:[
- t > maxT ifTrue:[
- info at:3 put:t.
- ]
- ].
- ].
- info at:4 put:(sumTimes + t).
- info at:1 put:cnt + 1
+ info rememberExecutionTime:t.
].
aMethod changed:#statistics
]
@@ -1136,8 +1080,8 @@
MessageTracer stopTimingMethod:(Integer compiledMethodAt:#factorial)
"
- "Created: / 17.6.1996 / 17:03:50 / cg"
- "Modified: / 30.7.1998 / 17:13:11 / cg"
+ "Created: / 17-06-1996 / 17:03:50 / cg"
+ "Modified: / 05-03-2007 / 15:34:01 / cg"
! !
!MessageTracer class methodsFor:'method tracing'!
@@ -1461,25 +1405,25 @@
|selector class originalMethod dict mthd|
-"/ Transcript showCR:'unwrapping a Method...'.
+ originalMethod := aMethod originalMethod.
MethodCounts notNil ifTrue:[
aMethod isWrapped ifTrue:[
- MethodCounts removeKey:aMethod originalMethod ifAbsent:nil.
+ MethodCounts removeKey:originalMethod ifAbsent:nil.
].
MethodCounts removeKey:aMethod ifAbsent:nil.
MethodCounts isEmpty ifTrue:[MethodCounts := nil].
].
MethodMemoryUsage notNil ifTrue:[
aMethod isWrapped ifTrue:[
- MethodMemoryUsage removeKey:aMethod originalMethod ifAbsent:nil.
+ MethodMemoryUsage removeKey:originalMethod ifAbsent:nil.
].
MethodMemoryUsage removeKey:aMethod ifAbsent:nil.
MethodMemoryUsage isEmpty ifTrue:[MethodMemoryUsage := nil].
].
MethodTiming notNil ifTrue:[
aMethod isWrapped ifTrue:[
- MethodTiming removeKey:aMethod originalMethod ifAbsent:nil.
+ MethodTiming removeKey:originalMethod ifAbsent:nil.
].
MethodTiming removeKey:aMethod ifAbsent:nil.
MethodTiming isEmpty ifTrue:[MethodTiming := nil].
@@ -1501,7 +1445,6 @@
].
selector := class selectorAtMethod:aMethod.
- originalMethod := aMethod originalMethod.
originalMethod isNil ifTrue:[
self error:'oops, could not find original method' mayProceed:true.
^ aMethod
@@ -1526,8 +1469,8 @@
^ originalMethod
- "Modified: 5.6.1996 / 14:08:08 / stefan"
- "Modified: 24.4.1997 / 18:20:49 / cg"
+ "Modified: / 05-06-1996 / 14:08:08 / stefan"
+ "Modified: / 05-03-2007 / 15:35:25 / cg"
!
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock
@@ -2798,13 +2741,13 @@
times := self executionTimesOfMethod:m.
self stopTimingMethod:m.
- ^ (TimeForWrappers := times at:#avgTime)
+ ^ (TimeForWrappers := times avgTime)
"
self getTimeForWrappers
"
- "Modified: / 30.7.1998 / 17:10:07 / cg"
+ "Modified: / 05-03-2007 / 15:44:24 / cg"
!
printEntryFull:aContext
@@ -3070,6 +3013,91 @@
InterruptPending := 1.
! !
+!MessageTracer::MethodTimingInfo methodsFor:'accessing'!
+
+avgTime
+ sumTimes notNil ifTrue:[
+ ^ sumTimes / count
+ ].
+ ^ nil
+
+ "Created: / 05-03-2007 / 15:38:43 / cg"
+!
+
+avgTimeRounded
+ |avg|
+
+ avg := self avgTime.
+ avg > 100 ifTrue:[ ^ avg roundTo:1 ].
+ avg > 10 ifTrue:[ ^ avg roundTo:0.1 ].
+ avg > 1 ifTrue:[ ^ avg roundTo:0.01 ].
+ ^ avg roundTo:0.001
+
+ "Created: / 05-03-2007 / 15:47:02 / cg"
+!
+
+count
+ ^ count
+!
+
+count:countArg minTime:minTimeArg maxTime:maxTimeArg sumTimes:sumTimesArg
+ count := countArg.
+ minTime := minTimeArg.
+ maxTime := maxTimeArg.
+ sumTimes := sumTimesArg.
+!
+
+maxTime
+ ^ maxTime
+!
+
+maxTimeRounded
+ |max|
+
+ max := self maxTime.
+ ^ max roundTo:(max > 10 ifTrue:0.1 ifFalse:0.01)
+
+ "Created: / 05-03-2007 / 15:47:22 / cg"
+!
+
+minTime
+ ^ minTime
+!
+
+minTimeRounded
+ |min|
+
+ min := self minTime.
+ ^ min roundTo:(min > 10 ifTrue:0.1 ifFalse:0.01)
+
+ "Created: / 05-03-2007 / 15:47:16 / cg"
+!
+
+sumTimes
+ ^ sumTimes
+! !
+
+!MessageTracer::MethodTimingInfo methodsFor:'initialization'!
+
+rememberExecutionTime:t
+ (count isNil or:[count == 0]) ifTrue:[
+ minTime := maxTime := sumTimes := t.
+ count := 1.
+ ] ifFalse:[
+ t < minTime ifTrue:[
+ minTime := t.
+ ] ifFalse:[
+ t > maxTime ifTrue:[
+ maxTime := t.
+ ]
+ ].
+ sumTimes := (sumTimes + t).
+ count := count + 1
+ ].
+
+ "Created: / 05-03-2007 / 15:32:43 / cg"
+! !
+
!MessageTracer::PrintingMessageTracer methodsFor:'trace helpers'!
stepInterrupt
@@ -3150,7 +3178,7 @@
!MessageTracer class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic3/MessageTracer.st,v 1.104 2006-04-07 07:28:35 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic3/MessageTracer.st,v 1.105 2007-03-05 15:21:17 cg Exp $'
! !
MessageTracer initialize!