7 import pstats
, fpformat
11 return string
.rjust(fpformat
.fix(x
, 4), 8)
14 # hacking around a hack
15 if sys
.version
[:3] > '1.4':
18 def timer(TickCount
= Evt
.TickCount
):
19 return TickCount() / 60.0
23 def __init__(self
, stats
= None):
24 self
.sortkeys
= ('calls',)
28 def setupwidgets(self
):
29 self
.w
= W
.Window((580, 400), "Profile Statistics", minsize
= (200, 100), tabbable
= 0)
30 self
.w
.divline
= W
.HorizontalLine((0, 20, 0, 0))
31 self
.w
.titlebar
= W
.TextBox((4, 4, 40, 12), 'Sort by:')
36 for name
in ["calls", "time", "cumulative", "stdname", "file", "line", "name"]:
41 self
.w
["button_" + name
] = W
.RadioButton((x
, 4, width
, 12), name
, self
.buttons
, self
.setsort
)
43 self
.w
.button_calls
.set(1)
44 self
.w
.text
= W
.TextEditor((0, 21, -15, -15), inset
= (6, 5),
45 readonly
= 1, wrap
= 0, fontsettings
= ('Monaco', 0, 9, (0, 0, 0)))
46 self
.w
._bary
= W
.Scrollbar((-15, 20, 16, -14), self
.w
.text
.vscroll
, max = 32767)
47 self
.w
._barx
= W
.Scrollbar((-1, -15, -14, 16), self
.w
.text
.hscroll
, max = 32767)
50 def setstats(self
, stats
):
52 self
.stats
.strip_dirs()
56 # Grmpf. The callback doesn't give us the button:-(
57 for b
in self
.buttons
:
59 if b
._title
== self
.sortkeys
[0]:
61 self
.sortkeys
= (b
._title
,) + self
.sortkeys
[:3]
65 def displaystats(self
):
67 apply(self
.stats
.sort_stats
, self
.sortkeys
)
70 s
= sys
.stdout
= StringIO
.StringIO()
71 self
.stats
.print_stats()
74 text
= string
.join(string
.split(s
.getvalue(), '\n'), '\r')
82 stats
= pstats
.Stats(i
)
83 browser
= ProfileBrowser(stats
)
86 fss
, ok
= macfs
.PromptGetFile('Profiler data')
87 if not ok
: sys
.exit(0)
88 stats
= pstats
.Stats(fss
.as_pathname())
89 browser
= ProfileBrowser(stats
)
91 if __name__
== '__main__':