History

perf scripts python: exported-sql-viewer.py: Add context menu

Add a context menu (right-click) that provides options for copying to clipboard, including, for trees, the ability to copy only the cell under the mouse pointer. Committer testing: $ python ~acme/libexec/perf-core/scripts/python/exported-sql-viewer.py ~/c/adrian.hunter/simple-retpoline.db Simply right click and pick "Copy selection", that at this point has just the first line, not expanded, then see what was copied by pressing shift+control+v on a terminal: Call Path,Object,Count,Time (ns),Time (%),Branch Count,Branch Count (%) ▶ simple-retpolin,,,,,, Ditto after expanding, i.e. the selection continues to be just one line: Call Path Object Count Time (ns) Time (%) Branch Count Branch Count (%) ▼ simple-retpolin Now select all the lines with the mouse and control+shift+v again: Call Path Object Count Time (ns) Time (%) Branch Count Branch Count (%) ▼ 14503:14503 ▼ _start ld-2.28.so 1 156267 100.0 10602 100.0 ▶ unknown unknown 1 2276 1.5 1 0.0 ▶ _dl_start ld-2.28.so 1 137047 87.7 10088 95.2 ▶ _dl_init ld-2.28.so 1 9142 5.9 326 3.1 ▼ _start simple-retpoline 1 7457 4.8 182 1.7 ▶ unknown unknown 1 805 10.8 1 0.5 ▶ __libc_start_main libc-2.28.so 1 6347 85.1 179 98.4

Adrian Hunter committed 7 years ago

Commit 9bc4e4b1 parent 96c43b91 file · +41 −0Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/exported-sql-viewer.py+41−0
@@ -887,6 +887,8 @@ class TreeWindowBase(QMdiSubWindow): · 886 unmodified lines
887887 self.view.setSelectionMode(QAbstractItemView.ContiguousSelection)
888888 self.view.CopyCellsToClipboard = CopyTreeCellsToClipboard
889889
890+ self.context_menu = TreeContextMenu(self.view)
891+
890892 def DisplayFound(self, ids):
891893 if not len(ids):
892894 return False
@@ -1660,6 +1662,8 @@ class BranchWindow(QMdiSubWindow): · 767 unmodified lines
16601662
16611663 self.ResizeColumnsToContents()
16621664
1665+ self.context_menu = TreeContextMenu(self.view)
1666+
16631667 self.find_bar = FindBar(self, self, True)
16641668
16651669 self.finder = ChildDataItemFinder(self.model.root)
@@ -2469,6 +2473,39 @@ def CopyCellsToClipboardHdr(view): · 803 unmodified lines
24692473 def CopyCellsToClipboardCSV(view):
24702474 CopyCellsToClipboard(view, True, True)
24712475
2476+# Context menu
2477+
2478+class ContextMenu(object):
2479+
2480+ def __init__(self, view):
2481+ self.view = view
2482+ self.view.setContextMenuPolicy(Qt.CustomContextMenu)
2483+ self.view.customContextMenuRequested.connect(self.ShowContextMenu)
2484+
2485+ def ShowContextMenu(self, pos):
2486+ menu = QMenu(self.view)
2487+ self.AddActions(menu)
2488+ menu.exec_(self.view.mapToGlobal(pos))
2489+
2490+ def AddCopy(self, menu):
2491+ menu.addAction(CreateAction("&Copy selection", "Copy to clipboard", lambda: CopyCellsToClipboardHdr(self.view), self.view))
2492+ menu.addAction(CreateAction("Copy selection as CS&V", "Copy to clipboard as CSV", lambda: CopyCellsToClipboardCSV(self.view), self.view))
2493+
2494+ def AddActions(self, menu):
2495+ self.AddCopy(menu)
2496+
2497+class TreeContextMenu(ContextMenu):
2498+
2499+ def __init__(self, view):
2500+ super(TreeContextMenu, self).__init__(view)
2501+
2502+ def AddActions(self, menu):
2503+ i = self.view.currentIndex()
2504+ text = str(i.data()).strip()
2505+ if len(text):
2506+ menu.addAction(CreateAction('Copy "' + text + '"', "Copy to clipboard", lambda: QApplication.clipboard().setText(text), self.view))
2507+ self.AddCopy(menu)
2508+
24722509 # Table window
24732510
24742511 class TableWindow(QMdiSubWindow, ResizeColumnsToContentsBase):
@@ -2492,6 +2529,8 @@ class TableWindow(QMdiSubWindow, ResizeColumnsToContentsBase): · 17 unmodified lines
24922529
24932530 self.ResizeColumnsToContents()
24942531
2532+ self.context_menu = ContextMenu(self.view)
2533+
24952534 self.find_bar = FindBar(self, self, True)
24962535
24972536 self.finder = ChildDataItemFinder(self.data_model)
@@ -2608,6 +2647,8 @@ class TopCallsWindow(QMdiSubWindow, ResizeColumnsToContentsBase): · 110 unmodified lines
26082647 self.view.setSelectionMode(QAbstractItemView.ContiguousSelection)
26092648 self.view.CopyCellsToClipboard = CopyTableCellsToClipboard
26102649
2650+ self.context_menu = ContextMenu(self.view)
2651+
26112652 self.ResizeColumnsToContents()
26122653
26132654 self.find_bar = FindBar(self, self, True)