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