MCPcopy Index your code
hub / github.com/python/cpython / sort_stats

Method sort_stats

Lib/pstats.py:239–276  ·  view source on GitHub ↗
(self, *field)

Source from the content-addressed store, hash-verified

237 return self.sort_arg_dict
238
239 def sort_stats(self, *field):
240 if not field:
241 self.fcn_list = 0
242 return self
243 if len(field) == 1 and isinstance(field[0], int):
244 # Be compatible with old profiler
245 field = [ {-1: "stdname",
246 0: "calls",
247 1: "time",
248 2: "cumulative"}[field[0]] ]
249 elif len(field) >= 2:
250 for arg in field[1:]:
251 if type(arg) != type(field[0]):
252 raise TypeError("Can't have mixed argument type")
253
254 sort_arg_defs = self.get_sort_arg_defs()
255
256 sort_tuple = ()
257 self.sort_type = ""
258 connector = ""
259 for word in field:
260 if isinstance(word, SortKey):
261 word = word.value
262 sort_tuple = sort_tuple + sort_arg_defs[word][0]
263 self.sort_type += connector + sort_arg_defs[word][1]
264 connector = ", "
265
266 stats_list = []
267 for func, (cc, nc, tt, ct, callers) in self.stats.items():
268 stats_list.append((cc, nc, tt, ct) + func +
269 (func_std_string(func), func))
270
271 stats_list.sort(key=cmp_to_key(TupleComp(sort_tuple).compare))
272
273 self.fcn_list = fcn_list = []
274 for tuple in stats_list:
275 fcn_list.append(tuple[-1])
276 return self
277
278 def reverse_order(self):
279 if self.fcn_list:

Callers 8

do_sortMethod · 0.80
print_statsMethod · 0.80
print_statsMethod · 0.80
test_sort_stats_intMethod · 0.80
test_sort_stats_enumMethod · 0.80
do_profilingMethod · 0.80

Calls 7

get_sort_arg_defsMethod · 0.95
cmp_to_keyFunction · 0.90
func_std_stringFunction · 0.85
TupleCompClass · 0.85
itemsMethod · 0.45
appendMethod · 0.45
sortMethod · 0.45

Tested by 5

test_sort_stats_intMethod · 0.64
test_sort_stats_enumMethod · 0.64
do_profilingMethod · 0.64