mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Refactor interesting use of try-finally.
This commit is contained in:
parent
eb7e56922e
commit
9a8439d3e9
1 changed files with 9 additions and 10 deletions
|
@ -93,15 +93,12 @@ class Stats:
|
||||||
self.stats = {}
|
self.stats = {}
|
||||||
self.sort_arg_dict = {}
|
self.sort_arg_dict = {}
|
||||||
self.load_stats(arg)
|
self.load_stats(arg)
|
||||||
trouble = 1
|
|
||||||
try:
|
try:
|
||||||
self.get_top_level_stats()
|
self.get_top_level_stats()
|
||||||
trouble = 0
|
except Exception:
|
||||||
finally:
|
print("Invalid timing data %s" %
|
||||||
if trouble:
|
(self.files[-1] if self.files else ''), file=self.stream)
|
||||||
print("Invalid timing data", end=' ', file=self.stream)
|
raise
|
||||||
if self.files: print(self.files[-1], end=' ', file=self.stream)
|
|
||||||
print(file=self.stream)
|
|
||||||
|
|
||||||
def load_stats(self, arg):
|
def load_stats(self, arg):
|
||||||
if arg is None:
|
if arg is None:
|
||||||
|
@ -271,7 +268,8 @@ class Stats:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def calc_callees(self):
|
def calc_callees(self):
|
||||||
if self.all_callees: return
|
if self.all_callees:
|
||||||
|
return
|
||||||
self.all_callees = all_callees = {}
|
self.all_callees = all_callees = {}
|
||||||
for func, (cc, nc, tt, ct, callers) in self.stats.items():
|
for func, (cc, nc, tt, ct, callers) in self.stats.items():
|
||||||
if not func in all_callees:
|
if not func in all_callees:
|
||||||
|
@ -341,7 +339,8 @@ class Stats:
|
||||||
def print_stats(self, *amount):
|
def print_stats(self, *amount):
|
||||||
for filename in self.files:
|
for filename in self.files:
|
||||||
print(filename, file=self.stream)
|
print(filename, file=self.stream)
|
||||||
if self.files: print(file=self.stream)
|
if self.files:
|
||||||
|
print(file=self.stream)
|
||||||
indent = ' ' * 8
|
indent = ' ' * 8
|
||||||
for func in self.top_level:
|
for func in self.top_level:
|
||||||
print(indent, func_get_function_name(func), file=self.stream)
|
print(indent, func_get_function_name(func), file=self.stream)
|
||||||
|
@ -427,7 +426,7 @@ class Stats:
|
||||||
print(' ncalls tottime percall cumtime percall', end=' ', file=self.stream)
|
print(' ncalls tottime percall cumtime percall', end=' ', file=self.stream)
|
||||||
print('filename:lineno(function)', file=self.stream)
|
print('filename:lineno(function)', file=self.stream)
|
||||||
|
|
||||||
def print_line(self, func): # hack : should print percentages
|
def print_line(self, func): # hack: should print percentages
|
||||||
cc, nc, tt, ct, callers = self.stats[func]
|
cc, nc, tt, ct, callers = self.stats[func]
|
||||||
c = str(nc)
|
c = str(nc)
|
||||||
if nc != cc:
|
if nc != cc:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue