[Goodie] Squeak system load display

Bert Freudenberg bert at isgnw.CS.Uni-Magdeburg.De
Wed Mar 15 11:30:42 UTC 2000

On Tue, 14 Mar 2000, Lex Spoon wrote:

> It will detect high-priority work as you say, because the high-priority
> work will cause the delays to get shorter.  However, suppose you are RSA
> cracking in a *low-priority* thread.  Then, Morphic will have
> delays between its cycles, but CPU usage will actually be 100%.

Oh my - yes, you're right. Could we measure the idle time in the idle
process? If relinquishProcessor would return the time actually spent this
could work. But currently I see no way. The millisecond clock is just too
inaccurate for this. It would be nice if the VM would collect CPU times
for each process ...

Anyway, I attached an update that makes the LoadMorph display full UI load
correctly (this was ignored before because no events were generated) and
some other enhancements. File this in after the original CS:

"Change Set:		sqload2-bf
Date:			14 March 2000
Author:			Bert Freudenberg
Requires:		sqload-bf

This is an enhancement for my LoadMorph. Added background color, full load
detection, and current load display if narrow."

I still think this looks nice ;-)

-------------- next part --------------
'From Squeak2.8alpha of 18 January 2000 [latest update: #1919] on 15 March 2000 at 12:13:38 pm'!
"Change Set:		sqload2-bf
Date:			14 March 2000
Author:			Bert Freudenberg
Requires:		sqload-bf

This is an enhancement for my LoadMorph. Added background color, full load detection, and current load display if narrow."!

Morph subclass: #LoadMorph
	instanceVariableNames: 'background '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Demo'!

!LoadMorph commentStamp: 'bf 3/15/2000 11:55' prior: 0!
LoadMorph displays a history of Squeak's system load.

(Actually, this only displays the UI process's load, not Squeak's background activities.)

Load measurement is based on the idle time in the World's interCyclePause. The displayed average load is collected in the World's #loadHistoryLong property. Load calculation can be disabled by removing the World's #loadHistory property (which is where the short-term history is collected):
	World removeProperty: #loadHistory.		"To stop it"
	World removeProperty: #loadHistoryLong.	"To save space"

Note that you can also enable an immediate load meter without this morph:
	World setProperty: #loadHistory toValue: OrderedCollection new.
	World setProperty: #loadDisplay toValue: true.
	World removeProperty: #loadDisplay.	 "To disable"

!LoadMorph methodsFor: 'initialization' stamp: 'bf 3/15/2000 11:09'!
	super initialize.
	color _ Color red.
	background _ Color green.
	self extent: 120 at 40.
! !

!LoadMorph methodsFor: 'drawing' stamp: 'bf 3/15/2000 11:28'!
areasRemainingToFill: aRectangle
	(background isColor and: [background isTranslucent])
		ifTrue: [^ Array with: aRectangle].
	^ aRectangle areasOutside: bounds! !

!LoadMorph methodsFor: 'drawing' stamp: 'bf 3/15/2000 11:08'!
drawOn: aCanvas
	| data r l h rawData |
	"Draw background"
	background ifNotNil: 
		[aCanvas fillRectangle: bounds color: background.
		0.25 to: 0.75 by: 0.25 do: [:y | 
			aCanvas line: bounds left @ (y * bounds height + bounds top)
				to: bounds right - 1 @ (y * bounds height + bounds top)
				color: background darker]]. 
	"Get data"
	rawData _ self world valueOfProperty: #loadHistoryLong
		ifAbsent: [^self].
	self showHistory
		ifTrue: [
			| startTime |
			data _ Array new: 60 withAll: 100.
			startTime _ rawData last key - 59.
			rawData do: [:each | | index |
				index _ each key - startTime + 1.
				(index between: 1 and: 60)
					ifTrue: [data at: index put: each value]]]
		ifFalse: [data _ Array with: rawData last value].
	r _ 0.
	1 to: data size do: [:i |
		l _ r.
		r _ i * bounds width // data size. 
		h _ (data at: i) * bounds height // 100.
		aCanvas fillRectangle: ((bounds left + l) @ (bounds bottom - h)
				corner: (bounds left + r) @ (bounds bottom))
			color: color]! !

!LoadMorph methodsFor: 'stepping' stamp: 'bf 3/15/2000 10:53'!
	^ self showHistory
		ifTrue: [300]
		ifFalse: [100]! !

!LoadMorph methodsFor: 'accessing' stamp: 'bf 3/14/2000 14:01'!
background: aColor
	background _ aColor isTransparent ifFalse: [aColor].
	self changed! !

!LoadMorph methodsFor: 'accessing' stamp: 'bf 3/15/2000 10:56'!
	^ bounds width >= 60! !

!LoadMorph methodsFor: 'menu' stamp: 'bf 3/15/2000 11:44'!
addCustomMenuItems: aCustomMenu hand: aHandMorph
	super addCustomMenuItems: aCustomMenu hand: aHandMorph.
		add: 'change background...' action: #changeBackground! !

!LoadMorph methodsFor: 'menu' stamp: 'bf 3/15/2000 12:07'!
	^ self showHistory ifTrue:
['History of the UI load
(make smaller to see only current load)']
['Current UI load
(make wider to see history)']! !

!LoadMorph methodsFor: 'menu' stamp: 'bf 3/14/2000 14:01'!
	ColorPickerMorph new
		sourceHand: self activeHand;
		target: self;
		selector: #background:;
		originalColor: background;
		addToWorld: self world near: self bounds! !

More information about the Squeak-dev mailing list