##// END OF EJS Templates
py3: sprinkle statprof.py with utf-8 encoding...
Gregory Szorc -
r40237:7df42042 default
parent child Browse files
Show More
@@ -362,7 +362,7 b' def save_data(path):'
362 for sample in state.samples:
362 for sample in state.samples:
363 time = sample.time
363 time = sample.time
364 stack = sample.stack
364 stack = sample.stack
365 sites = ['\1'.join([s.path, str(s.lineno), s.function])
365 sites = ['\1'.join([s.path, b'%d' % s.lineno, s.function])
366 for s in stack]
366 for s in stack]
367 file.write("%d\0%s\n" % (time, '\0'.join(sites)))
367 file.write("%d\0%s\n" % (time, '\0'.join(sites)))
368
368
@@ -507,7 +507,9 b' def display_by_line(data, fp):'
507
507
508 for stat in stats:
508 for stat in stats:
509 site = stat.site
509 site = stat.site
510 sitelabel = '%s:%d:%s' % (site.filename(), site.lineno, site.function)
510 sitelabel = '%s:%d:%s' % (pycompat.fsencode(site.filename()),
511 site.lineno,
512 pycompat.sysbytes(site.function))
511 fp.write(b'%6.2f %9.2f %9.2f %s\n' % (
513 fp.write(b'%6.2f %9.2f %9.2f %s\n' % (
512 stat.selfpercent(), stat.totalseconds(),
514 stat.selfpercent(), stat.totalseconds(),
513 stat.selfseconds(), sitelabel))
515 stat.selfseconds(), sitelabel))
@@ -525,7 +527,7 b' def display_by_method(data, fp):'
525
527
526 grouped = defaultdict(list)
528 grouped = defaultdict(list)
527 for stat in stats:
529 for stat in stats:
528 grouped[stat.site.filename() + ":" + stat.site.function].append(stat)
530 grouped[stat.site.filename() + r":" + stat.site.function].append(stat)
529
531
530 # compute sums for each function
532 # compute sums for each function
531 functiondata = []
533 functiondata = []
@@ -554,13 +556,16 b' def display_by_method(data, fp):'
554 function[3], # total percent
556 function[3], # total percent
555 function[1], # total cum sec
557 function[1], # total cum sec
556 function[2], # total self sec
558 function[2], # total self sec
557 function[0])) # file:function
559 pycompat.sysbytes(function[0]))) # file:function
558
560
559 function[4].sort(reverse=True, key=lambda i: i.selfseconds())
561 function[4].sort(reverse=True, key=lambda i: i.selfseconds())
560 for stat in function[4]:
562 for stat in function[4]:
561 # only show line numbers for significant locations (>1% time spent)
563 # only show line numbers for significant locations (>1% time spent)
562 if stat.selfpercent() > 1:
564 if stat.selfpercent() > 1:
563 source = stat.site.getsource(25)
565 source = stat.site.getsource(25)
566 if sys.version_info.major >= 3 and not isinstance(source, bytes):
567 source = pycompat.bytestr(source)
568
564 stattuple = (stat.selfpercent(), stat.selfseconds(),
569 stattuple = (stat.selfpercent(), stat.selfseconds(),
565 stat.site.lineno, source)
570 stat.site.lineno, source)
566
571
@@ -599,8 +604,11 b' def display_about_method(data, fp, funct'
599 parents.sort(reverse=True, key=lambda x: x[1])
604 parents.sort(reverse=True, key=lambda x: x[1])
600 for parent, count in parents:
605 for parent, count in parents:
601 fp.write(b'%6.2f%% %s:%s line %s: %s\n' %
606 fp.write(b'%6.2f%% %s:%s line %s: %s\n' %
602 (count / relevant_samples * 100, parent.filename(),
607 (count / relevant_samples * 100,
603 parent.function, parent.lineno, parent.getsource(50)))
608 pycompat.fsencode(parent.filename()),
609 pycompat.sysbytes(parent.function),
610 parent.lineno,
611 pycompat.sysbytes(parent.getsource(50))))
604
612
605 stats = SiteStats.buildstats(data.samples)
613 stats = SiteStats.buildstats(data.samples)
606 stats = [s for s in stats
614 stats = [s for s in stats
@@ -620,8 +628,8 b' def display_about_method(data, fp, funct'
620 fp.write(
628 fp.write(
621 b'\n %s:%s Total: %0.2fs (%0.2f%%) Self: %0.2fs (%0.2f%%)\n\n'
629 b'\n %s:%s Total: %0.2fs (%0.2f%%) Self: %0.2fs (%0.2f%%)\n\n'
622 % (
630 % (
623 filename or '___',
631 pycompat.sysbytes(filename or '___'),
624 function,
632 pycompat.sysbytes(function),
625 total_cum_sec,
633 total_cum_sec,
626 total_cum_percent,
634 total_cum_percent,
627 total_self_sec,
635 total_self_sec,
@@ -633,7 +641,7 b' def display_about_method(data, fp, funct'
633 for child, count in children:
641 for child, count in children:
634 fp.write(b' %6.2f%% line %s: %s\n' %
642 fp.write(b' %6.2f%% line %s: %s\n' %
635 (count / relevant_samples * 100, child.lineno,
643 (count / relevant_samples * 100, child.lineno,
636 child.getsource(50)))
644 pycompat.sysbytes(child.getsource(50))))
637
645
638 def display_hotpath(data, fp, limit=0.05, **kwargs):
646 def display_hotpath(data, fp, limit=0.05, **kwargs):
639 class HotNode(object):
647 class HotNode(object):
General Comments 0
You need to be logged in to leave comments. Login now