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

[tor-commits] [nyx/master] Update graph title more infrequently



commit 59048949769bb90e3d633215d25f7f3774d16306
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Sep 28 15:21:17 2017 -0700

    Update graph title more infrequently
    
    There's no point in fetching graph title stats every second. These change on an
    hourly basis. Caching this and skipping vline when there's nothing to display
    drops our cpu usage when idle by 70% (from 1% to 0.3% on my system).
---
 nyx/curses.py      |  4 +--
 nyx/panel/graph.py | 72 ++++++++++++++++++++++++++++++------------------------
 2 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/nyx/curses.py b/nyx/curses.py
index 73db19e..349572e 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -906,7 +906,7 @@ class _Subwindow(object):
     char = kwargs.get('char', curses.ACS_HLINE)
     char = ord(char) if isinstance(char, str) else char
 
-    if self.width > x and self.height > y:
+    if self.width > x and self.height > y and length > 0:
       try:
         self._curses_subwindow.hline(max(0, y), max(0, x), char | curses_attr(*attr), min(length, self.width - x))
       except:
@@ -916,7 +916,7 @@ class _Subwindow(object):
     char = kwargs.get('char', curses.ACS_VLINE)
     char = ord(char) if isinstance(char, str) else char
 
-    if self.width > x and self.height > y:
+    if self.width > x and self.height > y and length > 0:
       try:
         self._curses_subwindow.vline(max(0, y), max(0, x), char | curses_attr(*attr), min(length, self.height - y))
       except:
diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index e385fe6..f62ce55 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -50,6 +50,7 @@ PRIMARY_COLOR, SECONDARY_COLOR = GREEN, CYAN
 ACCOUNTING_RATE = 5
 DEFAULT_CONTENT_HEIGHT = 4  # space needed for labeling above and below the graph
 WIDE_LABELING_GRAPH_COL = 50  # minimum graph columns to use wide spacing for x-axis labels
+TITLE_UPDATE_RATE = 30
 
 
 def conf_handler(key, value):
@@ -87,6 +88,41 @@ CONFIG = conf.config_dict('nyx', {
 }, conf_handler)
 
 
+def _bandwidth_title_stats():
+  controller = tor_controller()
+
+  stats = []
+  bw_rate = controller.get_effective_rate(None)
+  bw_burst = controller.get_effective_rate(None, burst = True)
+
+  if bw_rate and bw_burst:
+    bw_rate_label = _size_label(bw_rate)
+    bw_burst_label = _size_label(bw_burst)
+
+    # if both are using rounded values then strip off the '.0' decimal
+
+    if '.0' in bw_rate_label and '.0' in bw_burst_label:
+      bw_rate_label = bw_rate_label.replace('.0', '')
+      bw_burst_label = bw_burst_label.replace('.0', '')
+
+    stats.append('limit: %s/s' % bw_rate_label)
+    stats.append('burst: %s/s' % bw_burst_label)
+
+  my_router_status_entry = nyx.tracker.get_consensus_tracker().my_router_status_entry()
+  measured_bw = getattr(my_router_status_entry, 'bandwidth', None)
+
+  if measured_bw:
+    stats.append('measured: %s/s' % _size_label(measured_bw))
+  else:
+    my_server_descriptor = controller.get_server_descriptor(default = None)
+    observed_bw = getattr(my_server_descriptor, 'observed_bandwidth', None)
+
+    if observed_bw:
+      stats.append('observed: %s/s' % _size_label(observed_bw))
+
+  return stats
+
+
 class GraphData(object):
   """
   Graphable statistical information.
@@ -267,6 +303,7 @@ class BandwidthStats(GraphCategory):
 
   def __init__(self, clone = None):
     GraphCategory.__init__(self, clone)
+    self._title_last_updated = None
 
     if not clone:
       # fill in past bandwidth information
@@ -320,38 +357,9 @@ class BandwidthStats(GraphCategory):
       ', total: %s' % _size_label(self.secondary.total),
     ]
 
-    controller = tor_controller()
-
-    stats = []
-    bw_rate = controller.get_effective_rate(None)
-    bw_burst = controller.get_effective_rate(None, burst = True)
-
-    if bw_rate and bw_burst:
-      bw_rate_label = _size_label(bw_rate)
-      bw_burst_label = _size_label(bw_burst)
-
-      # if both are using rounded values then strip off the '.0' decimal
-
-      if '.0' in bw_rate_label and '.0' in bw_burst_label:
-        bw_rate_label = bw_rate_label.replace('.0', '')
-        bw_burst_label = bw_burst_label.replace('.0', '')
-
-      stats.append('limit: %s/s' % bw_rate_label)
-      stats.append('burst: %s/s' % bw_burst_label)
-
-    my_router_status_entry = nyx.tracker.get_consensus_tracker().my_router_status_entry()
-    measured_bw = getattr(my_router_status_entry, 'bandwidth', None)
-
-    if measured_bw:
-      stats.append('measured: %s/s' % _size_label(measured_bw))
-    else:
-      my_server_descriptor = controller.get_server_descriptor(default = None)
-      observed_bw = getattr(my_server_descriptor, 'observed_bandwidth', None)
-
-      if observed_bw:
-        stats.append('observed: %s/s' % _size_label(observed_bw))
-
-    self._title_stats = stats
+    if not self._title_last_updated or time.time() - self._title_last_updated > TITLE_UPDATE_RATE:
+      self._title_stats = _bandwidth_title_stats()
+      self._title_last_updated = time.time()
 
 
 class ConnectionStats(GraphCategory):



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