Show More
@@ -469,7 +469,7 b' def display(fp=None, format=3, data=None' | |||||
469 | import sys |
|
469 | import sys | |
470 | fp = sys.stdout |
|
470 | fp = sys.stdout | |
471 | if len(data.samples) == 0: |
|
471 | if len(data.samples) == 0: | |
472 |
pri |
|
472 | fp.write(b'No samples recorded.\n') | |
473 | return |
|
473 | return | |
474 |
|
474 | |||
475 | if format == DisplayFormats.ByLine: |
|
475 | if format == DisplayFormats.ByLine: | |
@@ -490,10 +490,9 b' def display(fp=None, format=3, data=None' | |||||
490 | raise Exception("Invalid display format") |
|
490 | raise Exception("Invalid display format") | |
491 |
|
491 | |||
492 | if format not in (DisplayFormats.Json, DisplayFormats.Chrome): |
|
492 | if format not in (DisplayFormats.Json, DisplayFormats.Chrome): | |
493 |
pri |
|
493 | fp.write(b'---\n') | |
494 |
pri |
|
494 | fp.write(b'Sample count: %d\n' % len(data.samples)) | |
495 |
pri |
|
495 | fp.write(b'Total time: %f seconds (%f wall)\n' % data.accumulated_time) | |
496 | file=fp) |
|
|||
497 |
|
496 | |||
498 | def display_by_line(data, fp): |
|
497 | def display_by_line(data, fp): | |
499 | '''Print the profiler data with each sample line represented |
|
498 | '''Print the profiler data with each sample line represented | |
@@ -501,28 +500,26 b' def display_by_line(data, fp):' | |||||
501 | stats = SiteStats.buildstats(data.samples) |
|
500 | stats = SiteStats.buildstats(data.samples) | |
502 | stats.sort(reverse=True, key=lambda x: x.selfseconds()) |
|
501 | stats.sort(reverse=True, key=lambda x: x.selfseconds()) | |
503 |
|
502 | |||
504 |
pri |
|
503 | fp.write(b'%5.5s %10.10s %7.7s %-8.8s\n' % ( | |
505 |
|
|
504 | b'% ', b'cumulative', b'self', b'')) | |
506 |
pri |
|
505 | fp.write(b'%5.5s %9.9s %8.8s %-8.8s\n' % ( | |
507 |
|
|
506 | b"time", b"seconds", b"seconds", b"name")) | |
508 |
|
507 | |||
509 | for stat in stats: |
|
508 | for stat in stats: | |
510 | site = stat.site |
|
509 | site = stat.site | |
511 | sitelabel = '%s:%d:%s' % (site.filename(), site.lineno, site.function) |
|
510 | sitelabel = '%s:%d:%s' % (site.filename(), site.lineno, site.function) | |
512 |
pri |
|
511 | fp.write(b'%6.2f %9.2f %9.2f %s\n' % ( | |
513 | stat.totalseconds(), |
|
512 | stat.selfpercent(), stat.totalseconds(), | |
514 |
|
|
513 | stat.selfseconds(), sitelabel)) | |
515 | sitelabel), |
|
|||
516 | file=fp) |
|
|||
517 |
|
514 | |||
518 | def display_by_method(data, fp): |
|
515 | def display_by_method(data, fp): | |
519 | '''Print the profiler data with each sample function represented |
|
516 | '''Print the profiler data with each sample function represented | |
520 | as one row in a table. Important lines within that function are |
|
517 | as one row in a table. Important lines within that function are | |
521 | output as nested rows. Sorted by self-time per line.''' |
|
518 | output as nested rows. Sorted by self-time per line.''' | |
522 |
pri |
|
519 | fp.write(b'%5.5s %10.10s %7.7s %-8.8s\n' % | |
523 |
('% ', 'cumulative', 'self', '') |
|
520 | ('% ', 'cumulative', 'self', '')) | |
524 |
pri |
|
521 | fp.write(b'%5.5s %9.9s %8.8s %-8.8s\n' % | |
525 |
("time", "seconds", "seconds", "name") |
|
522 | ("time", "seconds", "seconds", "name")) | |
526 |
|
523 | |||
527 | stats = SiteStats.buildstats(data.samples) |
|
524 | stats = SiteStats.buildstats(data.samples) | |
528 |
|
525 | |||
@@ -553,11 +550,12 b' def display_by_method(data, fp):' | |||||
553 | for function in functiondata: |
|
550 | for function in functiondata: | |
554 | if function[3] < 0.05: |
|
551 | if function[3] < 0.05: | |
555 | continue |
|
552 | continue | |
556 |
pri |
|
553 | fp.write(b'%6.2f %9.2f %9.2f %s\n' % ( | |
557 |
|
|
554 | function[3], # total percent | |
558 |
|
|
555 | function[1], # total cum sec | |
559 | function[0]), # file:function |
|
556 | function[2], # total self sec | |
560 | file=fp) |
|
557 | function[0])) # file:function | |
|
558 | ||||
561 | function[4].sort(reverse=True, key=lambda i: i.selfseconds()) |
|
559 | function[4].sort(reverse=True, key=lambda i: i.selfseconds()) | |
562 | for stat in function[4]: |
|
560 | for stat in function[4]: | |
563 | # only show line numbers for significant locations (>1% time spent) |
|
561 | # only show line numbers for significant locations (>1% time spent) | |
@@ -566,7 +564,7 b' def display_by_method(data, fp):' | |||||
566 | stattuple = (stat.selfpercent(), stat.selfseconds(), |
|
564 | stattuple = (stat.selfpercent(), stat.selfseconds(), | |
567 | stat.site.lineno, source) |
|
565 | stat.site.lineno, source) | |
568 |
|
566 | |||
569 |
pri |
|
567 | fp.write(b'%33.0f%% %6.2f line %d: %s\n' % stattuple) | |
570 |
|
568 | |||
571 | def display_about_method(data, fp, function=None, **kwargs): |
|
569 | def display_about_method(data, fp, function=None, **kwargs): | |
572 | if function is None: |
|
570 | if function is None: | |
@@ -600,9 +598,9 b' def display_about_method(data, fp, funct' | |||||
600 | parents = [(parent, count) for parent, count in parents.iteritems()] |
|
598 | parents = [(parent, count) for parent, count in parents.iteritems()] | |
601 | parents.sort(reverse=True, key=lambda x: x[1]) |
|
599 | parents.sort(reverse=True, key=lambda x: x[1]) | |
602 | for parent, count in parents: |
|
600 | for parent, count in parents: | |
603 |
pri |
|
601 | fp.write(b'%6.2f%% %s:%s line %s: %s\n' % | |
604 | (count / relevant_samples * 100, parent.filename(), |
|
602 | (count / relevant_samples * 100, parent.filename(), | |
605 |
parent.function, parent.lineno, parent.getsource(50)) |
|
603 | parent.function, parent.lineno, parent.getsource(50))) | |
606 |
|
604 | |||
607 | stats = SiteStats.buildstats(data.samples) |
|
605 | stats = SiteStats.buildstats(data.samples) | |
608 | stats = [s for s in stats |
|
606 | stats = [s for s in stats | |
@@ -619,23 +617,23 b' def display_about_method(data, fp, funct' | |||||
619 | total_self_percent += stat.selfpercent() |
|
617 | total_self_percent += stat.selfpercent() | |
620 | total_cum_percent += stat.totalpercent() |
|
618 | total_cum_percent += stat.totalpercent() | |
621 |
|
619 | |||
622 |
pri |
|
620 | fp.write( | |
623 |
'\n %s:%s Total: %0.2fs (%0.2f%%) Self: %0.2fs (%0.2f%%)\n' |
|
621 | b'\n %s:%s Total: %0.2fs (%0.2f%%) Self: %0.2fs (%0.2f%%)\n\n' | |
624 | ( |
|
622 | % ( | |
625 | filename or '___', |
|
623 | filename or '___', | |
626 | function, |
|
624 | function, | |
627 | total_cum_sec, |
|
625 | total_cum_sec, | |
628 | total_cum_percent, |
|
626 | total_cum_percent, | |
629 | total_self_sec, |
|
627 | total_self_sec, | |
630 | total_self_percent |
|
628 | total_self_percent | |
631 |
) |
|
629 | )) | |
632 |
|
630 | |||
633 | children = [(child, count) for child, count in children.iteritems()] |
|
631 | children = [(child, count) for child, count in children.iteritems()] | |
634 | children.sort(reverse=True, key=lambda x: x[1]) |
|
632 | children.sort(reverse=True, key=lambda x: x[1]) | |
635 | for child, count in children: |
|
633 | for child, count in children: | |
636 |
pri |
|
634 | fp.write(b' %6.2f%% line %s: %s\n' % | |
637 | (count / relevant_samples * 100, child.lineno, |
|
635 | (count / relevant_samples * 100, child.lineno, | |
638 |
child.getsource(50)) |
|
636 | child.getsource(50))) | |
639 |
|
637 | |||
640 | def display_hotpath(data, fp, limit=0.05, **kwargs): |
|
638 | def display_hotpath(data, fp, limit=0.05, **kwargs): | |
641 | class HotNode(object): |
|
639 | class HotNode(object): | |
@@ -697,7 +695,7 b' def display_hotpath(data, fp, limit=0.05' | |||||
697 | # Make frames that didn't actually perform work dark grey |
|
695 | # Make frames that didn't actually perform work dark grey | |
698 | elif node.count - childrensamples == 0: |
|
696 | elif node.count - childrensamples == 0: | |
699 | finalstring = '\033[90m' + finalstring + '\033[0m' |
|
697 | finalstring = '\033[90m' + finalstring + '\033[0m' | |
700 |
pri |
|
698 | fp.write(finalstring + b'\n') | |
701 |
|
699 | |||
702 | newdepth = depth |
|
700 | newdepth = depth | |
703 | if len(visiblechildren) > 1 or multiple_siblings: |
|
701 | if len(visiblechildren) > 1 or multiple_siblings: | |
@@ -714,9 +712,8 b' def write_to_flame(data, fp, scriptpath=' | |||||
714 | if scriptpath is None: |
|
712 | if scriptpath is None: | |
715 | scriptpath = encoding.environ['HOME'] + '/flamegraph.pl' |
|
713 | scriptpath = encoding.environ['HOME'] + '/flamegraph.pl' | |
716 | if not os.path.exists(scriptpath): |
|
714 | if not os.path.exists(scriptpath): | |
717 |
pri |
|
715 | fp.write(b'error: missing %s\n' % scriptpath) | |
718 |
pri |
|
716 | fp.write(b'get it here: https://github.com/brendangregg/FlameGraph\n') | |
719 | file=fp) |
|
|||
720 | return |
|
717 | return | |
721 |
|
718 | |||
722 | fd, path = pycompat.mkstemp() |
|
719 | fd, path = pycompat.mkstemp() | |
@@ -742,7 +739,7 b' def write_to_flame(data, fp, scriptpath=' | |||||
742 | outputfile = '~/flamegraph.svg' |
|
739 | outputfile = '~/flamegraph.svg' | |
743 |
|
740 | |||
744 | os.system("perl ~/flamegraph.pl %s > %s" % (path, outputfile)) |
|
741 | os.system("perl ~/flamegraph.pl %s > %s" % (path, outputfile)) | |
745 |
pri |
|
742 | fp.write(b'Written to %s\n' % outputfile) | |
746 |
|
743 | |||
747 | _pathcache = {} |
|
744 | _pathcache = {} | |
748 | def simplifypath(path): |
|
745 | def simplifypath(path): | |
@@ -874,7 +871,7 b' def write_to_chrome(data, fp, minthresho' | |||||
874 | fp.write('\n') |
|
871 | fp.write('\n') | |
875 |
|
872 | |||
876 | def printusage(): |
|
873 | def printusage(): | |
877 | print(""" |
|
874 | print(r""" | |
878 | The statprof command line allows you to inspect the last profile's results in |
|
875 | The statprof command line allows you to inspect the last profile's results in | |
879 | the following forms: |
|
876 | the following forms: | |
880 |
|
877 |
General Comments 0
You need to be logged in to leave comments.
Login now