Leon Matthes uploaded a new version of CogTools to project VM Maker: http://source.squeak.org/VMMaker/CogTools.threaded-LM.98.mcz
==================== Summary ====================
Name: CogTools.threaded-LM.98 Author: LM Time: 11 December 2023, 6:45:51.961251 pm UUID: 5ddbc164-f9fa-4ef9-95f3-b4197e06ad8a Ancestors: CogTools.threaded-LM.97
Add a small GUI to the ThreadInspector.
=============== Diff against CogTools.threaded-LM.97 ===============
Item was changed: Model subclass: #ThreadInspector + instanceVariableNames: 'startTime ownerLog graph currentStartTime currentEndTime' - instanceVariableNames: 'startTime ownerLog' classVariableNames: '' poolDictionaries: '' category: 'CogTools-ThreadInspector'!
Item was added: + ----- Method: ThreadInspector>>afterBuildWith: (in category 'as yet unclassified') ----- + afterBuildWith: builder + + self initializeGraph. + self plotGraphFrom: startTime to: self ownerLog last timestamp. + (builder widgetAt: #PlotViewport) + addMorph: graph + fullFrame: (LayoutFrame fractions: (0@0 corner: 1@1)).!
Item was added: + ----- Method: ThreadInspector>>buildWith: (in category 'as yet unclassified') ----- + buildWith: builder + + |windowSpec window| + windowSpec := builder pluggableWindowSpec new. + windowSpec + model: self; + label: 'VM Owner Inspector'; + extent: 400@400; + children: (self windowMemberSpecsFor: builder). + + window := builder build: windowSpec. + self afterBuildWith: builder. + ^ window!
Item was added: + ----- Method: ThreadInspector>>currentEndTime (in category 'accessing') ----- + currentEndTime + + ^ currentEndTime!
Item was added: + ----- Method: ThreadInspector>>currentEndTime: (in category 'accessing') ----- + currentEndTime: anObject + + currentEndTime := anObject.!
Item was added: + ----- Method: ThreadInspector>>currentStartTime (in category 'accessing') ----- + currentStartTime + + ^ currentStartTime!
Item was added: + ----- Method: ThreadInspector>>currentStartTime: (in category 'accessing') ----- + currentStartTime: anObject + + currentStartTime := anObject.!
Item was added: + ----- Method: ThreadInspector>>graph (in category 'accessing') ----- + graph + + ^ graph!
Item was added: + ----- Method: ThreadInspector>>graph: (in category 'accessing') ----- + graph: anObject + + graph := anObject.!
Item was added: + ----- Method: ThreadInspector>>initialize (in category 'as yet unclassified') ----- + initialize + + self currentStartTime: 0. + self currentEndTime: 1. + !
Item was added: + ----- Method: ThreadInspector>>initializeGraph (in category 'plotting') ----- + initializeGraph + + graph := ThreadInspectorPlotMorph new + model: self; + yourself. + graph + series: #vmOwner color: Color green; + series: #vmOwner description: 'vm owner'; + series: #vmOwner type: #stepped. + + graph + series: #failedLocks color: Color red; + series: #failedLocks description: 'failed locking attempts'; + series: #failedLocks drawLine: false; + series: #failedLocks width: 2. + + graph xAxisFormatter: [:value | + ((value - (self currentStartTime)/ 1000) asFloat printShowingMaxDecimalPlaces: 4), ' ms']. + + "make sure we always have at least -1, 0 and 1 in view, even if there were no owner switches to them." + graph minPoint y > -1 + ifTrue: [graph limitMinY: -1]. + graph maxPoint y < 1 + ifTrue: [graph limitMaxY: 1].!
Item was added: + ----- Method: ThreadInspector>>menuBarHeight (in category 'as yet unclassified') ----- + menuBarHeight + + ^ Preferences standardButtonFont height * 3!
Item was added: + ----- Method: ThreadInspector>>menuBarSpec: (in category 'as yet unclassified') ----- + menuBarSpec: builder + + ^ builder pluggablePanelSpec new + model: self; + frame: (LayoutFrame new + leftFraction: 0; + rightFraction: 1; + topFraction: 1 offset: self menuBarHeight negated; + bottomFraction: 1; + yourself); + children: { + builder pluggableButtonSpec new + model: self; + action: #zoomOut; + label: 'Zoom out'; + frame: LayoutFrame fullFrame; + yourself. + }!
Item was added: + ----- Method: ThreadInspector>>open (in category 'as yet unclassified') ----- + open + + (self buildWith: ToolBuilder default) openInWorld.!
Item was added: + ----- Method: ThreadInspector>>plotGraphFrom:to: (in category 'plotting') ----- + plotGraphFrom: startTime to: endTime + + | successful failed startIndex endIndex lastVMOwner | + graph clear. + + successful := self ownerLog select: #successfulSwitch. + failed := self ownerLog select: [:entry | entry successfulSwitch not and: [entry timestamp between: startTime and: endTime]]. + + startIndex := (successful findLast: [:entry | entry timestamp <= startTime]). + startIndex := startIndex max: 1. + + endIndex := (successful findLast: [:entry | entry timestamp <= endTime]). + endIndex := endIndex max: 1. + startIndex to: endIndex + do: [:index | |entry timestamp | + entry := (successful at: index). + "The first entry that we want to visualize may be before the start time, but because + we only want to show the plot from the start time, make sure to 'round up' in that case." + timestamp := (entry timestamp max: startTime) min: endTime. + graph series: #vmOwner addPoint: timestamp @ entry vmOwner]. + lastVMOwner := (successful at: endIndex) vmOwner. + graph series: #vmOwner addPoint: endTime @ lastVMOwner. + + failed do: [:entry | graph series: #failedLocks addPoint: entry timestamp @ entry vmOwner]. + + graph + limitMinX: startTime; + limitMaxX: endTime. + self currentStartTime: startTime. + self currentEndTime: endTime.!
Item was added: + ----- Method: ThreadInspector>>plotSpec: (in category 'as yet unclassified') ----- + plotSpec: builder + + ^ builder pluggablePanelSpec new + model: self; + frame: (LayoutFrame new + leftFraction: 0; + topFraction: 0; + rightFraction: 1; + bottomFraction: 1 offset: self menuBarHeight negated; + yourself); + name: #PlotViewport; + children: {}; + yourself!
Item was removed: - ----- Method: ThreadInspector>>primitiveMillisecondsNow (in category 'primitives') ----- - primitiveMillisecondsNow - <primitive: 245> - ^ self primitiveFailed!
Item was added: + ----- Method: ThreadInspector>>primitiveTimeNow (in category 'primitives') ----- + primitiveTimeNow + <primitive: 245> + ^ self primitiveFailed!
Item was added: + ----- Method: ThreadInspector>>selectProportionFrom:to: (in category 'plotting') ----- + selectProportionFrom: lowPortion to: highPortion + + |timeRange| + timeRange := self currentEndTime - self currentStartTime. + self plotGraphFrom: self currentStartTime + (timeRange * lowPortion) rounded + to: self currentStartTime + (timeRange * highPortion) rounded.!
Item was changed: + ----- Method: ThreadInspector>>spyOn: (in category 'profiling') ----- - ----- Method: ThreadInspector>>spyOn: (in category 'as yet unclassified') ----- spyOn: aBlock
| newStartTime | + newStartTime := self primitiveTimeNow. - newStartTime := self primitiveMillisecondsNow. aBlock value. "Only update the startTime & ownerLog if the block succeeded." self startTime: newStartTime. self ownerLog: self getOwnerLogFromVM.!
Item was changed: + ----- Method: ThreadInspector>>visualize (in category 'plotting') ----- - ----- Method: ThreadInspector>>visualize (in category 'as yet unclassified') ----- visualize
+ self initializeGraph. + self plotGraphFrom: self startTime to: self ownerLog last timestamp. - | pm startIndex lastVMOwner | - pm := ThreadInspectorPlotMorph new. - pm - series: #vmOwner color: Color green; - series: #vmOwner description: 'vm owner'; - series: #vmOwner type: #stepped. + graph openInWorld.! - pm - series: #failedLocks color: Color red; - series: #failedLocks description: 'failed locking attempts'; - series: #failedLocks drawLine: false. - - startIndex := (self ownerLog findLast: [:entry | entry successfulSwitch and: [entry timestamp <= self startTime]]). - startIndex := startIndex max: 1. - startIndex to: self ownerLog size - do: [:index | |entry series | - entry := (self ownerLog at: index). - series := entry successfulSwitch ifTrue: [#vmOwner] ifFalse: [#failedLocks]. - pm series: series addPoint: entry timestamp @ entry vmOwner]. - lastVMOwner := (self ownerLog at: (self ownerLog findLast: [:entry | entry successfulSwitch])) vmOwner. - pm series: #vmOwner addPoint: self ownerLog last timestamp@ lastVMOwner. - "make sure we always have at least -1, 0 and 1 in view, even if there were no owner switches to them." - pm minPoint y > -1 - ifTrue: [pm limitMinY: -1]. - pm maxPoint y < 1 - ifTrue: [pm limitMaxY: 1]. - - pm openInWorld. - !
Item was added: + ----- Method: ThreadInspector>>windowMemberSpecsFor: (in category 'as yet unclassified') ----- + windowMemberSpecsFor: builder + + ^ { + self plotSpec: builder. + self menuBarSpec: builder. + }!
Item was added: + ----- Method: ThreadInspector>>zoomOut (in category 'plotting') ----- + zoomOut + + self plotGraphFrom: startTime to: self ownerLog last timestamp.!
vm-dev@lists.squeakfoundation.org