##// 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 362 for sample in state.samples:
363 363 time = sample.time
364 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 366 for s in stack]
367 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 508 for stat in stats:
509 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 513 fp.write(b'%6.2f %9.2f %9.2f %s\n' % (
512 514 stat.selfpercent(), stat.totalseconds(),
513 515 stat.selfseconds(), sitelabel))
@@ -525,7 +527,7 b' def display_by_method(data, fp):'
525 527
526 528 grouped = defaultdict(list)
527 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 532 # compute sums for each function
531 533 functiondata = []
@@ -554,13 +556,16 b' def display_by_method(data, fp):'
554 556 function[3], # total percent
555 557 function[1], # total cum sec
556 558 function[2], # total self sec
557 function[0])) # file:function
559 pycompat.sysbytes(function[0]))) # file:function
558 560
559 561 function[4].sort(reverse=True, key=lambda i: i.selfseconds())
560 562 for stat in function[4]:
561 563 # only show line numbers for significant locations (>1% time spent)
562 564 if stat.selfpercent() > 1:
563 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 569 stattuple = (stat.selfpercent(), stat.selfseconds(),
565 570 stat.site.lineno, source)
566 571
@@ -599,8 +604,11 b' def display_about_method(data, fp, funct'
599 604 parents.sort(reverse=True, key=lambda x: x[1])
600 605 for parent, count in parents:
601 606 fp.write(b'%6.2f%% %s:%s line %s: %s\n' %
602 (count / relevant_samples * 100, parent.filename(),
603 parent.function, parent.lineno, parent.getsource(50)))
607 (count / relevant_samples * 100,
608 pycompat.fsencode(parent.filename()),
609 pycompat.sysbytes(parent.function),
610 parent.lineno,
611 pycompat.sysbytes(parent.getsource(50))))
604 612
605 613 stats = SiteStats.buildstats(data.samples)
606 614 stats = [s for s in stats
@@ -620,8 +628,8 b' def display_about_method(data, fp, funct'
620 628 fp.write(
621 629 b'\n %s:%s Total: %0.2fs (%0.2f%%) Self: %0.2fs (%0.2f%%)\n\n'
622 630 % (
623 filename or '___',
624 function,
631 pycompat.sysbytes(filename or '___'),
632 pycompat.sysbytes(function),
625 633 total_cum_sec,
626 634 total_cum_percent,
627 635 total_self_sec,
@@ -633,7 +641,7 b' def display_about_method(data, fp, funct'
633 641 for child, count in children:
634 642 fp.write(b' %6.2f%% line %s: %s\n' %
635 643 (count / relevant_samples * 100, child.lineno,
636 child.getsource(50)))
644 pycompat.sysbytes(child.getsource(50))))
637 645
638 646 def display_hotpath(data, fp, limit=0.05, **kwargs):
639 647 class HotNode(object):
General Comments 0
You need to be logged in to leave comments. Login now