[tor-commits] [arm/master] Use treestore and group circuit entries by header, cache the model.

atagar at torproject.org atagar at torproject.org
Fri Jul 15 01:07:02 UTC 2011


commit 0b58312fe6b543cef4193c7f1cda36e801b5d36e
Author: Kamran Riaz Khan <krkhan at inspirated.com>
Date:   Fri Jul 8 18:32:56 2011 +0500

    Use treestore and group circuit entries by header, cache the model.
    
    The treestore is updated only if the (local, foreign) tuple for one of
    the entries is not found in cache. Otherwise, only the time column
    is updated.
---
 src/gui/arm.xml                  |    4 +-
 src/gui/connections/connPanel.py |   43 ++++++++++++++++++++++++++++++++-----
 src/starter.py                   |    2 +-
 3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/src/gui/arm.xml b/src/gui/arm.xml
index dca5f33..0aafb28 100644
--- a/src/gui/arm.xml
+++ b/src/gui/arm.xml
@@ -59,7 +59,7 @@
       </row>
     </data>
   </object>
-  <object class="GtkListStore" id="liststore_conn">
+  <object class="GtkTreeStore" id="treestore_conn">
     <columns>
       <!-- column-name origin -->
       <column type="gchararray"/>
@@ -432,7 +432,7 @@
                               <object class="GtkTreeView" id="treeview_conn">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
-                                <property name="model">liststore_conn</property>
+                                <property name="model">treestore_conn</property>
                                 <property name="headers_visible">False</property>
                                 <property name="headers_clickable">False</property>
                                 <property name="search_column">0</property>
diff --git a/src/gui/connections/connPanel.py b/src/gui/connections/connPanel.py
index cbabc41..ad57878 100644
--- a/src/gui/connections/connPanel.py
+++ b/src/gui/connections/connPanel.py
@@ -11,10 +11,10 @@ from collections import deque
 import gobject
 import gtk
 
-from cli.connections import connEntry
+from cli.connections import circEntry, connEntry
 from cli.connections.connPanel import ConnectionPanel as CliConnectionPanel
 from TorCtl import TorCtl
-from util import connections, uiTools, torTools
+from util import connections, sysTools, uiTools, torTools
 
 REFRESH_RATE = 3
 
@@ -23,8 +23,12 @@ class ConnectionPanel(CliConnectionPanel):
     CliConnectionPanel.__init__(self, None)
 
     self.builder = builder
+    self.cache = {}
 
-    self.resolver = connections.getResolver('tor')
+    conn = torTools.getConn()
+    torPid = conn.getMyPid()
+    torCmdName = sysTools.getProcessName(torPid, "tor")
+    connections.getResolver(torCmdName, torPid, "tor")
 
     gobject.timeout_add(3000, self._fill_entries)
 
@@ -37,8 +41,25 @@ class ConnectionPanel(CliConnectionPanel):
     label = self.builder.get_object('label_conn_top')
     label.set_text(self._title)
 
-    liststore = self.builder.get_object('liststore_conn')
-    liststore.clear()
+    treestore = self.builder.get_object('treestore_conn')
+
+    # first pass checks whether we have enough entries cached to not update the treeview
+    for (index, line) in enumerate(self._entryLines):
+      local = "%s:%s" % (line.local.ipAddr, line.local.port)
+      foreign = "%s:%s" % (line.foreign.ipAddr, line.foreign.port)
+      cachekey = (local, foreign)
+      if self.cache.has_key(cachekey):
+        timeLabel = "%d s" % (time.time() - line.startTime)
+        treestore.set_value(self.cache[cachekey], 2, timeLabel)
+      else:
+        break
+
+    if index == len(self._entryLines) - 1:
+      return
+
+    treestore.clear()
+
+    headeriter = None
 
     for line in self._entryLines:
       if isinstance(line, connEntry.ConnectionLine) and line.isUnresolvedApp():
@@ -48,7 +69,17 @@ class ConnectionPanel(CliConnectionPanel):
       foreign = "%s:%s" % (line.foreign.ipAddr, line.foreign.port)
       timeLabel = "%d s" % (time.time() - line.startTime)
       row = (local, foreign, timeLabel, line.baseType, 'black')
-      liststore.append(row)
+
+      if isinstance(line, circEntry.CircHeaderLine):
+        currentiter = treestore.append(None, row)
+        headeriter = currentiter
+      elif isinstance(line, circEntry.CircLine):
+        currentiter = treestore.append(headeriter, row)
+      else:
+        currentiter = treestore.append(None, row)
+
+      cachekey = (local, foreign)
+      self.cache[cachekey] = currentiter
 
     self.valsLock.release()
 
diff --git a/src/starter.py b/src/starter.py
index 1b6049a..5518caa 100644
--- a/src/starter.py
+++ b/src/starter.py
@@ -30,7 +30,7 @@ import util.uiTools
 import TorCtl.TorCtl
 import TorCtl.TorUtil
 
-INCLUDE_GUI = False
+INCLUDE_GUI = True
 LOG_DUMP_PATH = os.path.expanduser("~/.arm/log")
 DEFAULT_CONFIG = os.path.expanduser("~/.arm/armrc")
 CONFIG = {"startup.controlPassword": None,





More information about the tor-commits mailing list