@@ -142,20 +142,20 @@ def add(self, *arg_list):
142142 self .total_calls += other .total_calls
143143 self .prim_calls += other .prim_calls
144144 self .total_tt += other .total_tt
145- for func in other .top_level . keys () :
145+ for func in other .top_level :
146146 self .top_level [func ] = None
147147
148148 if self .max_name_len < other .max_name_len :
149149 self .max_name_len = other .max_name_len
150150
151151 self .fcn_list = None
152152
153- for func in other .stats .keys ():
153+ for func , stat in other .stats .iteritems ():
154154 if func in self .stats :
155155 old_func_stat = self .stats [func ]
156156 else :
157157 old_func_stat = (0 , 0 , 0 , 0 , {},)
158- self .stats [func ] = add_func_stats (old_func_stat , other . stats [ func ] )
158+ self .stats [func ] = add_func_stats (old_func_stat , stat )
159159 return self
160160
161161 # list the tuple indices and directions for sorting,
@@ -178,17 +178,17 @@ def get_sort_arg_defs(self):
178178 if not self .sort_arg_dict :
179179 self .sort_arg_dict = dict = {}
180180 bad_list = {}
181- for word in self .sort_arg_dict_default .keys ():
181+ for word , tup in self .sort_arg_dict_default .iteritems ():
182182 fragment = word
183183 while fragment :
184184 if not fragment :
185185 break
186186 if fragment in dict :
187187 bad_list [fragment ] = 0
188188 break
189- dict [fragment ] = self . sort_arg_dict_default [ word ]
189+ dict [fragment ] = tup
190190 fragment = fragment [:- 1 ]
191- for word in bad_list . keys () :
191+ for word in bad_list :
192192 del dict [word ]
193193 return self .sort_arg_dict
194194
@@ -213,8 +213,7 @@ def sort_stats(self, *field):
213213 connector = ", "
214214
215215 stats_list = []
216- for func in self .stats .keys ():
217- cc , nc , tt , ct , callers = self .stats [func ]
216+ for func , (cc , nc , tt , ct , callers ) in self .stats .iteritems ():
218217 stats_list .append ((cc , nc , tt , ct ) + func +
219218 (func_std_string (func ), func ))
220219
@@ -234,14 +233,13 @@ def strip_dirs(self):
234233 oldstats = self .stats
235234 self .stats = newstats = {}
236235 max_name_len = 0
237- for func in oldstats .keys ():
238- cc , nc , tt , ct , callers = oldstats [func ]
236+ for func , (cc , nc , tt , ct , callers ) in oldstats .iteritems ():
239237 newfunc = func_strip_path (func )
240238 if len (func_std_string (newfunc )) > max_name_len :
241239 max_name_len = len (func_std_string (newfunc ))
242240 newcallers = {}
243- for func2 in callers .keys ():
244- newcallers [func_strip_path (func2 )] = callers [ func2 ]
241+ for func2 , caller in callers .iteritems ():
242+ newcallers [func_strip_path (func2 )] = caller
245243
246244 if newfunc in newstats :
247245 newstats [newfunc ] = add_func_stats (
@@ -251,7 +249,7 @@ def strip_dirs(self):
251249 newstats [newfunc ] = (cc , nc , tt , ct , newcallers )
252250 old_top = self .top_level
253251 self .top_level = new_top = {}
254- for func in old_top . keys () :
252+ for func in old_top :
255253 new_top [func_strip_path (func )] = None
256254
257255 self .max_name_len = max_name_len
@@ -263,14 +261,13 @@ def strip_dirs(self):
263261 def calc_callees (self ):
264262 if self .all_callees : return
265263 self .all_callees = all_callees = {}
266- for func in self .stats .keys ():
264+ for func , ( cc , nc , tt , ct , callers ) in self .stats .iteritems ():
267265 if not func in all_callees :
268266 all_callees [func ] = {}
269- cc , nc , tt , ct , callers = self .stats [func ]
270- for func2 in callers .keys ():
267+ for func2 , caller in callers .iteritems ():
271268 if not func2 in all_callees :
272269 all_callees [func2 ] = {}
273- all_callees [func2 ][func ] = callers [ func2 ]
270+ all_callees [func2 ][func ] = caller
274271 return
275272
276273 #******************************************************************
@@ -330,7 +327,7 @@ def print_stats(self, *amount):
330327 print filename
331328 if self .files : print
332329 indent = ' ' * 8
333- for func in self .top_level . keys () :
330+ for func in self .top_level :
334331 print indent , func_get_function_name (func )
335332
336333 print indent , self .total_calls , "function calls" ,
@@ -468,20 +465,20 @@ def add_func_stats(target, source):
468465def add_callers (target , source ):
469466 """Combine two caller lists in a single list."""
470467 new_callers = {}
471- for func in target .keys ():
472- new_callers [func ] = target [ func ]
473- for func in source .keys ():
468+ for func , caller in target .iteritems ():
469+ new_callers [func ] = caller
470+ for func , caller in source .iteritems ():
474471 if func in new_callers :
475- new_callers [func ] = source [ func ] + new_callers [func ]
472+ new_callers [func ] = caller + new_callers [func ]
476473 else :
477- new_callers [func ] = source [ func ]
474+ new_callers [func ] = caller
478475 return new_callers
479476
480477def count_calls (callers ):
481478 """Sum the caller statistics to get total number of calls received."""
482479 nc = 0
483- for func in callers .keys ():
484- nc += callers [ func ]
480+ for calls in callers .itervalues ():
481+ nc += calls
485482 return nc
486483
487484#**************************************************************************
@@ -595,19 +592,19 @@ def help_reverse(self):
595592 print "Reverse the sort order of the profiling report."
596593
597594 def do_sort (self , line ):
598- abbrevs = self .stats .get_sort_arg_defs (). keys ()
595+ abbrevs = self .stats .get_sort_arg_defs ()
599596 if line and not filter (lambda x ,a = abbrevs : x not in a ,line .split ()):
600597 apply (self .stats .sort_stats , line .split ())
601598 else :
602599 print "Valid sort keys (unique prefixes are accepted):"
603- for (key , value ) in Stats .sort_arg_dict_default .items ():
600+ for (key , value ) in Stats .sort_arg_dict_default .iteritems ():
604601 print "%s -- %s" % (key , value [1 ])
605602 return 0
606603 def help_sort (self ):
607604 print "Sort profile data according to specified keys."
608605 print "(Typing `sort' without arguments lists valid keys.)"
609606 def complete_sort (self , text , * args ):
610- return [a for a in Stats .sort_arg_dict_default . keys () if a .startswith (text )]
607+ return [a for a in Stats .sort_arg_dict_default if a .startswith (text )]
611608
612609 def do_stats (self , line ):
613610 return self .generic ('print_stats' , line )
0 commit comments