commit 4c5c20be5c30cb120c61a58e47fdfb821932cc75
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sun Feb 16 04:25:22 2014 -0800
Dropping the notion of static header parameters
The header panel split the attributes it used into two camps: static and
volatile. The reason for this is that we wanted to avoid repeatedly querying
things that rarely change. However, the stem controller caches static values
for us anyway so we can drop this.
The only additional burden this is adding is for the process' start time. This
is now fetched on each call - haven't yet decided how we want to handle those.
---
arm/header_panel.py | 150 +++++++++++++++++++++++++--------------------------
1 file changed, 73 insertions(+), 77 deletions(-)
diff --git a/arm/header_panel.py b/arm/header_panel.py
index de3c5a8..2affaad 100644
--- a/arm/header_panel.py
+++ b/arm/header_panel.py
@@ -98,7 +98,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
self.vals = {}
self.vals_lock = threading.RLock()
- self._update(True)
+ self._update()
# listens for tor reload (sighup) events
@@ -494,7 +494,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
initial_height = self.get_height()
self._is_tor_connected = True
self._halt_time = None
- self._update(True)
+ self._update()
if self.get_height() != initial_height:
# We're toggling between being a relay and client, causing the height
@@ -511,125 +511,121 @@ class HeaderPanel(panel.Panel, threading.Thread):
self._update()
self.redraw(True)
- def _update(self, set_static=False):
+ def _update(self):
"""
Updates stats in the vals mapping. By default this just revises volatile
attributes.
-
- Arguments:
- set_static - resets all parameters, including relatively static values
"""
self.vals_lock.acquire()
controller = tor_controller()
- if set_static:
- # version is truncated to first part, for instance:
- # 0.2.2.13-alpha (git-feb8c1b5f67f2c6f) -> 0.2.2.13-alpha
+ # version is truncated to first part, for instance:
+ # 0.2.2.13-alpha (git-feb8c1b5f67f2c6f) -> 0.2.2.13-alpha
- self.vals["tor/version"] = controller.get_info("version", "Unknown").split()[0]
- self.vals["tor/versionStatus"] = controller.get_info("status/version/current", "Unknown")
- self.vals["tor/nickname"] = controller.get_conf("Nickname", "")
- self.vals["tor/or_port"] = controller.get_conf("ORPort", "0")
- self.vals["tor/dir_port"] = controller.get_conf("DirPort", "0")
- self.vals["tor/control_port"] = controller.get_conf("ControlPort", "0")
- self.vals["tor/socketPath"] = controller.get_conf("ControlSocket", "")
- self.vals["tor/isAuthPassword"] = controller.get_conf("HashedControlPassword", None) is not None
- self.vals["tor/isAuthCookie"] = controller.get_conf("CookieAuthentication", None) == "1"
+ self.vals['tor/version'] = str(controller.get_version('Unknown')).split()[0]
+ self.vals['tor/versionStatus'] = controller.get_info('status/version/current', 'Unknown')
+ self.vals['tor/nickname'] = controller.get_conf('Nickname', '')
+ self.vals['tor/or_port'] = controller.get_conf('ORPort', '0')
+ self.vals['tor/dir_port'] = controller.get_conf('DirPort', '0')
+ self.vals['tor/control_port'] = controller.get_conf('ControlPort', '0')
+ self.vals['tor/socketPath'] = controller.get_conf('ControlSocket', '')
+ self.vals['tor/isAuthPassword'] = controller.get_conf('HashedControlPassword', None) is not None
+ self.vals['tor/isAuthCookie'] = controller.get_conf('CookieAuthentication', None) == '1'
- # orport is reported as zero if unset
+ # orport is reported as zero if unset
- if self.vals["tor/or_port"] == "0":
- self.vals["tor/or_port"] = ""
+ if self.vals['tor/or_port'] == '0':
+ self.vals['tor/or_port'] = ''
- # overwrite address if ORListenAddress is set (and possibly or_port too)
+ # overwrite address if ORListenAddress is set (and possibly or_port too)
- self.vals["tor/orListenAddr"] = ""
- listen_addr = controller.get_conf("ORListenAddress", None)
+ self.vals['tor/orListenAddr'] = ''
+ listen_addr = controller.get_conf('ORListenAddress', None)
- if listen_addr:
- if ":" in listen_addr:
- # both ip and port overwritten
- self.vals["tor/orListenAddr"] = listen_addr[:listen_addr.find(":")]
- self.vals["tor/or_port"] = listen_addr[listen_addr.find(":") + 1:]
- else:
- self.vals["tor/orListenAddr"] = listen_addr
+ if listen_addr:
+ if ':' in listen_addr:
+ # both ip and port overwritten
+ self.vals['tor/orListenAddr'] = listen_addr[:listen_addr.find(':')]
+ self.vals['tor/or_port'] = listen_addr[listen_addr.find(':') + 1:]
+ else:
+ self.vals['tor/orListenAddr'] = listen_addr
- # fetch exit policy (might span over multiple lines)
+ # fetch exit policy (might span over multiple lines)
- policy_entries = []
+ policy_entries = []
- for exit_policy in controller.get_conf("ExitPolicy", [], True):
- policy_entries += [policy.strip() for policy in exit_policy.split(",")]
+ for exit_policy in controller.get_conf('ExitPolicy', [], True):
+ policy_entries += [policy.strip() for policy in exit_policy.split(',')]
- self.vals["tor/exit_policy"] = ", ".join(policy_entries)
+ self.vals['tor/exit_policy'] = ', '.join(policy_entries)
- # file descriptor limit for the process, if this can't be determined
- # then the limit is None
+ # file descriptor limit for the process, if this can't be determined
+ # then the limit is None
- fd_limit = controller.get_info('process/descriptor-limit', '-1')
+ fd_limit = controller.get_info('process/descriptor-limit', '-1')
- if fd_limit != '-1' and fd_limit.isdigit():
- self.vals["tor/fd_limit"] = int(fd_limit)
- else:
- self.vals["tor/fd_limit"] = None
+ if fd_limit != '-1' and fd_limit.isdigit():
+ self.vals['tor/fd_limit'] = int(fd_limit)
+ else:
+ self.vals['tor/fd_limit'] = None
- # system information
+ # system information
- uname_vals = os.uname()
- self.vals["sys/hostname"] = uname_vals[1]
- self.vals["sys/os"] = uname_vals[0]
- self.vals["sys/version"] = uname_vals[2]
+ uname_vals = os.uname()
+ self.vals['sys/hostname'] = uname_vals[1]
+ self.vals['sys/os'] = uname_vals[0]
+ self.vals['sys/version'] = uname_vals[2]
- self.vals["tor/pid"] = controller.get_pid("")
+ self.vals['tor/pid'] = controller.get_pid('')
- try:
- start_time = system.get_start_time(controller.get_pid())
- except:
- start_time = None
+ try:
+ start_time = system.get_start_time(controller.get_pid())
+ except:
+ start_time = None
- self.vals["tor/start_time"] = start_time if start_time else ""
+ self.vals['tor/start_time'] = start_time if start_time else ''
- # reverts volatile parameters to defaults
+ # reverts volatile parameters to defaults
- self.vals["tor/fingerprint"] = "Unknown"
- self.vals["tor/flags"] = []
- self.vals["tor/fd_used"] = 0
- self.vals["stat/%torCpu"] = "0"
- self.vals["stat/%armCpu"] = "0"
- self.vals["stat/rss"] = "0"
- self.vals["stat/%mem"] = "0"
+ self.vals['tor/fingerprint'] = 'Unknown'
+ self.vals['tor/flags'] = []
+ self.vals['tor/fd_used'] = 0
+ self.vals['stat/%torCpu'] = '0'
+ self.vals['stat/%armCpu'] = '0'
+ self.vals['stat/rss'] = '0'
+ self.vals['stat/%mem'] = '0'
# sets volatile parameters
# TODO: This can change, being reported by STATUS_SERVER -> EXTERNAL_ADDRESS
# events. Introduce caching via tor_tools?
- self.vals["tor/address"] = controller.get_info("address", "")
+ self.vals['tor/address'] = controller.get_info('address', '')
- self.vals["tor/fingerprint"] = controller.get_info("fingerprint", self.vals["tor/fingerprint"])
+ self.vals['tor/fingerprint'] = controller.get_info('fingerprint', self.vals['tor/fingerprint'])
- my_fingerprint = controller.get_info("fingerprint", None)
+ my_fingerprint = controller.get_info('fingerprint', None)
if my_fingerprint:
my_status_entry = controller.get_network_status(my_fingerprint)
if my_status_entry:
- self.vals["tor/flags"] = my_status_entry.flags
+ self.vals['tor/flags'] = my_status_entry.flags
# Updates file descriptor usage and logs if the usage is high. If we don't
# have a known limit or it's obviously faulty (being lower than our
# current usage) then omit file descriptor functionality.
- if self.vals["tor/fd_limit"]:
+ if self.vals['tor/fd_limit']:
fd_used = get_file_descriptor_usage(controller.get_pid(None))
- if fd_used and fd_used <= self.vals["tor/fd_limit"]:
- self.vals["tor/fd_used"] = fd_used
+ if fd_used and fd_used <= self.vals['tor/fd_limit']:
+ self.vals['tor/fd_used'] = fd_used
else:
- self.vals["tor/fd_used"] = 0
+ self.vals['tor/fd_used'] = 0
- if self.vals["tor/fd_used"] and self.vals["tor/fd_limit"]:
- fd_percent = 100 * self.vals["tor/fd_used"] / self.vals["tor/fd_limit"]
+ if self.vals['tor/fd_used'] and self.vals['tor/fd_limit']:
+ fd_percent = 100 * self.vals['tor/fd_used'] / self.vals['tor/fd_limit']
msg = "Tor's file descriptor usage is at %i%%." % fd_percent
if fd_percent >= 90 and not self._is_fd_ninety_percent_warned:
@@ -642,14 +638,14 @@ class HeaderPanel(panel.Panel, threading.Thread):
# ps or proc derived resource usage stats
- if self.vals["tor/pid"]:
+ if self.vals['tor/pid']:
resource_tracker = arm.util.tracker.get_resource_tracker()
resources = resource_tracker.get_resource_usage()
self._last_resource_fetch = resource_tracker.run_counter()
- self.vals["stat/%torCpu"] = "%0.1f" % (100 * resources.cpu_sample)
- self.vals["stat/rss"] = str(resources.memory_bytes)
- self.vals["stat/%mem"] = "%0.1f" % (100 * resources.memory_percent)
+ self.vals['stat/%torCpu'] = '%0.1f' % (100 * resources.cpu_sample)
+ self.vals['stat/rss'] = str(resources.memory_bytes)
+ self.vals['stat/%mem'] = '%0.1f' % (100 * resources.memory_percent)
# determines the cpu time for the arm process (including user and system
# time of both the primary and child processes)
@@ -659,7 +655,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
arm_time_delta = current_time - self._arm_cpu_sampling[1]
python_cpu_time = arm_cpu_telta / arm_time_delta
sys_call_cpu_time = 0.0 # TODO: add a wrapper around call() to get this
- self.vals["stat/%armCpu"] = "%0.1f" % (100 * (python_cpu_time + sys_call_cpu_time))
+ self.vals['stat/%armCpu'] = '%0.1f' % (100 * (python_cpu_time + sys_call_cpu_time))
self._arm_cpu_sampling = (total_arm_cpu_time, current_time)
self._last_update = current_time