Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/20190503120828.25326-6-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
9bc4e4bf 96c43b9a

+41
+41
tools/perf/scripts/python/exported-sql-viewer.py
··· 887 887 self.view.setSelectionMode(QAbstractItemView.ContiguousSelection) 888 888 self.view.CopyCellsToClipboard = CopyTreeCellsToClipboard 889 889 890 + self.context_menu = TreeContextMenu(self.view) 891 + 890 892 def DisplayFound(self, ids): 891 893 if not len(ids): 892 894 return False ··· 1661 1659 self.view.setModel(self.model) 1662 1660 1663 1661 self.ResizeColumnsToContents() 1662 + 1663 + self.context_menu = TreeContextMenu(self.view) 1664 1664 1665 1665 self.find_bar = FindBar(self, self, True) 1666 1666 ··· 2473 2469 def CopyCellsToClipboardCSV(view): 2474 2470 CopyCellsToClipboard(view, True, True) 2475 2471 2472 + # Context menu 2473 + 2474 + class ContextMenu(object): 2475 + 2476 + def __init__(self, view): 2477 + self.view = view 2478 + self.view.setContextMenuPolicy(Qt.CustomContextMenu) 2479 + self.view.customContextMenuRequested.connect(self.ShowContextMenu) 2480 + 2481 + def ShowContextMenu(self, pos): 2482 + menu = QMenu(self.view) 2483 + self.AddActions(menu) 2484 + menu.exec_(self.view.mapToGlobal(pos)) 2485 + 2486 + def AddCopy(self, menu): 2487 + menu.addAction(CreateAction("&Copy selection", "Copy to clipboard", lambda: CopyCellsToClipboardHdr(self.view), self.view)) 2488 + menu.addAction(CreateAction("Copy selection as CS&V", "Copy to clipboard as CSV", lambda: CopyCellsToClipboardCSV(self.view), self.view)) 2489 + 2490 + def AddActions(self, menu): 2491 + self.AddCopy(menu) 2492 + 2493 + class TreeContextMenu(ContextMenu): 2494 + 2495 + def __init__(self, view): 2496 + super(TreeContextMenu, self).__init__(view) 2497 + 2498 + def AddActions(self, menu): 2499 + i = self.view.currentIndex() 2500 + text = str(i.data()).strip() 2501 + if len(text): 2502 + menu.addAction(CreateAction('Copy "' + text + '"', "Copy to clipboard", lambda: QApplication.clipboard().setText(text), self.view)) 2503 + self.AddCopy(menu) 2504 + 2476 2505 # Table window 2477 2506 2478 2507 class TableWindow(QMdiSubWindow, ResizeColumnsToContentsBase): ··· 2528 2491 self.view.CopyCellsToClipboard = CopyTableCellsToClipboard 2529 2492 2530 2493 self.ResizeColumnsToContents() 2494 + 2495 + self.context_menu = ContextMenu(self.view) 2531 2496 2532 2497 self.find_bar = FindBar(self, self, True) 2533 2498 ··· 2646 2607 self.view.verticalHeader().setVisible(False) 2647 2608 self.view.setSelectionMode(QAbstractItemView.ContiguousSelection) 2648 2609 self.view.CopyCellsToClipboard = CopyTableCellsToClipboard 2610 + 2611 + self.context_menu = ContextMenu(self.view) 2649 2612 2650 2613 self.ResizeColumnsToContents() 2651 2614