Patchwork [2,of,2] statprof: fix overflow while skipping boilerplate parts

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 20, 2018, 11:33 a.m.
Message ID <cc4586749c8c99885619.1540035205@mimosa>
Download mbox | patch
Permalink /patch/36209/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 20, 2018, 11:33 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1540034756 -32400
#      Sat Oct 20 20:25:56 2018 +0900
# Node ID cc4586749c8c99885619eaaa17e3157176c4523c
# Parent  fc4c598dd4a0443977aff8c1b5d77c6377bd30cc
statprof: fix overflow while skipping boilerplate parts

I got IndexError randomly because of stack[i] where i = len(stack).

Patch

diff --git a/mercurial/statprof.py b/mercurial/statprof.py
--- a/mercurial/statprof.py
+++ b/mercurial/statprof.py
@@ -257,6 +257,9 @@  class CodeSite(object):
     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 @@  def display_hotpath(data, fp, limit=0.05
             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)