[or-cvs] r23978: {arm} Making proc resolution configurable (enabled/disabled via th (in arm/trunk: . src/util)

Damian Johnson atagar1 at gmail.com
Thu Dec 23 16:15:35 UTC 2010


Author: atagar
Date: 2010-12-23 16:15:35 +0000 (Thu, 23 Dec 2010)
New Revision: 23978

Modified:
   arm/trunk/TODO
   arm/trunk/armrc.sample
   arm/trunk/src/util/connections.py
   arm/trunk/src/util/procTools.py
   arm/trunk/src/util/sysTools.py
Log:
Making proc resolution configurable (enabled/disabled via the armrc).



Modified: arm/trunk/TODO
===================================================================
--- arm/trunk/TODO	2010-12-23 15:54:39 UTC (rev 23977)
+++ arm/trunk/TODO	2010-12-23 16:15:35 UTC (rev 23978)
@@ -86,6 +86,7 @@
             - http://www.linuxjournal.com/article/5737
 
 - Bugs
+  * The default resolver isn't configurable.
   * The cpu usage spikes for scrollable content when the key's held. Try
     coalescing the events.
   * The manpage layout is system dependent, so the scraper needs to be more

Modified: arm/trunk/armrc.sample
===================================================================
--- arm/trunk/armrc.sample	2010-12-23 15:54:39 UTC (rev 23977)
+++ arm/trunk/armrc.sample	2010-12-23 16:15:35 UTC (rev 23978)
@@ -10,6 +10,11 @@
 queries.connections.minRate 5
 queries.refreshRate.rate 5
 
+# Read the proc contents directly instead of calling ps, netstat, and other
+# resolvers. This provides very sizable performance benefits (around 90%
+# faster lookups) but this is only available on Linux.
+queries.useProc true
+
 # Renders the interface with color if set and the terminal supports it
 features.colorInterface true
 

Modified: arm/trunk/src/util/connections.py
===================================================================
--- arm/trunk/src/util/connections.py	2010-12-23 15:54:39 UTC (rev 23977)
+++ arm/trunk/src/util/connections.py	2010-12-23 16:15:35 UTC (rev 23978)
@@ -237,12 +237,17 @@
   """
   
   if osType == None: osType = os.uname()[0]
+  
   if osType == "FreeBSD":
-    return [CMD_BSD_SOCKSTAT, CMD_BSD_PROCSTAT, CMD_LSOF]
-  elif osType == "Linux":
-    return [CMD_PROC, CMD_NETSTAT, CMD_SOCKSTAT, CMD_LSOF, CMD_SS]
+    resolvers = [CMD_BSD_SOCKSTAT, CMD_BSD_PROCSTAT, CMD_LSOF]
   else:
-    return [CMD_NETSTAT, CMD_SOCKSTAT, CMD_LSOF, CMD_SS]
+    resolvers = [CMD_NETSTAT, CMD_SOCKSTAT, CMD_LSOF, CMD_SS]
+  
+  # proc resolution, by far, outperforms the others so defaults to this is able
+  if procTools.isProcAvailable():
+    resolvers = [CMD_PROC] + resolvers
+  
+  return resolvers
 
 class ConnectionResolver(threading.Thread):
   """

Modified: arm/trunk/src/util/procTools.py
===================================================================
--- arm/trunk/src/util/procTools.py	2010-12-23 15:54:39 UTC (rev 23977)
+++ arm/trunk/src/util/procTools.py	2010-12-23 16:15:35 UTC (rev 23978)
@@ -27,11 +27,20 @@
 CLOCK_TICKS = os.sysconf(os.sysconf_names["SC_CLK_TCK"])
 STAT_COMMAND, STAT_CPU_UTIME, STAT_CPU_STIME, STAT_START_TIME = range(4)
 
-CONFIG = {"log.procCallMade": log.DEBUG}
+CONFIG = {"queries.useProc": True,
+          "log.procCallMade": log.DEBUG}
 
 def loadConfig(config):
   config.update(CONFIG)
 
+def isProcAvailable():
+  """
+  Provides true if configured to use proc resolution and it's available on the
+  platform, false otherwise.
+  """
+  
+  return CONFIG["queries.useProc"] and os.uname()[0] == "Linux"
+
 def getSystemStartTime():
   """
   Provides the unix time (seconds since epoch) when the system started.

Modified: arm/trunk/src/util/sysTools.py
===================================================================
--- arm/trunk/src/util/sysTools.py	2010-12-23 15:54:39 UTC (rev 23977)
+++ arm/trunk/src/util/sysTools.py	2010-12-23 16:15:35 UTC (rev 23978)
@@ -78,8 +78,8 @@
 
 def getProcessName(pid, default = None, cacheFailure = True):
   """
-  Provides the name associated with the given process id. This is platform
-  specific and only implemented for Linux.
+  Provides the name associated with the given process id. This isn't available
+  on all platforms.
   
   Arguments:
     pid          - process id for the process being returned
@@ -93,7 +93,7 @@
     return PROCESS_NAME_CACHE[pid]
   
   processName, raisedExc = "", None
-  if os.uname()[0] == "Linux":
+  if procTools.isProcAvailable():
     try:
       processName = procTools.getStats(pid, procTools.STAT_COMMAND)[0]
     except IOError, exc:



More information about the tor-commits mailing list