changeset 40385:cc4586749c8c

statprof: fix overflow while skipping boilerplate parts I got IndexError randomly because of stack[i] where i = len(stack).
author Yuya Nishihara <yuya@tcha.org>
date Sat, 20 Oct 2018 20:25:56 +0900
parents fc4c598dd4a0
children 4a81d82474e9
files mercurial/statprof.py
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/statprof.py	Sat Oct 20 20:15:48 2018 +0900
+++ b/mercurial/statprof.py	Sat Oct 20 20:25:56 2018 +0900
@@ -257,6 +257,9 @@
     def filename(self):
         return os.path.basename(self.path)
 
+    def skipname(self):
+        return r'%s:%s' % (self.filename(), self.function)
+
 class Sample(object):
     __slots__ = (u'stack', u'time')
 
@@ -661,10 +664,8 @@
             if len(stack) > 1:
                 i = 1
                 # Skip boiler plate parts of the stack
-                name = r'%s:%s' % (stack[i].filename(), stack[i].function)
-                while i < len(stack) and name in skips:
+                while i < len(stack) and stack[i].skipname() in skips:
                     i += 1
-                    name = r'%s:%s' % (stack[i].filename(), stack[i].function)
                 if i < len(stack):
                     child.add(stack[i:], time)