[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Have the graph panel govern its own redrawing



commit 3fa9ca7547ec1aac76c4375f2ff217bccd899b00
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Oct 19 15:50:42 2014 -0700

    Have the graph panel govern its own redrawing
    
    Graph stats informed the graph panel when they were ready to be redrawn. This
    was kinda weird because it simply happened on a set schedule (it didn't really
    benefit anything). It's simpler if we just do this in the panel itself.
---
 arm/graph_panel.py |   38 +++++++++++---------------------------
 1 file changed, 11 insertions(+), 27 deletions(-)

diff --git a/arm/graph_panel.py b/arm/graph_panel.py
index 1b3158c..c32cc5f 100644
--- a/arm/graph_panel.py
+++ b/arm/graph_panel.py
@@ -159,8 +159,6 @@ class GraphStats(object):
 
       tor_controller().add_event_listener(self.bandwidth_event, stem.control.EventType.BW)
 
-    self._graph_panel = None
-
   def event_tick(self):
     """
     Called when it's time to process another event. All graphs use tor BW
@@ -169,19 +167,6 @@ class GraphStats(object):
 
     pass
 
-  def is_next_tick_redraw(self):
-    """
-    Provides true if the following tick (call to _process_event) will result in
-    being redrawn.
-    """
-
-    if self._graph_panel and self.is_selected and not self._graph_panel.is_paused():
-      # use the minimum of the current refresh rate and the panel's
-      update_rate = int(CONFIG['attr.graph.intervals'].values()[self._graph_panel.update_interval])
-      return (self.primary.tick + 1) % update_rate == 0
-    else:
-      return False
-
   def primary_header(self, width):
     return ''
 
@@ -197,14 +182,9 @@ class GraphStats(object):
     Includes new stats in graphs and notifies associated GraphPanel of changes.
     """
 
-    is_redraw = self.is_next_tick_redraw()
-
     self.primary.update(primary)
     self.secondary.update(secondary)
 
-    if is_redraw and self._graph_panel:
-      self._graph_panel.redraw(True)
-
 
 class BandwidthStats(GraphStats):
   """
@@ -485,6 +465,7 @@ class GraphPanel(panel.Panel):
     self.graph_height = CONFIG['features.graph.height']
     self.current_display = None    # label of the stats currently being displayed
     self._accounting_stats = None
+    self._last_redraw = 0
 
     self.stats = {
       GraphStat.BANDWIDTH: BandwidthStats(),
@@ -494,9 +475,6 @@ class GraphPanel(panel.Panel):
     if CONFIG['features.panels.show.connection']:
       self.stats[GraphStat.CONNECTIONS] = ConnStats()
 
-    for stat in self.stats.values():
-      stat._graph_panel = self
-
     self.set_pause_attr('stats')
     self.set_pause_attr('_accounting_stats')
 
@@ -521,7 +499,9 @@ class GraphPanel(panel.Panel):
       except ValueError as exc:
         log.info(msg('panel.graphing.prepopulation_failure', error = str(exc)))
 
-    tor_controller().add_event_listener(self.bandwidth_event, stem.control.EventType.BW)
+    controller = tor_controller()
+    controller.add_event_listener(self.bandwidth_event, stem.control.EventType.BW)
+    controller.add_status_listener(self.reset_listener)
 
   def bandwidth_event(self, event):
     if not CONFIG['features.graph.bw.accounting.show']:
@@ -535,12 +515,14 @@ class GraphPanel(panel.Panel):
 
         arm.controller.get_controller().redraw()
 
-    # redraws to reflect changes (this especially noticeable when we have
-    # accounting and shut down since it then gives notice of the shutdown)
+    update_rate = int(CONFIG['attr.graph.intervals'].values()[self.update_interval])
 
-    if self.current_display == GraphStat.BANDWIDTH:
+    if time.time() - self._last_redraw > update_rate:
       self.redraw(True)
 
+  def reset_listener(self, controller, event_type, _):
+    self.redraw(True)
+
   def get_update_interval(self):
     """
     Provides the rate that we update the graph at.
@@ -697,6 +679,8 @@ class GraphPanel(panel.Panel):
     if not self.current_display:
       return
 
+    self._last_redraw = time.time()
+
     param = self.get_attr('stats')[self.current_display]
     graph_column = min((width - 10) / 2, CONFIG['features.graph.max_width'])
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits