tools: in performance-log-viewer.py, defer UI updates util needed

In the performance-log viewer, defer updates to the various UI
elements when the selection changes until they're actually shown.
This improves responsiveness when changing the selection.

(cherry picked from commit a7afbe13ec)
This commit is contained in:
Ell
2018-09-22 23:23:28 -04:00
parent 0207c9baa1
commit ea17d18d1b

View File

@ -1369,7 +1369,7 @@ class InformationViewer (Gtk.ScrolledWindow):
for element in info: for element in info:
add_element (element) add_element (element)
class VariablesViewer (Gtk.Box): class VariablesViewer (Gtk.ScrolledWindow):
class Store (Gtk.ListStore): class Store (Gtk.ListStore):
NAME = 0 NAME = 0
COLOR = 1 COLOR = 1
@ -1397,21 +1397,17 @@ class VariablesViewer (Gtk.Box):
def __init__ (self, *args, **kwargs): def __init__ (self, *args, **kwargs):
Gtk.Box.__init__ (self, Gtk.Box.__init__ (self,
*args, *args,
orientation = Gtk.Orientation.VERTICAL, hscrollbar_policy = Gtk.PolicyType.AUTOMATIC,
vscrollbar_policy = Gtk.PolicyType.AUTOMATIC,
**kwargs) **kwargs)
scroll = Gtk.ScrolledWindow ( self.needs_update = True
hscrollbar_policy = Gtk.PolicyType.AUTOMATIC,
vscrollbar_policy = Gtk.PolicyType.AUTOMATIC
)
self.pack_start (scroll, True, True, 0)
scroll.show ()
store = self.Store () store = self.Store ()
self.store = store self.store = store
tree = Gtk.TreeView (model = store) tree = Gtk.TreeView (model = store)
scroll.add (tree) self.add (tree)
tree.show () tree.show ()
self.single_sample_cols = [] self.single_sample_cols = []
@ -1457,9 +1453,12 @@ class VariablesViewer (Gtk.Box):
selection.connect ("change-complete", self.selection_change_complete) selection.connect ("change-complete", self.selection_change_complete)
self.selection_change_complete (selection) def update (self):
if not self.needs_update:
return
self.needs_update = False
def selection_change_complete (self, selection):
sel = selection.get_effective_selection () sel = selection.get_effective_selection ()
n_sel = len (sel) n_sel = len (sel)
@ -1506,6 +1505,17 @@ class VariablesViewer (Gtk.Box):
for col in self.single_sample_cols: col.set_visible (n_sel == 1) for col in self.single_sample_cols: col.set_visible (n_sel == 1)
for col in self.multi_sample_cols: col.set_visible (n_sel > 1) for col in self.multi_sample_cols: col.set_visible (n_sel > 1)
def do_map (self):
self.update ()
Gtk.ScrolledWindow.do_map (self)
def selection_change_complete (self, selection):
self.needs_update = True
if self.get_mapped ():
self.update ()
class BacktraceViewer (Gtk.Box): class BacktraceViewer (Gtk.Box):
class ThreadStore (Gtk.ListStore): class ThreadStore (Gtk.ListStore):
INDEX = 0 INDEX = 0
@ -1534,6 +1544,8 @@ class BacktraceViewer (Gtk.Box):
orientation = Gtk.Orientation.HORIZONTAL, orientation = Gtk.Orientation.HORIZONTAL,
**kwargs) **kwargs)
self.needs_update = True
vbox = Gtk.Box (orientation = Gtk.Orientation.VERTICAL) vbox = Gtk.Box (orientation = Gtk.Orientation.VERTICAL)
self.pack_start (vbox, False, False, 0) self.pack_start (vbox, False, False, 0)
vbox.show () vbox.show ()
@ -1687,8 +1699,6 @@ class BacktraceViewer (Gtk.Box):
selection.connect ("change-complete", self.selection_change_complete) selection.connect ("change-complete", self.selection_change_complete)
self.selection_change_complete (selection)
@GObject.Property (type = bool, default = False) @GObject.Property (type = bool, default = False)
def available (self): def available (self):
sel = selection.get_effective_selection () sel = selection.get_effective_selection ()
@ -1700,7 +1710,12 @@ class BacktraceViewer (Gtk.Box):
return False return False
def selection_change_complete (self, selection): def update (self):
if not self.needs_update or not self.available:
return
self.needs_update = False
tid = None tid = None
sel_rows = self.thread_tree.get_selection ().get_selected_rows ()[1] sel_rows = self.thread_tree.get_selection ().get_selected_rows ()[1]
@ -1708,7 +1723,6 @@ class BacktraceViewer (Gtk.Box):
if sel_rows: if sel_rows:
tid = self.thread_store[sel_rows[0]][self.ThreadStore.ID] tid = self.thread_store[sel_rows[0]][self.ThreadStore.ID]
if self.available:
i, = selection.get_effective_selection () i, = selection.get_effective_selection ()
self.thread_store.clear () self.thread_store.clear ()
@ -1723,6 +1737,17 @@ class BacktraceViewer (Gtk.Box):
if thread.id == tid: if thread.id == tid:
self.thread_tree.get_selection ().select_iter (iter) self.thread_tree.get_selection ().select_iter (iter)
def do_map (self):
self.update ()
Gtk.Box.do_map (self)
def selection_change_complete (self, selection):
self.needs_update = True
if self.get_mapped ():
self.update ()
self.notify ("available") self.notify ("available")
def threads_row_activated (self, tree, path, col): def threads_row_activated (self, tree, path, col):
@ -1968,6 +1993,7 @@ class ProfileViewer (Gtk.ScrolledWindow):
col.set_cell_data_func (cell, col.set_cell_data_func (cell,
format_percentage_col, store.INCLUSIVE) format_percentage_col, store.INCLUSIVE)
if id:
self.update () self.update ()
def update (self): def update (self):
@ -2217,13 +2243,14 @@ class ProfileViewer (Gtk.ScrolledWindow):
) )
self.adjustment_changed_handler = None self.adjustment_changed_handler = None
self.needs_update = True
profile = self.Profile () profile = self.Profile ()
self.root_profile = profile self.root_profile = profile
self.add (profile) self.add (profile)
profile.show () profile.show ()
selection.connect ("change-complete", lambda *args: self.update ()) selection.connect ("change-complete", self.selection_change_complete)
profile.connect ("subprofile-added", self.subprofile_added) profile.connect ("subprofile-added", self.subprofile_added)
@ -2237,9 +2264,24 @@ class ProfileViewer (Gtk.ScrolledWindow):
return False return False
def update (self): def update (self):
if self.available: if not self.needs_update or not self.available:
return
self.needs_update = False
self.root_profile.update () self.root_profile.update ()
def do_map (self):
self.update ()
Gtk.ScrolledWindow.do_map (self)
def selection_change_complete (self, selection):
self.needs_update = True
if self.get_mapped ():
self.update ()
self.notify ("available") self.notify ("available")
def subprofile_added (self, profile, subprofile): def subprofile_added (self, profile, subprofile):