# HG changeset patch # User Drew Perttula # Date 2007-06-11 02:26:49 # Node ID c6aabf5bd3bcac90bd39c5b9f447322ceea5472f # Parent 4e60444605f684a6499bb353ff83af16a026f0cd big KC speedup from not reloading config.n3 constantly diff --git a/bin/keyboardcomposer b/bin/keyboardcomposer --- a/bin/keyboardcomposer +++ b/bin/keyboardcomposer @@ -14,7 +14,7 @@ import run_local 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 @@ class KeyboardComposer(Frame, SubClient) 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 @@ class Sliders(BCF2000): 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 @@ if __name__ == "__main__": 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) diff --git a/bin/lightsim b/bin/lightsim --- a/bin/lightsim +++ b/bin/lightsim @@ -12,7 +12,7 @@ log = logging.getLogger() 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.bind("",lambda ev: reactor. 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) diff --git a/light9/showconfig.py b/light9/showconfig.py --- a/light9/showconfig.py +++ b/light9/showconfig.py @@ -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():