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:')
33 self
.w
.button_calls
= W
.RadioButton((54, 4, 45, 12), 'calls', self
.buttons
, self
.setsort
)
34 self
.w
.button_time
= W
.RadioButton((104, 4, 40, 12), 'time', self
.buttons
, self
.setsort
)
35 self
.w
.button_cumulative
= W
.RadioButton((154, 4, 75, 12), 'cumulative', self
.buttons
, self
.setsort
)
36 self
.w
.button_stdname
= W
.RadioButton((234, 4, 60, 12), 'stdname', self
.buttons
, self
.setsort
)
37 self
.w
.button_calls
.set(1)
38 self
.w
.button_file
= W
.RadioButton((304, 4, 40, 12), 'file', self
.buttons
, self
.setsort
)
39 self
.w
.button_line
= W
.RadioButton((354, 4, 50, 12), 'line', self
.buttons
, self
.setsort
)
40 self
.w
.button_name
= W
.RadioButton((404, 4, 50, 12), 'name', self
.buttons
, self
.setsort
)
41 ## self.w.button_nfl = W.RadioButton((4, 4, 12, 12), 'nfl', self.buttons, self.setsort)
42 ## self.w.button_pcalls = W.RadioButton((4, 4, 12, 12), 'pcalls', self.buttons, self.setsort)
43 self
.w
.text
= W
.TextEditor((0, 21, -15, -15), inset
= (6, 5),
44 readonly
= 1, wrap
= 0, fontsettings
= ('Monaco', 0, 9, (0, 0, 0)))
45 self
.w
._bary
= W
.Scrollbar((-15, 20, 16, -14), self
.w
.text
.vscroll
, max = 32767)
46 self
.w
._barx
= W
.Scrollbar((-1, -15, -14, 16), self
.w
.text
.hscroll
, max = 32767)
49 def setstats(self
, stats
):
51 self
.stats
.strip_dirs()
55 # Grmpf. The callback doesn't give us the button:-(
56 for b
in self
.buttons
:
58 if b
._title
== self
.sortkeys
[0]:
60 self
.sortkeys
= (b
._title
,) + self
.sortkeys
[:3]
64 def displaystats(self
):
66 apply(self
.stats
.sort_stats
, self
.sortkeys
)
69 s
= sys
.stdout
= StringIO
.StringIO()
70 self
.stats
.print_stats()
73 text
= string
.join(string
.split(s
.getvalue(), '\n'), '\r')
81 stats
= pstats
.Stats(i
)
82 browser
= ProfileBrowser(stats
)
85 fss
, ok
= macfs
.PromptGetFile('Profiler data')
86 if not ok
: sys
.exit(0)
87 stats
= pstats
.Stats(fss
.as_pathname())
88 browser
= ProfileBrowser(stats
)
90 if __name__
== '__main__':