Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/statprof.py @ 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 | 93501a5fd62b |
comparison
equal
deleted
inserted
replaced
40384:fc4c598dd4a0 | 40385:cc4586749c8c |
---|---|
255 return source | 255 return source |
256 | 256 |
257 def filename(self): | 257 def filename(self): |
258 return os.path.basename(self.path) | 258 return os.path.basename(self.path) |
259 | 259 |
260 def skipname(self): | |
261 return r'%s:%s' % (self.filename(), self.function) | |
262 | |
260 class Sample(object): | 263 class Sample(object): |
261 __slots__ = (u'stack', u'time') | 264 __slots__ = (u'stack', u'time') |
262 | 265 |
263 def __init__(self, stack, time): | 266 def __init__(self, stack, time): |
264 self.stack = stack | 267 self.stack = stack |
659 self.children[site] = child | 662 self.children[site] = child |
660 | 663 |
661 if len(stack) > 1: | 664 if len(stack) > 1: |
662 i = 1 | 665 i = 1 |
663 # Skip boiler plate parts of the stack | 666 # Skip boiler plate parts of the stack |
664 name = r'%s:%s' % (stack[i].filename(), stack[i].function) | 667 while i < len(stack) and stack[i].skipname() in skips: |
665 while i < len(stack) and name in skips: | |
666 i += 1 | 668 i += 1 |
667 name = r'%s:%s' % (stack[i].filename(), stack[i].function) | |
668 if i < len(stack): | 669 if i < len(stack): |
669 child.add(stack[i:], time) | 670 child.add(stack[i:], time) |
670 | 671 |
671 root = HotNode(None) | 672 root = HotNode(None) |
672 lasttime = data.samples[0].time | 673 lasttime = data.samples[0].time |