Skip to content

Commit

Permalink
Introduce CallTargetBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Feb 21, 2021
1 parent 44d0838 commit 05a0374
Show file tree
Hide file tree
Showing 32 changed files with 229 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
testing
testCallTarget
| method string |
Java primitiveIsHostLookupAllowed ifFalse: [ ^ false ].

method := SmallInteger >> #/.

self deny: method callTarget isNil.

string := CallTargetBrowser callTargetInfoStringFor: method.
self assert: (string includesSubstring: 'knownCallSiteCount')
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +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/18/2021 09:20",
"testLayoutStatistics" : "fn 5/13/2020 17:37",
"testTestMapConsistency" : "fn 12/17/2020 19:52",
"testVMIntrospection" : "fn 2/1/2021 15:00" } }
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
helpers
callTargetInfoStringFor: aCompiledMethod
^ aCompiledMethod callTarget
ifNil: [ 'no call target available' ]
ifNotNil: [ :c |
'name: {1}
callCount: {2}
callAndLoopCount: {3}
knownCallSiteCount: {4}
nonTrivialNodeCount: {5}
profiled return value: {6}
profiled arguments: {7}' format: {
c getName asString.
c getCallCount.
c getCallAndLoopCount.
c getKnownCallSiteCount.
c getNonTrivialNodeCount.
c returnProfile
ifNil: [ 'unknown' ]
ifNotNil: [ :p | p getType ifNil: [ 'unknown' ] ifNotNil: [ :e | e getSimpleName asString ]].
c argumentsProfile
ifNil: [ 'all unknown' ]
ifNotNil: [ :p | p getTypes
ifNil: [ 'all unknown' ]
ifNotNil: [ :t | ((t asCollection allButFirst: 3) collect: [ :ea | ea
ifNil: ['unknown']
ifNotNil: [ ea getSimpleName asString ]]) joinSeparatedBy: ', ' ] ] } ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
preferences
showClassIcons
^ false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
preferences
showMessageIcons
^ false
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
message list
callTargetInfoContents
^ contents := self selectedClassOrMetaClass methodDict
at: self selectedMessageName
ifPresent: [ :cm | self class callTargetInfoStringFor: cm ]
ifAbsent: [ 'not found' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
controls
contentsSymbolQuints
^ super contentsSymbolQuints, #(#-
(callTargetInfo toggleCallTargetInfo showingCallTargetInfoString 'call target' 'information on underlying call target'))
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
helpers
countsToMessages: aMessageList
| result |
result := Dictionary new.
aMessageList do: [ :ea | | callTarget |
callTarget := (self selectedClassOrMetaClass >> ea asSymbol) callTarget.
result
at: (callTarget ifNil: [-1] ifNotNil: [ :c |
self sortBy caseOf: {
[#callCount] -> [ c getCallCount ln ].
[#callAndLoopCount] -> [ c getCallAndLoopCount ln ].
[#knownCallSiteCount] -> [ c getKnownCallSiteCount ].
[#nonTrivialNodeCount] -> [ c getNonTrivialNodeCount ] } ] )
ifPresent: [ :v | v add: ea ]
ifAbsentPut: [ OrderedCollection with: ea ] ].
^ result
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialize-release
defaultBrowserTitle
^ 'CallTarget Browser'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message list
formattedLabel: aString forSelector: aSymbol inClass: aClass
^ aString
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
message functions
inspectCallTarget
(self selectedClassOrMetaClass
compiledMethodAt: self selectedMessageName
ifAbsent: []) ifNotNil:
[:method| method callTarget inspect]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
message functions
mainMessageListMenu: aMenu
^ (super mainMessageListMenu: aMenu)
add: 'inspect call target' action: #inspectCallTarget;
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;
addLine;
yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
message list
messageList
| messages countsToMessages sortedCounts highestCount result |
messages := super messageList.
(self sortBy == #alphabetically or: [ messages isEmpty])
ifTrue: [ ^ messages ].
countsToMessages := self countsToMessages: messages.
result := OrderedCollection new.
sortedCounts := countsToMessages keysInOrder reversed.
highestCount := sortedCounts first.
sortedCounts do: [ :count |
result addAll: ((countsToMessages at: count) collect: [ :ea |
ea asText
addAttribute: (self textColorFor: count with: highestCount)
yourself])].
^ result
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
message list
selectedMessage
contents == nil ifFalse: [^ contents copy].

self showingCallTargetInfo ifTrue:
[ ^ self callTargetInfoContents ].

^ super selectedMessage
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
what to show
showCallTargetInfo: aBoolean
self contentsSymbol: (aBoolean ifFalse: [#source] ifTrue: [#callTargetInfo])
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
what to show
showingCallTargetInfo
^ contentsSymbol == #callTargetInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
what to show
showingCallTargetInfoString
"Answer a string telling whether the receiver is showing plain source"

^ (self showingCallTargetInfo
ifTrue:
['<yes>']
ifFalse:
['<no>']), 'call target'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
sortAlphabetically
self sortBy: #alphabetically
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
sortBy: anObject

sortBy := anObject.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
sortBy

^ sortBy ifNil: [ sortBy := #callAndLoopCount ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
sortByCallAndLoopCount
self sortBy: #callAndLoopCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
sortByCallCount
self sortBy: #callCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
sortByKnownCallSiteCount
self sortBy: #knownCallSiteCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions
sortByNonTrivialNodeCount
self sortBy: #nonTrivialNodeCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
helpers
textColorFor: aCount with: aMax

^ aCount >= 0
ifTrue: [ | r |
r := 1.0 * aCount / aMax.
TextColor color: (Color
r: r
g: 0
b: 1.0 - r) ]
ifFalse: [ TextColor gray]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
what to show
toggleCallTargetInfo
| wasShowing |
self okToChange ifTrue:
[wasShowing := self showingCallTargetInfo.
self restoreTextualCodingPane.
self showCallTargetInfo: wasShowing not.
self setContentsToForceRefetch.
self contentsChanged]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"class" : {
"callTargetInfoStringFor:" : "fn 2/18/2021 09:14",
"showClassIcons" : "fn 2/16/2021 22:17",
"showMessageIcons" : "fn 2/16/2021 22:17" },
"instance" : {
"callTargetInfoContents" : "fn 2/18/2021 10:12",
"contentsSymbolQuints" : "fn 2/17/2021 12:00",
"countsToMessages:" : "fn 2/17/2021 14:33",
"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",
"selectedMessage" : "fn 2/17/2021 12:26",
"showCallTargetInfo:" : "fn 2/17/2021 12:28",
"showingCallTargetInfo" : "fn 2/17/2021 12:01",
"showingCallTargetInfoString" : "fn 2/17/2021 12:01",
"sortAlphabetically" : "fn 2/16/2021 17:44",
"sortBy" : "fn 2/16/2021 17:33",
"sortBy:" : "fn 2/16/2021 17:27",
"sortByCallAndLoopCount" : "fn 2/16/2021 17:33",
"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" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "TruffleSqueak-Utilities",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
"sortBy" ],
"name" : "CallTargetBrowser",
"pools" : [
],
"super" : "Browser",
"type" : "normal" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*TruffleSqueak-Utilities
callTarget
<primitive: 'primitiveGetCallTarget' module: 'TruffleSqueakPlugin'>
^ nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"class" : {
},
"instance" : {
"callTarget" : "fn 2/16/2021 17:00" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "CompiledMethod" }

0 comments on commit 05a0374

Please sign in to comment.