X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=hacks%2Fanalog.py;h=2bca2ef763332e26236b49fbf815218dda6152ba;hb=adddda49c17e87198253d9c900dcef0f5fb2e175;hp=c58af76ee53972ba0341dba4e69cd96485fbc798;hpb=dae7fea98a5ca43d7e278b6381afcb5ccd1a310b;p=dcpomatic.git diff --git a/hacks/analog.py b/hacks/analog.py index c58af76ee..2bca2ef76 100644 --- a/hacks/analog.py +++ b/hacks/analog.py @@ -6,6 +6,8 @@ import sys import time import argparse +import matplotlib +matplotlib.use('GTK3Cairo') import matplotlib.pyplot as plt parser = argparse.ArgumentParser() @@ -19,6 +21,7 @@ parser.add_argument('--encoder-dump', help='dump activity of the specified encod parser.add_argument('-e', '--encoder', help='encoder index (from 0)') parser.add_argument('--from', help='time in seconds to start at', type=int, dest='from_time') parser.add_argument('--to', help='time in seconds to stop at', type=int, dest='to_time') +parser.add_argument('--max-encoder-threads', help='maximum number of encoder threads to plot with --encoder-threads', type=int, default=None) args = parser.parse_args() def find_nth(haystack, needle, n): @@ -106,7 +109,8 @@ while True: values = {} for i in range(2, len(p)): x = p[i].split('=') - values[x[0]] = x[1] + if len(x) == 2: + values[x[0]] = x[1] else: # Date/time timestamp: other LOG_* s = find_nth(l, ':', 3) @@ -116,10 +120,13 @@ while True: try: T = Time(time.mktime(time.strptime(l[:s], "%d.%m.%Y %H:%M:%S"))) except: - x = l[:s] - if not x.endswith('M'): - x += 'M' - T = Time(time.mktime(time.strptime(x, "%d/%m/%Y %H:%M:%S %p"))) + try: + T = Time(time.mktime(time.strptime(l[:s], "%d/%m/%Y %H:%M:%S"))) + except: + x = l[:s] + if not x.endswith('M'): + x += 'M' + T = Time(time.mktime(time.strptime(x, "%d/%m/%Y %H:%M:%S %p"))) message = l[s+2:] # T is elapsed time since the first log message @@ -160,6 +167,11 @@ elif args.encoder_threads: # y=0 thread is sleeping # y=1 thread is awake # y=2 thread is encoding + # y=3 thread is awaiting a remote encode + + if args.max_encoder_threads is not None: + encoder_threads = encoder_threads[0:min(args.max_encoder_threads, len(encoder_threads))] + plt.figure() N = len(encoder_threads) n = 1 @@ -174,6 +186,8 @@ elif args.encoder_threads: continue if args.to_time is not None and e[0].float_seconds() >= args.to_time: continue + if e[1] == 'start-remote-send' or e[1] == 'finish-remote-send' or e[1] == 'start-remote-receive' or e[1] == 'finish-remote-receive': + continue x.append(e[0].float_seconds()) x.append(e[0].float_seconds()) y.append(previous) @@ -185,8 +199,12 @@ elif args.encoder_threads: y.append(2) elif e[1] == 'finish-local-encode': y.append(1) + elif e[1] == 'start-remote-encode': + y.append(3) + elif e[1] == 'finish-remote-encode': + y.append(1) else: - print>>sys.stderr,'unknown event %s' % e[1] + print('unknown event %s' % e[1], file=sys.stderr) sys.exit(1) previous = y[-1] @@ -231,7 +249,7 @@ elif args.encoder_dump: for t in encoder_threads[int(args.encoder)]: last = 0 for e in t.events: - print (e[0].float_seconds() - last), e[1] + print((e[0].float_seconds() - last), e[1]) last = e[0].float_seconds() elif args.fps_stats: @@ -250,14 +268,14 @@ elif args.fps_stats: remote += 1 if end == None: - print 'Job did not appear to end' + print('Job did not appear to end') sys.exit(1) duration = end - start - print 'Job ran for %fs' % duration.float_seconds() - print '%d local and %d remote' % (local, remote) - print '%.2f fps local and %.2f fps remote' % (local / duration.float_seconds(), remote / duration.float_seconds()) + print('Job ran for %fs' % duration.float_seconds()) + print('%d local and %d remote' % (local, remote)) + print('%.2f fps local and %.2f fps remote' % (local / duration.float_seconds(), remote / duration.float_seconds())) elif args.encoder_stats: # Broad stats on what encoder threads spent their time doing @@ -288,23 +306,23 @@ elif args.encoder_stats: last = e - print '-- Encoder thread %s (%s)' % (t.server, t.id) - print '\tAwoken %d times' % wakes + print('-- Encoder thread %s (%s)' % (t.server, t.id)) + print('\tAwoken %d times' % wakes) total = asleep.float_seconds() + local_encoding.float_seconds() + sending.float_seconds() + remote_encoding.float_seconds() + receiving.float_seconds() if total == 0: continue - print '\t%s: %2.f%% %fs' % ('Asleep'.ljust(16), asleep.float_seconds() * 100 / total, asleep.float_seconds()) + print('\t%s: %2.f%% %fs' % ('Asleep'.ljust(16), asleep.float_seconds() * 100 / total, asleep.float_seconds())) def print_with_fps(v, name, total, frames): if v.float_seconds() > 1: - print '\t%s: %2.f%% %f %.2ffps' % (name.ljust(16), v.float_seconds() * 100 / total, v.float_seconds(), frames / v.float_seconds()) + print('\t%s: %2.f%% %f %.2ffps' % (name.ljust(16), v.float_seconds() * 100 / total, v.float_seconds(), frames / v.float_seconds())) print_with_fps(local_encoding, 'Local encoding', total, wakes) if sending.float_seconds() > 0: - print '\t%s: %2.f%%' % ('Sending'.ljust(16), sending.float_seconds() * 100 / total) + print('\t%s: %2.f%%' % ('Sending'.ljust(16), sending.float_seconds() * 100 / total)) print_with_fps(remote_encoding, 'Remote encoding', total, wakes) if receiving.float_seconds() > 0: - print '\t%s: %2.f%%' % ('Receiving'.ljust(16), receiving.float_seconds() * 100 / total) - print '' + print('\t%s: %2.f%%' % ('Receiving'.ljust(16), receiving.float_seconds() * 100 / total)) + print('')