[tor-commits] [arm/master] Revising ResourceStats class

atagar at torproject.org atagar at torproject.org
Tue Oct 21 15:36:05 UTC 2014


commit 833afb6daee873396e7d33c4ec00adae43225030
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Oct 21 08:29:34 2014 -0700

    Revising ResourceStats class
    
    Nothing much. Main difference is that we only registered stats if we had a new
    measurement. This was incorrect since we're supposed to register an update
    every second (not be limited by the rate of the tracker).
    
    I dislike the bytes => MB => bytes converting. Both this stat and bandwidth do
    this to shorten the y-axis labels but I'm starting to wonder if we should
    sacrifice a little data for proper labeling. Something to decide when revising
    the GraphPanel itself.
---
 arm/graph_panel.py |   20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/arm/graph_panel.py b/arm/graph_panel.py
index e65e623..36967c2 100644
--- a/arm/graph_panel.py
+++ b/arm/graph_panel.py
@@ -377,15 +377,11 @@ class ConnectionStats(GraphCategory):
 
 class ResourceStats(GraphCategory):
   """
-  System resource usage tracker.
+  Tracks cpu and memory usage of the tor process.
   """
 
   TITLE = 'System Resources'
 
-  def __init__(self, clone = None):
-    GraphCategory.__init__(self)
-    self._last_counter = clone._last_counter if clone else None
-
   def primary_header(self, width):
     avg = self.primary.total / max(1, self.primary.tick)
     return 'CPU (%0.1f%%, avg: %0.1f%%):' % (self.primary.latest_value, avg)
@@ -401,17 +397,9 @@ class ResourceStats(GraphCategory):
     return 'Memory (%s, avg: %s):' % (usage_label, avg_label)
 
   def bandwidth_event(self, event):
-    """
-    Fetch the cached measurement of resource usage from the ResourceTracker.
-    """
-
-    resource_tracker = arm.util.tracker.get_resource_tracker()
-
-    if resource_tracker and resource_tracker.run_counter() != self._last_counter:
-      resources = resource_tracker.get_value()
-      self.primary.update(resources.cpu_sample * 100)  # decimal percentage to whole numbers
-      self.secondary.update(resources.memory_bytes / 1048576)  # translate size to MB so axis labels are short
-      self._last_counter = resource_tracker.run_counter()
+    resources = arm.util.tracker.get_resource_tracker().get_value()
+    self.primary.update(resources.cpu_sample * 100)  # decimal percentage to whole numbers
+    self.secondary.update(resources.memory_bytes / 1048576)  # translate size to MB so axis labels are short
 
 
 class GraphPanel(panel.Panel):



More information about the tor-commits mailing list