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

atagar at torproject.org atagar at torproject.org
Tue Sep 16 16:52:20 UTC 2014


commit b65aa52951b8befd2113fe5501c23996d411487d
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Sep 16 08:34:21 2014 -0700

    Revising ResourceStats
    
    Just a little cleanup from earlier mass refactoring. We were fetching but not
    using tor's pid, set an unused run_count attribute, and registered zero
    cpu/memory if between tracker samplings.
---
 arm/graphing/resource_stats.py |   22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/arm/graphing/resource_stats.py b/arm/graphing/resource_stats.py
index 1f3998f..7b9dfc9 100644
--- a/arm/graphing/resource_stats.py
+++ b/arm/graphing/resource_stats.py
@@ -5,7 +5,6 @@ Tracks the system resource usage (cpu and memory) of the tor process.
 import arm.util.tracker
 
 from arm.graphing import graph_panel
-from arm.util import tor_controller
 
 from stem.util import str_tools
 
@@ -17,8 +16,7 @@ class ResourceStats(graph_panel.GraphStats):
 
   def __init__(self):
     graph_panel.GraphStats.__init__(self)
-    self.query_pid = tor_controller().get_pid(None)
-    self.last_counter = None
+    self._last_counter = None
 
   def clone(self, new_copy=None):
     if not new_copy:
@@ -48,16 +46,12 @@ class ResourceStats(graph_panel.GraphStats):
     Fetch the cached measurement of resource usage from the ResourceTracker.
     """
 
-    primary, secondary = 0, 0
+    resource_tracker = arm.util.tracker.get_resource_tracker()
 
-    if self.query_pid:
-      resource_tracker = arm.util.tracker.get_resource_tracker()
+    if resource_tracker and resource_tracker.run_counter() != self._last_counter:
+      resources = resource_tracker.get_value()
+      primary = resources.cpu_sample * 100  # decimal percentage to whole numbers
+      secondary = resources.memory_bytes / 1048576  # translate size to MB so axis labels are short
 
-      if resource_tracker and resource_tracker.run_counter() != self.last_counter:
-        resources = resource_tracker.get_value()
-        self.last_counter = resource_tracker.run_counter()
-        primary = resources.cpu_sample * 100  # decimal percentage to whole numbers
-        secondary = resources.memory_bytes / 1048576  # translate size to MB so axis labels are short
-        self.run_count = resource_tracker.run_counter()
-
-    self._process_event(primary, secondary)
+      self._last_counter = resource_tracker.run_counter()
+      self._process_event(primary, secondary)





More information about the tor-commits mailing list