comparison mercurial/statprof.py @ 51173:933551630b0d

statprof: handle `lineno == None` in more cases This continues the work from 972f3e5c94b8. We saw a crash on line 956 but I updated lots of other places as well.
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 07 Dec 2023 09:31:07 -0800
parents 18c8c18993f0
children 99632adff795 460e80488cf0
comparison
equal deleted inserted replaced
51172:77b86226dde2 51173:933551630b0d
382 file.write(b"%f %f\n" % state.accumulated_time) 382 file.write(b"%f %f\n" % state.accumulated_time)
383 for sample in state.samples: 383 for sample in state.samples:
384 time = sample.time 384 time = sample.time
385 stack = sample.stack 385 stack = sample.stack
386 sites = [ 386 sites = [
387 b'\1'.join([s.path, b'%d' % s.lineno, s.function]) 387 b'\1'.join([s.path, b'%d' % s.lineno or -1, s.function])
388 for s in stack 388 for s in stack
389 ] 389 ]
390 file.write(b"%d\0%s\n" % (time, b'\0'.join(sites))) 390 file.write(b"%d\0%s\n" % (time, b'\0'.join(sites)))
391 391
392 392
661 b'%6.2f%% %s:%s line %s: %s\n' 661 b'%6.2f%% %s:%s line %s: %s\n'
662 % ( 662 % (
663 count / relevant_samples * 100, 663 count / relevant_samples * 100,
664 pycompat.fsencode(parent.filename()), 664 pycompat.fsencode(parent.filename()),
665 pycompat.sysbytes(parent.function), 665 pycompat.sysbytes(parent.function),
666 parent.lineno, 666 parent.lineno or -1,
667 pycompat.sysbytes(parent.getsource(50)), 667 pycompat.sysbytes(parent.getsource(50)),
668 ) 668 )
669 ) 669 )
670 670
671 stats = SiteStats.buildstats(data.samples) 671 stats = SiteStats.buildstats(data.samples)
703 for child, count in children: 703 for child, count in children:
704 fp.write( 704 fp.write(
705 b' %6.2f%% line %s: %s\n' 705 b' %6.2f%% line %s: %s\n'
706 % ( 706 % (
707 count / relevant_samples * 100, 707 count / relevant_samples * 100,
708 child.lineno, 708 child.lineno or -1,
709 pycompat.sysbytes(child.getsource(50)), 709 pycompat.sysbytes(child.getsource(50)),
710 ) 710 )
711 ) 711 )
712 712
713 713
863 863
864 for frame in sample.stack: 864 for frame in sample.stack:
865 stack.append( 865 stack.append(
866 ( 866 (
867 pycompat.sysstr(frame.path), 867 pycompat.sysstr(frame.path),
868 frame.lineno, 868 frame.lineno or -1,
869 pycompat.sysstr(frame.function), 869 pycompat.sysstr(frame.function),
870 ) 870 )
871 ) 871 )
872 872
873 samples.append((sample.time, stack)) 873 samples.append((sample.time, stack))
952 for sample in data.samples: 952 for sample in data.samples:
953 stack = tuple( 953 stack = tuple(
954 ( 954 (
955 ( 955 (
956 '%s:%d' 956 '%s:%d'
957 % (simplifypath(pycompat.sysstr(frame.path)), frame.lineno), 957 % (
958 simplifypath(pycompat.sysstr(frame.path)),
959 frame.lineno or -1,
960 ),
958 pycompat.sysstr(frame.function), 961 pycompat.sysstr(frame.function),
959 ) 962 )
960 for frame in sample.stack 963 for frame in sample.stack
961 ) 964 )
962 ) 965 )