Morphic slowness (was Re: Does *anyone* use MVC?)

Bob Arning arning at charm.net
Fri Aug 2 00:00:12 UTC 2002


On Fri, 02 Aug 2002 01:17:35 +0200 (CEST) =?ISO-8859-1?Q?G=F6ran_Hultgren?= <goran.hultgren at bluefish.se> wrote:
>Yes, ok, I saw that - but that is not really what I want. I would like to do this:
>
>Smalltalk at: #MyTallyer put: MessageTally new.
>10 timesRepeat: [
> <some code I don't want to tally>
> MyTallyer spy: [ <some code> ].
> <some code I don't want to tally>
> MyTallyer spy: [ <some other code> ].
>].
>MyTallyer openUpInSomeFancyToolWhatever...
>
>:-) 
>
>Then we could select the pieces we want and the pieces we don't want even! We
>could of course use "MyTallyer pause" and "MyTallyer resume" too.

OK, then, do it. If you look at: 

spyOn: aBlock    "MessageTally spyOn: [100 timesRepeat: [3.14159 printString]]"
	| node result |
	node _ self new.
	result _ node spyEvery: 16 on: aBlock.
	(StringHolder new contents: (String streamContents: [:s | node report: s; close]))
		openLabel: 'Spy Results'.
	^ result

it would certainly seem that you could break this up into

| myTally |
myTally _ MessageTally new.
10 timesRepeat: [
	(String new: 10000) reversed.
	myTally spyEveryRepeating: 16 on: [ [(String new: 1000000) asLowercase.] value ].
	(String new: 10000) reversed.
	myTally spyEveryRepeating: 16 on: [ [(String new: 10000) shuffled.] value ].
].
(StringHolder new contents: (String streamContents: [:s | myTally report: s; close]))
	openLabel: 'Spy Results'.

The only change to the system is a spy method that does not reinitialize the tally every time it is called (see below).

Cheers,
Bob
=========

!MessageTally methodsFor: 'initialize-release' stamp: 'RAA 8/1/2002 19:54'!
spyEveryRepeating: millisecs on: aBlock 
	"Create a spy and spy on the given block at the specified rate."

	| myDelay value startTime time0 |

	tally ifNil: [
		tally _ 0.
		receivers _ Array new: 0
	].
	(aBlock isMemberOf: BlockContext)
		ifFalse: [self error: 'spy needs a block here'].
	class _ aBlock receiver class.
	method _ aBlock method.
		"set up the probe"
	ObservedProcess _ Processor activeProcess.
	myDelay := Delay forMilliseconds: millisecs.
	time0 := Time millisecondClockValue.
	gcStats _ Smalltalk getVMParameters.
	Timer :=
		[[true] whileTrue: 
			[startTime := Time millisecondClockValue.
			myDelay wait.
			self tally: ObservedProcess suspendedContext
				"tally can be > 1 if ran a long primitive"
				by: (Time millisecondClockValue - startTime) // millisecs].
		nil] newProcess.
	Timer priority: Processor userInterruptPriority.
		"activate the probe and evaluate the block"
	Timer resume.
	value := aBlock value.
	"Collect gc statistics"
	Smalltalk getVMParameters keysAndValuesDo:
		[:idx :gcVal| gcStats at: idx put: (gcVal - gcStats at: idx)].
		"cancel the probe and return the value"
	Timer terminate.
	time := Time millisecondClockValue - time0.
	^value! !
=====



More information about the Squeak-dev mailing list