Skip to content

Commit

Permalink
Add CallTargetBrowserRuby for TruffleRuby
Browse files Browse the repository at this point in the history
- Refactor and improve CallTargetBrowser to allow sharing
- Update a test
  • Loading branch information
fniephaus committed Mar 13, 2021
1 parent 37c97ba commit b71e5c1
Show file tree
Hide file tree
Showing 53 changed files with 321 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ testCallTarget

self deny: method callTarget isNil.

string := CallTargetBrowser callTargetInfoStringFor: method.
string := CallTargetBrowser callTargetInfoStringFor: method callTarget.
self assert: (string includesSubstring: 'knownCallSiteCount')
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"assertSorted:name:" : "fn 1/25/2020 15:24",
"testAdoptInstanceArrays" : "fn 1/31/2020 10:20",
"testArrayStatistics" : "fn 5/13/2020 17:37",
"testCallTarget" : "fn 2/22/2021 19:14",
"testCallTarget" : "fn 3/12/2021 11:08",
"testLayoutStatistics" : "fn 5/13/2020 17:37",
"testTestMapConsistency" : "fn 3/9/2021 15:59",
"testVMIntrospection" : "fn 3/11/2021 12:03" } }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
helpers
callTargetInfoStringFor: aCompiledMethod
^ aCompiledMethod callTarget
callTargetInfoStringFor: aCallTarget
^ aCallTarget
ifNil: [ 'no call target available' ]
ifNotNil: [ :c |
'name: {1}
Expand All @@ -24,9 +24,11 @@ included call nodes:
ifNil: [ 'all n/a' ]
ifNotNil: [ :p | p getTypes
ifNil: [ 'all n/a' ]
ifNotNil: [ :t | ((t asCollection allButFirst: 3) collect: [ :ea | ea
ifNotNil: [ :t | (t asCollection collect: [ :ea | ea
ifNil: ['n/a']
ifNotNil: [ ea getSimpleName asString ]]) joinSeparatedBy: ', ' ] ].
(c getCallNodes asCollection collect: [ :ea |
ea getCurrentCallTarget toString asString])
joinSeparatedBy: String cr, ' - ' } ]
(c getCallNodes asCollection
ifNotEmpty: [:n | (n collect: [ :ea |
ea getCurrentCallTarget toString asString])
joinSeparatedBy: String cr, ' - ' ]
ifEmpty: [ 'n/a' ] ) } ]
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ message list
callTargetInfoContents
^ contents := self selectedClassOrMetaClass methodDict
at: self selectedMessageName
ifPresent: [ :cm | self class callTargetInfoStringFor: cm ]
ifPresent: [ :cm | self class callTargetInfoStringFor: cm callTarget ]
ifAbsent: [ 'not found' ]
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ countsToMessages: aMessageList
result
at: (callTarget ifNil: [-1] ifNotNil: [ :c |
self sortBy caseOf: {
[#callCount] -> [ c getCallCount ln ].
[#callAndLoopCount] -> [ c getCallAndLoopCount ln ].
[#callCount] -> [ | v |
v := c getCallCount.
v > 0 ifTrue: [ v ln ] ifFalse: [ v ] ].
[#callAndLoopCount] -> [ | v |
v := c getCallAndLoopCount.
v > 0 ifTrue: [ v ln ] ifFalse: [ v ] ].
[#knownCallSiteCount] -> [ c getKnownCallSiteCount ].
[#nonTrivialNodeCount] -> [ c getNonTrivialNodeCount ] } ] )
ifPresent: [ :v | v add: ea ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ messageList
sortedCounts do: [ :count |
result addAll: ((countsToMessages at: count) collect: [ :ea |
ea asText
addAttribute: (self textColorFor: count with: highestCount)
addAttribute: (self class textColorFor: count with: highestCount)
yourself])].
^ result
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"class" : {
"callTargetInfoStringFor:" : "fn 2/27/2021 17:28",
"callTargetInfoStringFor:" : "fn 3/12/2021 14:05",
"showClassIcons" : "fn 2/16/2021 22:17",
"showMessageIcons" : "fn 2/16/2021 22:17" },
"showMessageIcons" : "fn 2/16/2021 22:17",
"textColorFor:with:" : "fn 3/12/2021 11:14" },
"instance" : {
"callTargetInfoContents" : "fn 2/18/2021 10:12",
"callTargetInfoContents" : "fn 3/12/2021 11:08",
"contentsSymbolQuints" : "fn 2/17/2021 12:00",
"countsToMessages:" : "fn 2/17/2021 14:33",
"countsToMessages:" : "fn 3/12/2021 11:48",
"defaultBrowserTitle" : "fn 2/16/2021 16:54",
"formattedLabel:forSelector:inClass:" : "fn 2/16/2021 22:10",
"inspectCallTarget" : "fn 2/17/2021 14:50",
"mainMessageListMenu:" : "fn 2/17/2021 14:51",
"messageList" : "fn 2/16/2021 22:13",
"messageList" : "fn 3/12/2021 11:14",
"selectedMessage" : "fn 2/17/2021 12:26",
"showCallTargetInfo:" : "fn 2/17/2021 12:28",
"showingCallTargetInfo" : "fn 2/17/2021 12:01",
Expand All @@ -23,6 +24,5 @@
"sortByCallCount" : "fn 2/16/2021 17:30",
"sortByKnownCallSiteCount" : "fn 2/16/2021 17:39",
"sortByNonTrivialNodeCount" : "fn 2/16/2021 17:39",
"textColorFor:with:" : "fn 2/17/2021 11:08",
"toggleCallTargetInfo" : "fn 2/17/2021 12:28",
"updateListsAndCodeIn:" : "fn 2/21/2021 15:59" } }
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
helpers
callTargetFor: aMethodName of: aModuleName
^ (TruffleSqueakUtilities primitiveGetVMObject: (
self methodFor: aMethodName of: aModuleName))
method callTarget
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
helpers
methodFor: aMethodName of: aModuleName
^ self methodGetter value: aModuleName value: aMethodName
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
helpers
methodGetter
"MethodGetter := nil"
^ MethodGetter ifNil: [ MethodGetter := Polyglot eval: 'ruby' string:
'Proc.new{|mod_name,meth_name| m1 = Object.const_get(mod_name); m2 = meth_name.to_s.to_sym; if m1.methods(false).include?(m2);m1.method(m2);else;m1.instance_method(m2);end}' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
helpers
methodList: aModuleName
^ ((self methodListGetter value: aModuleName) asCollection
collect: [:ea | ea asString]) sorted
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
helpers
methodListGetter
"MethodListGetter := nil"
^ MethodListGetter ifNil: [ MethodListGetter := Polyglot eval: 'ruby' string:
'Proc.new{|mod_name| m = Object.const_get(mod_name); m.methods(false).concat(m.instance_methods(false))}' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
opening
open
self new open
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
autoUpdate
^ autoUpdate ifNil: [ autoUpdate := true ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
toolbuilder
buildCallTargetPaneWith: builder
| textSpec |
textSpec := builder pluggableTextSpec new.
textSpec
model: self;
getText: #callTargetInfo.
^ textSpec
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
toolbuilder
buildMethodListWith: builder
| listSpec |
listSpec := builder pluggableListSpec new.
listSpec
model: self;
list: #methodList;
getIndex: #methodListIndex;
setIndex: #methodListIndex:;
icon: #methodIconAt:;
menu: #methodListMenu:.
^ listSpec
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
toolbuilder
buildModuleListWith: builder
| listSpec |
listSpec := builder pluggableListSpec new.
listSpec
model: self;
list: #moduleList;
getIndex: #moduleListIndex;
setIndex: #moduleListIndex:.
^ listSpec
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
toolbuilder
buildWith: builder
^ builder build: (self buildWindowWith: builder specs: {
(0@0 corner: 0.25@1) -> [self buildModuleListWith: builder].
(0.25@0 corner: 0.5@1) -> [self buildMethodListWith: builder].
(0.5@0 corner: 1@1) -> [self buildCallTargetPaneWith: builder].
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
call targets
callTargetInfo
^ self selectedCallTarget
ifNotNil: [ :c | CallTargetBrowser callTargetInfoStringFor: c ]
ifNil: [ 'no call target available' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
methods
countsToMethods: aMethodList
| result |
result := Dictionary new.
aMethodList do: [ :ea | | callTarget |
callTarget := (self class callTargetFor: ea of: self selectedModuleName).
result
at: (callTarget ifNil: [-1] ifNotNil: [ :c |
self sortBy caseOf: {
[#callCount] -> [ | v |
v := c getCallCount.
v > 0 ifTrue: [ v ln ] ifFalse: [ v ] ].
[#callAndLoopCount] -> [ | v |
v := c getCallAndLoopCount.
v > 0 ifTrue: [ v ln ] ifFalse: [ v ] ].
[#knownCallSiteCount] -> [ c getKnownCallSiteCount ].
[#nonTrivialNodeCount] -> [ c getNonTrivialNodeCount ] } ] )
ifPresent: [ :v | v add: ea asString ]
ifAbsentPut: [ OrderedCollection with: ea ] ].
^ result
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
overrides
initialExtent
^ 800 @ 400
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
call targets
inspectCallTarget
self selectedCallTarget inspect
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
toolbuilder
labelString
| label |
label := 'CallTargetBrowser for TruffleRuby'.
self selectedModuleName
ifNotNil: [ :name | label := label, ': ', name ].
^ label
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
methods
methodIconAt: anIndex
^ nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
methods
methodList
| methods countsToMessages sortedCounts highestCount result |
methods := self selectedMethods.
(self sortBy == #alphabetically or: [ methods isEmpty])
ifTrue: [ ^ methods ].
countsToMessages := self countsToMethods: methods.
result := OrderedCollection new.
sortedCounts := countsToMessages keysInOrder reversed.
highestCount := sortedCounts first max: 1.
sortedCounts do: [ :count |
result addAll: ((countsToMessages at: count) collect: [ :ea |
ea asText
addAttribute: (CallTargetBrowser textColorFor: count with: highestCount)
yourself])].
^ result
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
methods
methodListIndex: anInteger
self selectedMethodName: (self methodList at: anInteger ifPresent: [ :t | t asString ] ifAbsent: [ nil ])
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
methods
methodListIndex
^ self methodList indexOf: self selectedMethodName
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
methods
methodListMenu: aMenu
^ aMenu
add: 'inspect method' action: #inspectMethod;
add: 'inspect call target' action: #inspectCallTarget;
addLine;
add: ('toggle auto-update ', (self autoUpdate ifTrue: [ '(on)' ] ifFalse: [ '(off)' ])) action: #toggleAutoUpdate;
addLine;
add: 'sort alphabetically' action: #sortAlphabetically;
add: 'sort by call and loop count (default)' action: #sortByCallAndLoopCount;
add: 'sort by call count' action: #sortByCallCount;
add: 'sort by known call site count' action: #sortByKnownCallSiteCount;
add: 'sort by non-trivial node count' action: #sortByNonTrivialNodeCount;
yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
modules
moduleList
^ ((Polyglot eval: 'ruby' string: 'Object.constants')
asCollection collect: [ :ea | ea asString ]) sorted
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
modules
moduleListIndex: anInteger
self selectedModuleName: (self moduleList at: anInteger ifAbsent: [ nil ])
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
modules
moduleListIndex
^ self moduleList indexOf: self selectedModuleName
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialize-release
open
^ ToolBuilder open: self
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
call targets
selectedCallTarget
^ self selectedModuleName
ifNil: [ nil ]
ifNotNil: [ :moduleName |
self selectedMethodName
ifNil: [ nil ]
ifNotNil: [ :methodName | self class callTargetFor: methodName of: moduleName] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
methods
selectedMethod
^ self selectedModuleName
ifNil: [ nil ]
ifNotNil: [ :moduleName |
self selectedMethodName
ifNil: [ nil ]
ifNotNil: [ :methodName | self class methodFor: methodName of: moduleName] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
accessing
selectedMethodName: anObject

selectedMethodName := anObject.
self changed: #methodListIndex.
self changed: #callTargetInfo.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
selectedMethodName

^ selectedMethodName
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
methods
selectedMethods
^ self selectedModuleName
ifNotNil: [ :name | self class methodList: name ]
ifNil: [ #() ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
accessing
selectedModuleName: anObject

selectedModuleName := anObject.
selectedMethodName := nil.
self changed: #moduleListIndex.
self changed: #methodList.
self changed: #relabel.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
selectedModuleName

^ selectedModuleName
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sorting
sortAlphabetically
self sortBy: #alphabetically
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sorting
sortBy: anObject

sortBy := anObject.
self changed: #methodList
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sorting
sortBy

^ sortBy ifNil: [ sortBy := #callAndLoopCount ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sorting
sortByCallAndLoopCount
self sortBy: #callAndLoopCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sorting
sortByCallCount
self sortBy: #callCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sorting
sortByKnownCallSiteCount
self sortBy: #knownCallSiteCount
Loading

0 comments on commit b71e5c1

Please sign in to comment.