[or-cvs] r23913: {arm} Logging a warning (with advice) when arm's cpu usage is high (in arm/trunk: . src/interface)

Damian Johnson atagar1 at gmail.com
Thu Dec 9 17:49:13 UTC 2010


Author: atagar
Date: 2010-12-09 17:49:12 +0000 (Thu, 09 Dec 2010)
New Revision: 23913

Modified:
   arm/trunk/armrc.sample
   arm/trunk/src/interface/controller.py
Log:
Logging a warning (with advice) when arm's cpu usage is high (thanks to Clete)



Modified: arm/trunk/armrc.sample
===================================================================
--- arm/trunk/armrc.sample	2010-12-09 17:25:25 UTC (rev 23912)
+++ arm/trunk/armrc.sample	2010-12-09 17:49:12 UTC (rev 23913)
@@ -185,6 +185,7 @@
 # Runlevels at which arm logs its events
 log.startTime INFO
 log.refreshRate DEBUG
+log.highCpuUsage WARN
 log.configEntryNotFound NONE
 log.configEntryUndefined NOTICE
 log.configEntryTypeError NOTICE

Modified: arm/trunk/src/interface/controller.py
===================================================================
--- arm/trunk/src/interface/controller.py	2010-12-09 17:25:25 UTC (rev 23912)
+++ arm/trunk/src/interface/controller.py	2010-12-09 17:49:12 UTC (rev 23913)
@@ -54,6 +54,7 @@
           "features.graph.bw.prepopulate": True,
           "log.startTime": log.INFO,
           "log.refreshRate": log.DEBUG,
+          "log.highCpuUsage": log.WARN,
           "log.configEntryUndefined": log.NOTICE,
           "log.torrc.validation.torStateDiffers": log.WARN,
           "log.torrc.validation.unnecessaryTorrcEntries": log.WARN}
@@ -631,6 +632,10 @@
   initTime = time.time() - startTime
   log.log(CONFIG["log.startTime"], "arm started (initialization took %0.3f seconds)" % initTime)
   
+  # attributes to give a WARN level event if arm's resource usage is too high
+  isResourceWarningGiven = False
+  lastResourceCheck = startTime
+  
   # TODO: come up with a nice, clean method for other threads to immediately
   # terminate the draw loop and provide a stacktrace
   while True:
@@ -722,6 +727,20 @@
         
         log.log(CONFIG["log.refreshRate"], "refresh rate: %0.3f seconds, average cpu usage: %0.3f%%" % (currentTime - redrawStartTime, 100 * cpuAvg))
         lastPerformanceLog = currentTime
+        
+        # once per minute check if the sustained cpu usage is above 5%, if so
+        # then give a warning (and if able, some advice for lowering it)
+        if not isResourceWarningGiven and currentTime > (lastResourceCheck + 60):
+          if cpuAvg >= 0.05:
+            msg = "Arm's cpu usage is high (averaging %0.3f%%)." % (100 * cpuAvg)
+            
+            if not isBlindMode:
+              msg += " You could lower it by dropping the connection data (running as \"arm -b\")."
+            
+            log.log(CONFIG["log.highCpuUsage"], msg)
+            isResourceWarningGiven = True
+          
+          lastResourceCheck = currentTime
     finally:
       panel.CURSES_LOCK.release()
     



More information about the tor-commits mailing list