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
 
@@ -170,49 +170,50 @@ class EffectEval(PrettyErrorHandler, cyc
 
        outSub = node.eval(songTime)
 
        self.write(json.dumps(outSub.get_dmx_list()))
 

	
 

	
 
# Completely not sure where the effect background loop should
 
# go. Another process could own it, and get this request repeatedly:
 
class SongEffectsEval(PrettyErrorHandler, cyclone.web.RequestHandler):
 
    def get(self):
 
        song = URIRef(self.get_argument('song'))
 
        effects = effectsForSong(self.settings.graph, song)
 
        raise NotImplementedError
 
        self.write(maxDict(effectDmxDict(e) for e in effects))
 
        # 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),
 
            (r'/(websocket\.js)', SFH, {'path': 'light9/rdfdb/web/'}),
 
            (r'/effect\.js', StaticCoffee, {'src': 'light9/effecteval/effect.coffee'}),
 
            (r'/index\.js', StaticCoffee, {'src': 'light9/effecteval/index.coffee'}),
 
            (r'/effectUpdates', EffectUpdates),
 
            (r'/code', Code),
 
            (r'/songEffectsUpdates', SongEffectsUpdates),
 
            (r'/static/(.*)', SFH, {'path': 'static/'}),
 
            (r'/effect/eval', EffectEval),
 
            (r'/songEffects', SongEffects),
 
            (r'/songEffects/eval', SongEffectsEval),
 
            (r'/stats', StatsForCyclone),
 
        ], debug=True, graph=self.graph, stats=self.stats)
light9/effecteval/effectloop.py
Show inline comments
 
@@ -59,75 +59,76 @@ class EffectLoop(object):
 
            response = json.loads((yield cyclone.httpclient.fetch(
 
                networking.musicPlayer.path('time'))).body)
 
            self.requestTime = now
 
            self.currentPlaying = response['playing']
 
            self.songTimeFromRequest = response['t']
 
            returnValue(
 
                (response['t'], (response['song'] and URIRef(response['song']))))
 
            
 
    @inlineCallbacks
 
    def sendLevels(self):
 
        t1 = time.time()
 
        try:
 
            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
 
        
 
    def logLevels(self, now, out):
 
        # this would look nice on the top of the effecteval web pages too
 
        if log.isEnabledFor(logging.DEBUG):
 
            log.debug(self.logMessage(out))
 
        else:
 
            if now > self.lastLogTime + 5:
 
                msg = self.logMessage(out)
 
                if msg != self.lastLogMsg:
 
                    log.info(msg)
 
                    self.lastLogMsg = msg
 
                self.lastLogTime = now
0 comments (0 inline, 0 general)