Show More
@@ -238,7 +238,7 b' class CodeSite(object):' | |||||
238 | lineno = self.lineno - 1 |
|
238 | lineno = self.lineno - 1 | |
239 | fp = None |
|
239 | fp = None | |
240 | try: |
|
240 | try: | |
241 | fp = open(self.path) |
|
241 | fp = open(self.path, 'rb') | |
242 | for i, line in enumerate(fp): |
|
242 | for i, line in enumerate(fp): | |
243 | if i == lineno: |
|
243 | if i == lineno: | |
244 | self.source = line.strip() |
|
244 | self.source = line.strip() | |
@@ -274,8 +274,10 b' class Sample(object):' | |||||
274 | stack = [] |
|
274 | stack = [] | |
275 |
|
275 | |||
276 | while frame: |
|
276 | while frame: | |
277 |
stack.append(CodeSite.get( |
|
277 | stack.append(CodeSite.get( | |
278 |
|
|
278 | pycompat.sysbytes(frame.f_code.co_filename), | |
|
279 | frame.f_lineno, | |||
|
280 | pycompat.sysbytes(frame.f_code.co_name))) | |||
279 | frame = frame.f_back |
|
281 | frame = frame.f_back | |
280 |
|
282 | |||
281 | return Sample(stack, time) |
|
283 | return Sample(stack, time) | |
@@ -372,7 +374,7 b' def save_data(path):' | |||||
372 | file.write("%d\0%s\n" % (time, '\0'.join(sites))) |
|
374 | file.write("%d\0%s\n" % (time, '\0'.join(sites))) | |
373 |
|
375 | |||
374 | def load_data(path): |
|
376 | def load_data(path): | |
375 | lines = open(path, 'r').read().splitlines() |
|
377 | lines = open(path, 'rb').read().splitlines() | |
376 |
|
378 | |||
377 | state.accumulated_time = [float(value) for value in lines[0].split()] |
|
379 | state.accumulated_time = [float(value) for value in lines[0].split()] | |
378 | state.samples = [] |
|
380 | state.samples = [] | |
@@ -512,9 +514,9 b' def display_by_line(data, fp):' | |||||
512 |
|
514 | |||
513 | for stat in stats: |
|
515 | for stat in stats: | |
514 | site = stat.site |
|
516 | site = stat.site | |
515 |
sitelabel = '%s:%d:%s' % ( |
|
517 | sitelabel = '%s:%d:%s' % (site.filename(), | |
516 | site.lineno, |
|
518 | site.lineno, | |
517 |
|
|
519 | site.function) | |
518 | fp.write(b'%6.2f %9.2f %9.2f %s\n' % ( |
|
520 | fp.write(b'%6.2f %9.2f %9.2f %s\n' % ( | |
519 | stat.selfpercent(), stat.totalseconds(), |
|
521 | stat.selfpercent(), stat.totalseconds(), | |
520 | stat.selfseconds(), sitelabel)) |
|
522 | stat.selfseconds(), sitelabel)) | |
@@ -532,7 +534,7 b' def display_by_method(data, fp):' | |||||
532 |
|
534 | |||
533 | grouped = defaultdict(list) |
|
535 | grouped = defaultdict(list) | |
534 | for stat in stats: |
|
536 | for stat in stats: | |
535 |
grouped[stat.site.filename() + |
|
537 | grouped[stat.site.filename() + b":" + stat.site.function].append(stat) | |
536 |
|
538 | |||
537 | # compute sums for each function |
|
539 | # compute sums for each function | |
538 | functiondata = [] |
|
540 | functiondata = [] | |
@@ -561,7 +563,7 b' def display_by_method(data, fp):' | |||||
561 | function[3], # total percent |
|
563 | function[3], # total percent | |
562 | function[1], # total cum sec |
|
564 | function[1], # total cum sec | |
563 | function[2], # total self sec |
|
565 | function[2], # total self sec | |
564 |
|
|
566 | function[0])) # file:function | |
565 |
|
567 | |||
566 | function[4].sort(reverse=True, key=lambda i: i.selfseconds()) |
|
568 | function[4].sort(reverse=True, key=lambda i: i.selfseconds()) | |
567 | for stat in function[4]: |
|
569 | for stat in function[4]: | |
@@ -696,7 +698,7 b' def display_hotpath(data, fp, limit=0.05' | |||||
696 | ' %4.1f%% %s %s' |
|
698 | ' %4.1f%% %s %s' | |
697 | liststring = listpattern % (node.count / root.count * 100, |
|
699 | liststring = listpattern % (node.count / root.count * 100, | |
698 | filename, function) |
|
700 | filename, function) | |
699 |
codepattern = '%' + |
|
701 | codepattern = '%' + ('%d' % (55 - len(liststring))) + 's %d: %s' | |
700 | codestring = codepattern % ('line', site.lineno, site.getsource(30)) |
|
702 | codestring = codepattern % ('line', site.lineno, site.getsource(30)) | |
701 |
|
703 | |||
702 | finalstring = liststring + codestring |
|
704 | finalstring = liststring + codestring | |
@@ -777,7 +779,10 b' def write_to_json(data, fp):' | |||||
777 | stack = [] |
|
779 | stack = [] | |
778 |
|
780 | |||
779 | for frame in sample.stack: |
|
781 | for frame in sample.stack: | |
780 | stack.append((frame.path, frame.lineno, frame.function)) |
|
782 | stack.append( | |
|
783 | (pycompat.sysstr(frame.path), | |||
|
784 | frame.lineno, | |||
|
785 | pycompat.sysstr(frame.function))) | |||
781 |
|
786 | |||
782 | samples.append((sample.time, stack)) |
|
787 | samples.append((sample.time, stack)) | |
783 |
|
788 |
General Comments 0
You need to be logged in to leave comments.
Login now