From 319e5dc82769f0f1ea68812aa125730d70f9e290 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Thu, 15 Jul 2021 10:35:24 +0200 Subject: [PATCH] Add ability to show coverage based on Truffle ASTs --- .../instance/aboutToStyle..st | 3 +++ .../instance/mainMessageListMenu..st | 2 ++ .../instance/showCoverage..st | 4 ++++ .../instance/showCoverage.st | 4 ++++ .../sourceStringPrettifiedAndDiffed.st | 21 +++++++++++++++++++ .../instance/toggleCoverage.st | 4 ++++ .../instance/updateListsAndCodeIn..st | 2 +- .../methodProperties.json | 9 ++++++-- .../CallTargetBrowser.class/properties.json | 3 ++- 9 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/aboutToStyle..st create mode 100644 src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/showCoverage..st create mode 100644 src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/showCoverage.st create mode 100644 src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/sourceStringPrettifiedAndDiffed.st create mode 100644 src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/toggleCoverage.st diff --git a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/aboutToStyle..st b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/aboutToStyle..st new file mode 100644 index 000000000..1114a9a24 --- /dev/null +++ b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/aboutToStyle..st @@ -0,0 +1,3 @@ +what to show +aboutToStyle: aStyler + ^ self showCoverage not and: [ super aboutToStyle: aStyler ] \ No newline at end of file diff --git a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/mainMessageListMenu..st b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/mainMessageListMenu..st index d74adf039..a7dace6a5 100644 --- a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/mainMessageListMenu..st +++ b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/mainMessageListMenu..st @@ -9,4 +9,6 @@ mainMessageListMenu: aMenu add: 'sort by known call site count' action: #sortByKnownCallSiteCount; add: 'sort by non-trivial node count' action: #sortByNonTrivialNodeCount; addLine; + add: 'toggle coverage based on Truffle ASTs' action: #toggleCoverage; + addLine; yourself \ No newline at end of file diff --git a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/showCoverage..st b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/showCoverage..st new file mode 100644 index 000000000..4a4f26d8f --- /dev/null +++ b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/showCoverage..st @@ -0,0 +1,4 @@ +accessing +showCoverage: anObject + + showCoverage := anObject. \ No newline at end of file diff --git a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/showCoverage.st b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/showCoverage.st new file mode 100644 index 000000000..233ac3f2d --- /dev/null +++ b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/showCoverage.st @@ -0,0 +1,4 @@ +accessing +showCoverage + + ^ showCoverage ifNil: [ false ] \ No newline at end of file diff --git a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/sourceStringPrettifiedAndDiffed.st b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/sourceStringPrettifiedAndDiffed.st new file mode 100644 index 000000000..7fd763e90 --- /dev/null +++ b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/sourceStringPrettifiedAndDiffed.st @@ -0,0 +1,21 @@ +message list +sourceStringPrettifiedAndDiffed + | text | + text := super sourceStringPrettifiedAndDiffed. + (self showCoverage and: [ contentsSymbol = #source ]) ifFalse: [ ^ text ]. + currentCompiledMethod callTarget ifNotNil: [ :ct | | map nodes initialPC scanner client | + map := DebuggerMethodMap forMethod: currentCompiledMethod. + nodes := ct getRootNode executeBytecodeNode bytecodeNodes. + initialPC := currentCompiledMethod initialPC. + scanner := InstructionStream on: currentCompiledMethod. + client := InstructionClient new. + [ scanner pc <= currentCompiledMethod endPC ] whileTrue: [ | pc range attribute | + pc := scanner pc. + (scanner willSend or: [ scanner willReturn ]) ifTrue: [ + range := map rangeForPC: pc in: currentCompiledMethod contextIsActiveContext: true. + attribute := TextColor color: ( + (nodes at: (1 + pc - initialPC)) + ifNil: [ Color red ] ifNotNil: [ Color green ]) muchDarker. + text addAttribute: attribute from: range first to: range last ]. + scanner interpretNextInstructionFor: client ] ]. + ^ text \ No newline at end of file diff --git a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/toggleCoverage.st b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/toggleCoverage.st new file mode 100644 index 000000000..36b579c4c --- /dev/null +++ b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/toggleCoverage.st @@ -0,0 +1,4 @@ +actions +toggleCoverage + self showCoverage: self showCoverage not. + self changed: #contents \ No newline at end of file diff --git a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/updateListsAndCodeIn..st b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/updateListsAndCodeIn..st index ebe709fe8..e6d79be3f 100644 --- a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/updateListsAndCodeIn..st +++ b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/instance/updateListsAndCodeIn..st @@ -1,6 +1,6 @@ self-updating updateListsAndCodeIn: aWindow super updateListsAndCodeIn: aWindow. - self showingCallTargetInfo ifTrue: [ + (self showingCallTargetInfo or: [ self showCoverage ]) ifTrue: [ self setContentsToForceRefetch. self contentsChanged ] \ No newline at end of file diff --git a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/methodProperties.json b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/methodProperties.json index 8da72fb84..7bda22847 100644 --- a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/methodProperties.json +++ b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/methodProperties.json @@ -7,17 +7,20 @@ "showMessageIcons" : "fn 2/16/2021 22:17", "textColorFor:with:" : "fn 3/12/2021 11:14" }, "instance" : { + "aboutToStyle:" : "fn 7/15/2021 10:24", "callTargetInfoContents" : "fn 3/12/2021 11:08", "contentsSymbolQuints" : "fn 2/17/2021 12:00", "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", + "mainMessageListMenu:" : "fn 7/15/2021 10:22", "messageList" : "fn 7/8/2021 12:02", "selectedBytecodes" : "fn 7/14/2021 21:28", "selectedMessage" : "fn 2/17/2021 12:26", "showCallTargetInfo:" : "fn 2/17/2021 12:28", + "showCoverage" : "fn 7/15/2021 10:23", + "showCoverage:" : "fn 7/15/2021 10:22", "showingCallTargetInfo" : "fn 2/17/2021 12:01", "showingCallTargetInfoString" : "fn 2/17/2021 12:01", "sortAlphabetically" : "fn 2/16/2021 17:44", @@ -27,5 +30,7 @@ "sortByCallCount" : "fn 2/16/2021 17:30", "sortByKnownCallSiteCount" : "fn 2/16/2021 17:39", "sortByNonTrivialNodeCount" : "fn 2/16/2021 17:39", + "sourceStringPrettifiedAndDiffed" : "fn 7/15/2021 10:25", "toggleCallTargetInfo" : "fn 2/17/2021 12:28", - "updateListsAndCodeIn:" : "fn 2/21/2021 15:59" } } + "toggleCoverage" : "fn 7/15/2021 10:27", + "updateListsAndCodeIn:" : "fn 7/15/2021 10:34" } } diff --git a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/properties.json b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/properties.json index 2199beded..0b2456ecc 100644 --- a/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/properties.json +++ b/src/TruffleSqueak-Utilities.package/CallTargetBrowser.class/properties.json @@ -6,7 +6,8 @@ ], "commentStamp" : "", "instvars" : [ - "sortBy" ], + "sortBy", + "showCoverage" ], "name" : "CallTargetBrowser", "pools" : [ ],