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