Mercurial > public > mercurial-scm > hg
comparison mercurial/statprof.py @ 43106:d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
This commit finishes porting .iteritems() to pycompat.iteritems()
for the mercurial package.
The translation of .iteritems() to .items() was the last conversion
performed by the source transformer. With the porting to pycompat
complete, we no longer have a need for the source transformer. So
the source transformer has been removed. Good riddance! The code
base is now compatible with Python 2 and Python 3.
For the record, as the person who introduced the source transformer,
it brings me joy to delete it. It accomplished its goal to facilitate
a port to Python 3 without overly burdening people on some painful
low-level differences between Python 2 and 3. It is unfortunate we
still have to wallpaper over many differences with the pycompat
shim. But it is what it is.
Differential Revision: https://phab.mercurial-scm.org/D7015
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 07 Oct 2019 00:04:04 -0400 |
parents | 74802979dd9d |
children | 5c9daf7df2b4 |
comparison
equal
deleted
inserted
replaced
43105:649d3ac37a12 | 43106:d783f945a701 |
---|---|
572 for stat in stats: | 572 for stat in stats: |
573 grouped[stat.site.filename() + b":" + stat.site.function].append(stat) | 573 grouped[stat.site.filename() + b":" + stat.site.function].append(stat) |
574 | 574 |
575 # compute sums for each function | 575 # compute sums for each function |
576 functiondata = [] | 576 functiondata = [] |
577 for fname, sitestats in grouped.iteritems(): | 577 for fname, sitestats in pycompat.iteritems(grouped): |
578 total_cum_sec = 0 | 578 total_cum_sec = 0 |
579 total_self_sec = 0 | 579 total_self_sec = 0 |
580 total_percent = 0 | 580 total_percent = 0 |
581 for stat in sitestats: | 581 for stat in sitestats: |
582 total_cum_sec += stat.totalseconds() | 582 total_cum_sec += stat.totalseconds() |
651 if site in children: | 651 if site in children: |
652 children[site] = children[site] + 1 | 652 children[site] = children[site] + 1 |
653 else: | 653 else: |
654 children[site] = 1 | 654 children[site] = 1 |
655 | 655 |
656 parents = [(parent, count) for parent, count in parents.iteritems()] | 656 parents = [(parent, count) for parent, count in pycompat.iteritems(parents)] |
657 parents.sort(reverse=True, key=lambda x: x[1]) | 657 parents.sort(reverse=True, key=lambda x: x[1]) |
658 for parent, count in parents: | 658 for parent, count in parents: |
659 fp.write( | 659 fp.write( |
660 b'%6.2f%% %s:%s line %s: %s\n' | 660 b'%6.2f%% %s:%s line %s: %s\n' |
661 % ( | 661 % ( |
695 total_self_sec, | 695 total_self_sec, |
696 total_self_percent, | 696 total_self_percent, |
697 ) | 697 ) |
698 ) | 698 ) |
699 | 699 |
700 children = [(child, count) for child, count in children.iteritems()] | 700 children = [(child, count) for child, count in pycompat.iteritems(children)] |
701 children.sort(reverse=True, key=lambda x: x[1]) | 701 children.sort(reverse=True, key=lambda x: x[1]) |
702 for child, count in children: | 702 for child, count in children: |
703 fp.write( | 703 fp.write( |
704 b' %6.2f%% line %s: %s\n' | 704 b' %6.2f%% line %s: %s\n' |
705 % ( | 705 % ( |
819 lines[line] = 1 | 819 lines[line] = 1 |
820 | 820 |
821 fd, path = pycompat.mkstemp() | 821 fd, path = pycompat.mkstemp() |
822 | 822 |
823 with open(path, b"w+") as file: | 823 with open(path, b"w+") as file: |
824 for line, count in lines.iteritems(): | 824 for line, count in pycompat.iteritems(lines): |
825 file.write(b"%s %d\n" % (line, count)) | 825 file.write(b"%s %d\n" % (line, count)) |
826 | 826 |
827 if outputfile is None: | 827 if outputfile is None: |
828 outputfile = b'~/flamegraph.svg' | 828 outputfile = b'~/flamegraph.svg' |
829 | 829 |