changeset 356:c6aabf5bd3bc

big KC speedup from not reloading config.n3 constantly
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 11 Jun 2007 02:26:49 +0000
parents 4e60444605f6
children 7771f37252da
files bin/keyboardcomposer bin/lightsim light9/showconfig.py
diffstat 3 files changed, 32 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/bin/keyboardcomposer	Wed Jun 13 06:01:22 2007 +0000
+++ b/bin/keyboardcomposer	Mon Jun 11 02:26:49 2007 +0000
@@ -14,7 +14,7 @@
 from light9.Fadable import Fadable
 from light9.Submaster import Submasters, sub_maxes
 from light9.subclient import SubClient
-from light9 import dmxclient, showconfig, networking
+from light9 import dmxclient, showconfig, networking, prof
 from light9.uihelpers import toplevelat, bindkeys
 from bcf2000 import BCF2000
 
@@ -111,10 +111,10 @@
         try:
             self.sliders = Sliders(self.hw_slider_moved)
         except IOError:
-            class _:
+            class dummy:
                 def valueOut(self, name, value):
                     pass
-            self.sliders = _()
+            self.sliders = dummy()
             print "no hw sliders found"
 
     def make_key_hints(self):
@@ -294,6 +294,10 @@
             self.cb(int(name[6:]) - 1, value / 127)
 
 if __name__ == "__main__":
+
+    #prof.watchPoint("/usr/lib/python2.4/site-packages/rdflib-2.3.3-py2.4-linux-i686.egg/rdflib/syntax/parsers/n3p/n3p.py", 67)
+
+
     parser = OptionParser()
     parser.add_option('--nonpersistent', action="store_true",
                       help="don't load or save levels")
@@ -327,9 +331,7 @@
         reactor.addSystemEventTrigger('after', 'shutdown', kc.save)
     
     tksupport.install(root,ms=10)
-    if 0:
-        sys.path.append("/home/drewp/projects/cuisine/pour")
-        from utils import runstats
-        runstats("reactor.run()")
-    else:
-        reactor.run()
+
+
+    
+    prof.run(reactor.run, profile=False)
--- a/bin/lightsim	Wed Jun 13 06:01:22 2007 +0000
+++ b/bin/lightsim	Mon Jun 11 02:26:49 2007 +0000
@@ -12,7 +12,7 @@
 logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s")
 log.setLevel(logging.DEBUG)
 import Tkinter as tk
-from light9 import networking, Patch, showconfig, dmxclient, updatefreq
+from light9 import networking, Patch, showconfig, dmxclient, updatefreq, prof
 from light9.namespaces import L9
 from louie import dispatcher
 
@@ -96,11 +96,4 @@
 top.protocol('WM_DELETE_WINDOW', reactor.stop)
 tksupport.install(ogl, ms=20)
 
-if 0:
-    import hotshot, hotshot.stats
-    p = hotshot.Profile("/tmp/pro")
-    p.runcall(reactor.run)
-    p.close()
-    hotshot.stats.load("/tmp/pro").sort_stats('time').print_stats()
-else:
-    reactor.run()
+prof.run(reactor.run, profile=False)
--- a/light9/showconfig.py	Wed Jun 13 06:01:22 2007 +0000
+++ b/light9/showconfig.py	Mon Jun 11 02:26:49 2007 +0000
@@ -1,11 +1,28 @@
-from os import path,getenv
+import time
+from os import path, getenv
 from rdflib.Graph import Graph
 from rdflib import URIRef
 from namespaces import MUS, L9
 
+_config = (None, None, None) # graph, mtime, len
 def getGraph():
+    global _config
+    configPath = path.join(root(), 'config.n3')
+    
+    now = time.time()
+    diskMtime = path.getmtime(configPath)
+    if diskMtime <= _config[1]:
+        graph = _config[0]
+        # i'm scared of some program modifying the graph, and then i
+        # return that from a new getGraph call. Maybe I should be
+        # copying it right here, or doing something clever with
+        # contexts
+        assert len(graph) == _config[2]
+        return _config[0]
+
     graph = Graph()
-    graph.parse(path.join(root(), 'config.n3'), format='n3')
+    graph.parse(configPath, format='n3')
+    _config = (graph, diskMtime, len(graph))
     return graph
 
 def root():