Changeset - 5e905ff44e84
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 11 years ago 2014-06-15 03:09:48
drewp@bigasterisk.com
CC now suports statprof profiling, and every other profile() call is now broken
Ignore-this: bc7c31af6598e7c132d2f847afe8de68
2 files changed with 11 insertions and 2 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -469,45 +469,45 @@ def launch(args, graph, session, opts, s
 
    def hoverTimeResponse(requestHandler):
 
        results = dispatcher.send("onPlayPause")
 
        times = [t for listener, t in results if t is not None]
 
        if not times:
 
            requestHandler.set_status(404)
 
            requestHandler.write("not hovering over any time")
 
            return
 
        with graph.currentState(
 
                tripleFilter=(session, L9['currentSong'], None)) as g:
 
            song = g.value(session, L9['currentSong'])
 
            json.dump({"song": song, "hoverTime" : times[0]}, requestHandler)
 
        
 
    serveCurveEdit(networking.curveCalc.port, hoverTimeResponse, start.curveset)
 

	
 
def main():
 
    startTime = time.time()
 
    parser = optparse.OptionParser()
 
    parser.set_usage("%prog [opts] [songURI]")
 
    parser.add_option("--debug", action="store_true",
 
                      help="log at DEBUG")
 
    parser.add_option("--reload", action="store_true",
 
                      help="live reload of themes and code")
 
    parser.add_option("--startup-only", action='store_true',
 
                      help="quit after loading everything (for timing tests)")
 
    parser.add_option("--profile", action='store_true', help='profile')
 
    parser.add_option("--profile", help='"hotshot" or "stat"')
 
    clientsession.add_option(parser)
 
    opts, args = parser.parse_args()
 

	
 
    log.setLevel(logging.DEBUG if opts.debug else logging.INFO)
 

	
 
    log.debug("startup: music %s", time.time() - startTime)
 

	
 

	
 
    session = clientsession.getUri('curvecalc', opts)
 

	
 
    music = Music()
 
    graph = SyncedGraph(networking.rdfdb.url, "curvecalc")
 

	
 
    graph.initiallySynced.addCallback(
 
        lambda _: launch(args, graph, session, opts, startTime, music))
 
    from light9 import prof
 
    prof.run(reactor.run, profile=opts.profile)
 

	
 
main()
 

	
light9/prof.py
Show inline comments
 
import sys, traceback, time, logging
 
log = logging.getLogger()
 

	
 
def run(main, profile=False):
 
def run(main, profile=None):
 
    if not profile:
 
        main()
 
        return
 
    
 
    if profile == 'hotshot':
 
    import hotshot, hotshot.stats
 
    p = hotshot.Profile("/tmp/pro")
 
    p.runcall(main)
 
    p.close()
 
    hotshot.stats.load("/tmp/pro").sort_stats('cumulative').print_stats()
 
    elif profile == 'stat':
 
        import statprof
 
        statprof.start()
 
        try:
 
            main()
 
        finally:
 
            statprof.stop()
 
            statprof.display()
 
    
 
def watchPoint(filename, lineno, event="call"):
 
    """whenever we hit this line, print a stack trace. event='call'
 
    for lines that are function definitions, like what a profiler
 
    gives you.
 

	
 
    Switch to 'line' to match lines inside functions. Execution speed
 
    will be much slower."""
 
    seenTraces = {} # trace contents : count
 
    def trace(frame, ev, arg):
 
        if ev == event:
 
            if (frame.f_code.co_filename, frame.f_lineno) == (filename, lineno):
 
                stack = ''.join(traceback.format_stack(frame))
 
                if stack not in seenTraces:
 
                    print "watchPoint hit"
 
                    print stack
 
                    seenTraces[stack] = 1
 
                else:
 
                    seenTraces[stack] += 1
 

	
 
        return trace
 
    sys.settrace(trace)
 

	
 
    # atexit, print the frequencies?
0 comments (0 inline, 0 general)