[tor-commits] [arm/master] Splitting get_header_label()
atagar at torproject.org
atagar at torproject.org
Tue Sep 16 16:52:20 UTC 2014
commit d97126ec69c7980c77babbee566720a1babebc20
Author: Damian Johnson <atagar at torproject.org>
Date: Tue Sep 16 09:50:36 2014 -0700
Splitting get_header_label()
We fetched both our primary and secondary headers via get_header_label() but on
reflection it's cleaner to split these up. This improves the connection and
resource stats, but couldn't be applied to the bandwidth stats since those are
a convoluted mess. Fun.
---
arm/graphing/bandwidth_stats.py | 6 ++++++
arm/graphing/conn_stats.py | 15 ++++++---------
arm/graphing/graph_panel.py | 9 ++++-----
arm/graphing/resource_stats.py | 20 ++++++++++----------
4 files changed, 26 insertions(+), 24 deletions(-)
diff --git a/arm/graphing/bandwidth_stats.py b/arm/graphing/bandwidth_stats.py
index 4fc01c6..80c105b 100644
--- a/arm/graphing/bandwidth_stats.py
+++ b/arm/graphing/bandwidth_stats.py
@@ -233,6 +233,12 @@ class BandwidthStats(graph_panel.GraphStats):
else:
return label
+ def primary_header(self, width):
+ return self.get_header_label(width, True)
+
+ def secondary_header(self, width):
+ return self.get_header_label(width, False)
+
def get_header_label(self, width, is_primary):
graph_type = 'Download' if is_primary else 'Upload'
stats = ['']
diff --git a/arm/graphing/conn_stats.py b/arm/graphing/conn_stats.py
index a69fc33..c5b1c83 100644
--- a/arm/graphing/conn_stats.py
+++ b/arm/graphing/conn_stats.py
@@ -16,9 +16,6 @@ class ConnStats(graph_panel.GraphStats):
outbound. Control connections are excluded from counts.
"""
- def __init__(self):
- graph_panel.GraphStats.__init__(self)
-
def clone(self, new_copy=None):
if not new_copy:
new_copy = ConnStats()
@@ -53,10 +50,10 @@ class ConnStats(graph_panel.GraphStats):
def get_title(self, width):
return 'Connection Count:'
- def get_header_label(self, width, is_primary):
- avg = (self.primary_total if is_primary else self.secondary_total) / max(1, self.tick)
+ def primary_header(self, width):
+ avg = self.primary_total / max(1, self.tick)
+ return 'Inbound (%s, avg: %s):' % (self.last_primary, avg)
- if is_primary:
- return 'Inbound (%s, avg: %s):' % (self.last_primary, avg)
- else:
- return 'Outbound (%s, avg: %s):' % (self.last_secondary, avg)
+ def secondary_header(self, width):
+ avg = self.secondary_total / max(1, self.tick)
+ return 'Outbound (%s, avg: %s):' % (self.last_secondary, avg)
diff --git a/arm/graphing/graph_panel.py b/arm/graphing/graph_panel.py
index 5bf61d1..818699f 100644
--- a/arm/graphing/graph_panel.py
+++ b/arm/graphing/graph_panel.py
@@ -174,11 +174,10 @@ class GraphStats:
return ''
- def get_header_label(self, width, is_primary):
- """
- Provides labeling presented at the top of the graph.
- """
+ def primary_header(self, width):
+ return ''
+ def secondary_header(self, width):
return ''
def get_color(self, is_primary):
@@ -435,7 +434,7 @@ class GraphPanel(panel.Panel):
# top labels
- left, right = param.get_header_label(width / 2, True), param.get_header_label(width / 2, False)
+ left, right = param.primary_header(width / 2), param.secondary_header(width / 2)
if left:
self.addstr(1, 0, left, curses.A_BOLD, primary_color)
diff --git a/arm/graphing/resource_stats.py b/arm/graphing/resource_stats.py
index 7b9dfc9..d38803a 100644
--- a/arm/graphing/resource_stats.py
+++ b/arm/graphing/resource_stats.py
@@ -27,19 +27,19 @@ class ResourceStats(graph_panel.GraphStats):
def get_title(self, width):
return 'System Resources:'
- def get_header_label(self, width, is_primary):
- avg = (self.primary_total if is_primary else self.secondary_total) / max(1, self.tick)
- last_amount = self.last_primary if is_primary else self.last_secondary
+ def primary_header(self, width):
+ avg = self.primary_total / max(1, self.tick)
+ return 'CPU (%0.1f%%, avg: %0.1f%%):' % (self.last_primary, avg)
- if is_primary:
- return 'CPU (%0.1f%%, avg: %0.1f%%):' % (last_amount, avg)
- else:
- # memory sizes are converted from MB to B before generating labels
+ def secondary_header(self, width):
+ # memory sizes are converted from MB to B before generating labels
- usage_label = str_tools.size_label(last_amount * 1048576, 1)
- avg_label = str_tools.size_label(avg * 1048576, 1)
+ usage_label = str_tools.size_label(self.last_secondary * 1048576, 1)
- return 'Memory (%s, avg: %s):' % (usage_label, avg_label)
+ avg = self.secondary_total / max(1, self.tick)
+ avg_label = str_tools.size_label(avg * 1048576, 1)
+
+ return 'Memory (%s, avg: %s):' % (usage_label, avg_label)
def event_tick(self):
"""
More information about the tor-commits
mailing list