/[thuban]/branches/WIP-pyshapelib-bramz/Extensions/profiling/profiling.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Extensions/profiling/profiling.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1896 by bh, Fri Oct 31 11:55:33 2003 UTC revision 1901 by jan, Fri Oct 31 16:05:29 2003 UTC
# Line 21  __version__ = "$Revision$" Line 21  __version__ = "$Revision$"
21  # $Id$  # $Id$
22    
23  import os  import os
24    import StringIO
25    import sys
26  import tempfile  import tempfile
27  import profile  import profile
28  import time  import time
29    import pstats
30    
31    from wxPython.lib.dialogs import wxScrolledMessageDialog
32    
33    from Thuban import _
34  from Thuban.UI.command import registry, Command  from Thuban.UI.command import registry, Command
35  import Thuban.UI.mainwindow  import Thuban.UI.mainwindow
 menu = Thuban.UI.mainwindow.main_menu.InsertMenu("profiler", "&Profiler")  
36    
37  #  #
38  # Customization  # Customization
# Line 82  def profile_screen_renderer(context): Line 87  def profile_screen_renderer(context):
87      prof.dump_stats(filename)      prof.dump_stats(filename)
88      print "done and saved to", filename      print "done and saved to", filename
89    
90        # catch the printout to stdout so that we can present the
91        # text in a dialog
92        f = StringIO.StringIO()
93        orig_stdout = sys.stdout
94        sys.stdout = f
95        try:
96            p = pstats.Stats(filename)
97            msg = _('These are the statistics sorted by cumulative time:')
98            p.strip_dirs().sort_stats('cumulative').print_stats()
99            m = f.getvalue()
100            msg = '%s\n\n%s' % (msg, m)
101        finally:
102            sys.stdout = orig_stdout
103    
104        dlg = wxScrolledMessageDialog(context.mainwindow, msg,
105                                      _('Profile Screen Render'))
106        dlg.ShowModal()
107    
108    
109  registry.Add(Command("profile_screen_renderer", "Profile Screen Render",  registry.Add(Command("profile_screen_renderer", _('Profile Screen Render'),
110                       profile_screen_renderer,                       profile_screen_renderer,
111                       helptext = "Profile the screen render"))                       helptext = _('Profile the screen render')))
 menu.InsertItem("profile_screen_renderer")  
112    
113    
114  #  #
# Line 100  def time_screen_renderer(context): Line 122  def time_screen_renderer(context):
122      """      """
123      start = time.clock()      start = time.clock()
124      do_redraw(context)      do_redraw(context)
125      print "redraw finished in", time.clock() - start, "s"      duration = time.clock() - start
126        msg = _('Redraw finished in %g seconds.') % duration
127        context.mainwindow.RunMessageBox(_('Time Screen Render'), msg)
128    
129    
130  registry.Add(Command("time_screen_renderer", "Time Screen Render",  registry.Add(Command("time_screen_renderer", _('Time Screen Render'),
131                       time_screen_renderer,                       time_screen_renderer,
132                       helptext = "Time the screen render"))                       helptext = _('Time the screen render')))
133  menu.InsertItem("time_screen_renderer")  
134    
135    # find the extensions menu (create it anew if not found)
136    main_menu = Thuban.UI.mainwindow.main_menu
137    extensions_menu = main_menu.find_menu('extensions')
138    if extensions_menu is None:
139        extensions_menu = main_menu.InsertMenu('extensions', _('E&xtensions'))
140    
141    profiler_menu = extensions_menu.InsertMenu("profiler", _('&Profiler'))
142    profiler_menu.InsertItem("time_screen_renderer")
143    profiler_menu.InsertItem("profile_screen_renderer")

Legend:
Removed from v.1896  
changed lines
  Added in v.1901

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26