comparison mercurial/statprof.py @ 43104:74802979dd9d

py3: define and use pycompat.itervalues() .itervalues() only exists on Python 2. Python 3's equivalent is .values(). But we don't want to blindly use .values() everywhere because on Python 2, it will create a list, which will have performance implications. This commit introduces pycompat.itervalues() which will call the appropriate method on the passed object. We update all callers of obj.itervalues() to pycompat.itervalues(obj) instead. With this commit, the only source tranforming remaining is for iteritems(). Victory is near... Differential Revision: https://phab.mercurial-scm.org/D7013
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 06 Oct 2019 17:59:15 -0400
parents 0d612db7047c
children d783f945a701
comparison
equal deleted inserted replaced
43103:c95b2f40db7c 43104:74802979dd9d
473 sitestat.addtotal() 473 sitestat.addtotal()
474 474
475 if i == 0: 475 if i == 0:
476 sitestat.addself() 476 sitestat.addself()
477 477
478 return [s for s in stats.itervalues()] 478 return [s for s in pycompat.itervalues(stats)]
479 479
480 480
481 class DisplayFormats: 481 class DisplayFormats:
482 ByLine = 0 482 ByLine = 0
483 ByMethod = 1 483 ByMethod = 1
742 742
743 def _write(node, depth, multiple_siblings): 743 def _write(node, depth, multiple_siblings):
744 site = node.site 744 site = node.site
745 visiblechildren = [ 745 visiblechildren = [
746 c 746 c
747 for c in node.children.itervalues() 747 for c in pycompat.itervalues(node.children)
748 if c.count >= (limit * root.count) 748 if c.count >= (limit * root.count)
749 ] 749 ]
750 if site: 750 if site:
751 indent = depth * 2 - 1 751 indent = depth * 2 - 1
752 filename = b'' 752 filename = b''
753 function = b'' 753 function = b''
754 if len(node.children) > 0: 754 if len(node.children) > 0:
755 childsite = list(node.children.itervalues())[0].site 755 childsite = list(pycompat.itervalues(node.children))[0].site
756 filename = (childsite.filename() + b':').ljust(15) 756 filename = (childsite.filename() + b':').ljust(15)
757 function = childsite.function 757 function = childsite.function
758 758
759 # lots of string formatting 759 # lots of string formatting
760 listpattern = ( 760 listpattern = (
775 site.lineno, 775 site.lineno,
776 site.getsource(30), 776 site.getsource(30),
777 ) 777 )
778 778
779 finalstring = liststring + codestring 779 finalstring = liststring + codestring
780 childrensamples = sum([c.count for c in node.children.itervalues()]) 780 childrensamples = sum(
781 [c.count for c in pycompat.itervalues(node.children)]
782 )
781 # Make frames that performed more than 10% of the operation red 783 # Make frames that performed more than 10% of the operation red
782 if node.count - childrensamples > (0.1 * root.count): 784 if node.count - childrensamples > (0.1 * root.count):
783 finalstring = b'\033[91m' + finalstring + b'\033[0m' 785 finalstring = b'\033[91m' + finalstring + b'\033[0m'
784 # Make frames that didn't actually perform work dark grey 786 # Make frames that didn't actually perform work dark grey
785 elif node.count - childrensamples == 0: 787 elif node.count - childrensamples == 0: