Changeset - 17b24cb10202
[Not reviewed]
default
0 2 0
Drew Perttula - 11 years ago 2014-06-13 07:34:12
drewp@bigasterisk.com
gather more output loop timing
Ignore-this: 723db286bb94478104b71f013b260fe
2 files changed with 7 insertions and 5 deletions:
0 comments (0 inline, 0 general)
bin/effecteval
Show inline comments
 
@@ -182,25 +182,26 @@ class SongEffectsEval(PrettyErrorHandler
 
        # return dmx dict for all effects in the song, already combined
 

	
 
class App(object):
 
    def __init__(self, show, outputWhere):
 
        self.show = show
 
        self.outputWhere = outputWhere
 
        self.graph = SyncedGraph(networking.rdfdb.url, "effectEval")
 
        self.graph.initiallySynced.addCallback(self.launch)
 

	
 
        self.stats = scales.collection('/',
 
                                       scales.PmfStat('sendLevels'),
 
                                       scales.PmfStat('getMusic'),
 
                                       scales.PmfStat('writeDmx'),
 
                                       scales.PmfStat('evals'),
 
                                       scales.PmfStat('sendOutupt'),
 
                                       scales.IntStat('errors'),
 
                                       )
 

	
 
    def launch(self, *args):
 
        self.loop = makeEffectLoop(self.graph, self.stats, self.outputWhere)
 
        self.loop.startLoop()
 
        
 
        SFH = cyclone.web.StaticFileHandler
 
        self.cycloneApp = cyclone.web.Application(handlers=[
 
            (r'/()', SFH,
 
             {'path': 'light9/effecteval', 'default_filename': 'index.html'}),
 
            (r'/effect', EffectEdit),
light9/effecteval/effectloop.py
Show inline comments
 
@@ -71,51 +71,52 @@ class EffectLoop(object):
 
            with self.stats.sendLevels.time():
 
                with self.stats.getMusic.time():
 
                    songTime, song = yield self.getSongTime()
 

	
 
                if song != self.currentSong:
 
                    self.currentSong = song
 
                    # this may be piling on the handlers
 
                    self.graph.addHandler(self.setEffects)
 

	
 
                if song is None:
 
                    return
 

	
 
                outputs = self.allEffectOutputs(songTime)
 
                with self.stats.evals.time():
 
                    outputs = self.allEffectOutputs(songTime)
 
                combined = self.combineOutputs(outputs)
 
                self.logLevels(t1, combined)
 
                yield self.sendOutput(combined)
 
                with self.stats.sendOutput.time():
 
                    yield self.sendOutput(combined)
 
                
 
                elapsed = time.time() - t1
 
                dt = max(0, self.period - elapsed)
 
        except Exception:
 
            self.stats.errors += 1
 
            traceback.print_exc()
 
            dt = 1
 

	
 
        reactor.callLater(dt, self.sendLevels)
 

	
 
    def combineOutputs(self, outputs):
 
        """pick usable effect outputs and reduce them into one for sendOutput"""
 
        outputs = [x for x in outputs if isinstance(x, Submaster.Submaster)]
 
        log.info('outputs %r', outputs)
 
        out = Submaster.sub_maxes(*outputs)
 

	
 
        return out
 
        
 
    @inlineCallbacks
 
    def sendOutput(self, combined):
 
        dmx = combined.get_dmx_list()
 
        with self.stats.writeDmx.time():
 
            yield dmxclient.outputlevels(dmx, twisted=True)
 
        yield dmxclient.outputlevels(dmx, twisted=True)
 
        
 
    def allEffectOutputs(self, songTime):
 
        outputs = []
 
        for e in self.currentEffects:
 
            try:
 
                outputs.append(e.eval(songTime))
 
            except Exception as exc:
 
                now = time.time()
 
                if now > self.lastErrorLog + 5:
 
                    log.error("effect %s: %s" % (e.uri, exc))
 
                    self.lastErrorLog = now
 
        return outputs
0 comments (0 inline, 0 general)