comparison bin/curvecalc @ 680:ad17b0a09f5c

CC more startup logging, timing option to quit after init Ignore-this: 6116d151a3c36a7830740a7407d5665c
author drewp@bigasterisk.com
date Tue, 21 Jun 2011 01:58:49 +0000
parents c113c759559b
children 83c239d3fd33
comparison
equal deleted inserted replaced
679:958b309147b0 680:ad17b0a09f5c
416 416
417 417
418 def graphPathForSubterms(song): 418 def graphPathForSubterms(song):
419 return showconfig.subtermsForSong(showconfig.songFilenameFromURI(song)) + ".n3" 419 return showconfig.subtermsForSong(showconfig.songFilenameFromURI(song)) + ".n3"
420 420
421 @prof.logTime
421 def read_all_subs(graph): 422 def read_all_subs(graph):
422 """read all sub files into this graph so when add_one_subterm tries 423 """read all sub files into this graph so when add_one_subterm tries
423 to add, the sub will be available""" 424 to add, the sub will be available"""
424 subsDir = showconfig.subsDir() 425 subsDir = showconfig.subsDir()
425 for filename in os.listdir(subsDir): 426 for filename in os.listdir(subsDir):
502 if t['song'] is None: 503 if t['song'] is None:
503 raise ValueError("music player is not playing any song") 504 raise ValueError("music player is not playing any song")
504 return URIRef(t['song']) 505 return URIRef(t['song'])
505 506
506 def main(): 507 def main():
508 startTime = time.time()
507 parser = optparse.OptionParser() 509 parser = optparse.OptionParser()
508 parser.set_usage("%prog [opts] [songURI]") 510 parser.set_usage("%prog [opts] [songURI]")
509 parser.add_option("--sliders", action='store_true', 511 parser.add_option("--sliders", action='store_true',
510 help='use hardware sliders') 512 help='use hardware sliders')
511 parser.add_option("--skip-music", action='store_true', 513 parser.add_option("--skip-music", action='store_true',
512 help="ignore music and smooth_music curve files") 514 help="ignore music and smooth_music curve files")
515 parser.add_option("--debug", action="store_true",
516 help="log at DEBUG")
517 parser.add_option("--startup-only", action='store_true',
518 help="quit after loading everything (for timing tests)")
513 opts, args = parser.parse_args() 519 opts, args = parser.parse_args()
514 520
515 logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s") 521 logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s")
516 log.setLevel(logging.INFO) 522 log.setLevel(logging.DEBUG if opts.debug else logging.INFO)
517 523
518 524 log.debug("startup: music %s", time.time() - startTime)
519 try: 525 try:
520 song = URIRef(args[0]) 526 song = URIRef(args[0])
521 except IndexError: 527 except IndexError:
522 song = currentlyPlayingSong() 528 song = currentlyPlayingSong()
523 529
524 log.debug("music")
525 music=Music() 530 music=Music()
526 graph = makeGraph() 531 graph = makeGraph()
527 curveset = Curveset(sliders=opts.sliders) 532 curveset = Curveset(sliders=opts.sliders)
528 subterms = [] 533 subterms = []
529 534
533 except urllib2.URLError, e: 538 except urllib2.URLError, e:
534 if e.reason.errno != 2: 539 if e.reason.errno != 2:
535 raise 540 raise
536 log.info("%s not found, starting with empty graph" % subtermPath) 541 log.info("%s not found, starting with empty graph" % subtermPath)
537 542
538 log.debug("output") 543 log.debug("startup: output %s", time.time() - startTime)
539 out = Output(subterms, music) 544 out = Output(subterms, music)
540 545
541 musicfilename = showconfig.songOnDisk(song) 546 musicfilename = showconfig.songOnDisk(song)
542 maxtime = wavelength(musicfilename) 547 maxtime = wavelength(musicfilename)
543 dispatcher.connect(lambda: maxtime, "get max time", weak=False) 548 dispatcher.connect(lambda: maxtime, "get max time", weak=False)
599 # the number of times we redraw the curve at startup. If tk is 604 # the number of times we redraw the curve at startup. If tk is
600 # very slow, it's ok. You'll just get some wasted redraws. 605 # very slow, it's ok. You'll just get some wasted redraws.
601 reactor.callLater(.1, curvesetView.goLive) 606 reactor.callLater(.1, curvesetView.goLive)
602 607
603 tksupport.install(root, ms=10) 608 tksupport.install(root, ms=10)
604 log.debug("run") 609 log.debug("startup: run %s", time.time() - startTime)
610 if opts.startup_only:
611 log.debug("quitting now because of --startup-only")
612 return
605 prof.run(reactor.run, profile=False) 613 prof.run(reactor.run, profile=False)
606 614
607 main() 615 main()