~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to profile_imports.py

  • Committer: John Arbash Meinel
  • Date: 2006-06-18 04:39:17 UTC
  • mto: This revision was merged to the branch mainline in revision 1794.
  • Revision ID: john@arbash-meinel.com-20060618043917-6d0009ac9f628ca4
More layout work

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
    _info[this].append(cost)
69
69
 
70
70
 
71
 
def log_stack_info(out_file):
 
71
def log_stack_info(out_file, sorted=True):
72
72
    # Find all of the roots with import = 0
73
73
    out_file.write('cum   inline name\t\t\tscope\t\t\tframe\n')
74
 
    todo = [key for key,value in _info.iteritems() if value[0] == 0]
 
74
    todo = [(value[-1], key) for key,value in _info.iteritems() if value[0] == 0]
 
75
 
 
76
    if sorted:
 
77
        todo.sort()
75
78
 
76
79
    while todo:
77
 
        cur = todo.pop()
 
80
        cum_time, cur = todo.pop()
78
81
        children = _total_stack[cur]
79
82
 
 
83
        c_times = []
 
84
 
80
85
        info = _info[cur]
81
86
        # Compute the module time by removing the children times
82
87
        mod_time = info[-1]
83
88
        for child in children:
84
89
            c_info = _info[child]
85
90
            mod_time -= c_info[-1]
 
91
            c_times.append((c_info[-1], child))
86
92
 
87
93
        scope_name = info[3]
88
94
        if scope_name is None:
89
 
            txt = '%-64s' % (cur[1],)
 
95
            txt = '%-62s' % (cur[1][:64],)
90
96
        else:
91
 
            txt = '%-28s\tfor %-24s' % (cur[1], scope_name)
 
97
            txt = '%-27s\tfor %-24s' % (cur[1], scope_name)
92
98
        # indent, cum_time, mod_time, name,
93
99
        # scope_name, frame_name, frame_lineno
94
100
        out_file.write('%5.1f %5.1f %s %s\t@ %s:%d\n'
95
101
            % (info[-1]*1000., mod_time*1000., '+'*info[0], 
96
102
               txt, info[1], info[2]))
97
103
 
98
 
        todo.extend(reversed(children))
 
104
        if sorted:
 
105
            c_times.sort()
 
106
        else:
 
107
            c_times.reverse()
 
108
        todo.extend(c_times)
99
109
 
100
110
 
101
111
_real_import = __import__