/[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

trunk/thuban/Extensions/profiling/profiling.py revision 1901 by jan, Fri Oct 31 16:05:29 2003 UTC branches/WIP-pyshapelib-bramz/Extensions/profiling/profiling.py revision 2734 by bramz, Thu Mar 1 12:42:59 2007 UTC
# Line 1  Line 1 
1  # Copyright (C) 2003 by Intevation GmbH  # Copyright (C) 2003, 2004 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]> (2003)
4    # Jan-Oliver Wagner <[email protected]> (2003, 2004)
5  #  #
6  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
7  # Read the file COPYING coming with the software for details.  # Read the file COPYING coming with the software for details.
# Line 28  import profile Line 29  import profile
29  import time  import time
30  import pstats  import pstats
31    
32  from wxPython.lib.dialogs import wxScrolledMessageDialog  from wx.lib.dialogs import ScrolledMessageDialog
33    
34  from Thuban import _  from Thuban import _
35  from Thuban.UI.command import registry, Command  from Thuban.UI.command import registry, Command
36  import Thuban.UI.mainwindow  from Thuban.UI.mainwindow import main_menu
37    
38  #  #
39  # Customization  # Customization
# Line 48  profiler_bias = 0 Line 49  profiler_bias = 0
49  tempfile.mktemp()  tempfile.mktemp()
50  profile_dir = tempfile.tempdir  profile_dir = tempfile.tempdir
51    
52    # Wether to pop up a dialog box with the result.
53    popup_dialog_box = True
54    
55    
56  #  #
57  #       Timing and profiling a complete redraw  #       Timing and profiling a complete redraw
# Line 81  def profile_screen_renderer(context): Line 85  def profile_screen_renderer(context):
85      how to access the data in the generated .profile file.      how to access the data in the generated .profile file.
86      """      """
87      print "profiling screen renderer...",      print "profiling screen renderer...",
88        sys.stdout.flush()
89      prof = profile.Profile(bias = profiler_bias)      prof = profile.Profile(bias = profiler_bias)
90      prof.runctx("do_redraw(context)", globals(), locals())      prof.runctx("do_redraw(context)", globals(), locals())
91      filename = os.path.join(profile_dir, "thuban-render.profile")      filename = os.path.join(profile_dir, "thuban-render.profile")
92      prof.dump_stats(filename)      prof.dump_stats(filename)
93      print "done and saved to", filename      print "done and saved to", filename
94    
95      # catch the printout to stdout so that we can present the      if popup_dialog_box:
96      # text in a dialog          # catch the printout to stdout so that we can present the
97      f = StringIO.StringIO()          # text in a dialog
98      orig_stdout = sys.stdout          f = StringIO.StringIO()
99      sys.stdout = f          orig_stdout = sys.stdout
100      try:          sys.stdout = f
101          p = pstats.Stats(filename)          try:
102          msg = _('These are the statistics sorted by cumulative time:')              p = pstats.Stats(filename)
103          p.strip_dirs().sort_stats('cumulative').print_stats()              msg = _('These are the statistics sorted by cumulative time:')
104          m = f.getvalue()              p.strip_dirs().sort_stats('cumulative').print_stats()
105          msg = '%s\n\n%s' % (msg, m)              m = f.getvalue()
106      finally:              msg = '%s\n\n%s' % (msg, m)
107          sys.stdout = orig_stdout          finally:
108                sys.stdout = orig_stdout
109      dlg = wxScrolledMessageDialog(context.mainwindow, msg,  
110                                    _('Profile Screen Render'))          dlg = ScrolledMessageDialog(context.mainwindow, msg,
111      dlg.ShowModal()                                        _('Profile Screen Render'))
112            dlg.ShowModal()
113    
114    
115  registry.Add(Command("profile_screen_renderer", _('Profile Screen Render'),  registry.Add(Command("profile_screen_renderer", _('Profile Screen Render'),
# Line 124  def time_screen_renderer(context): Line 130  def time_screen_renderer(context):
130      do_redraw(context)      do_redraw(context)
131      duration = time.clock() - start      duration = time.clock() - start
132      msg = _('Redraw finished in %g seconds.') % duration      msg = _('Redraw finished in %g seconds.') % duration
133      context.mainwindow.RunMessageBox(_('Time Screen Render'), msg)      if popup_dialog_box:
134            context.mainwindow.RunMessageBox(_('Time Screen Render'), msg)
135        else:
136            print msg
137    
138    
139  registry.Add(Command("time_screen_renderer", _('Time Screen Render'),  registry.Add(Command("time_screen_renderer", _('Time Screen Render'),
140                       time_screen_renderer,                       time_screen_renderer,
141                       helptext = _('Time the screen render')))                       helptext = _('Time the screen render')))
142    
   
143  # find the extensions menu (create it anew if not found)  # find the extensions menu (create it anew if not found)
144  main_menu = Thuban.UI.mainwindow.main_menu  extensions_menu = main_menu.FindOrInsertMenu('extensions', _('E&xtensions'))
 extensions_menu = main_menu.find_menu('extensions')  
 if extensions_menu is None:  
     extensions_menu = main_menu.InsertMenu('extensions', _('E&xtensions'))  
145    
146  profiler_menu = extensions_menu.InsertMenu("profiler", _('&Profiler'))  profiler_menu = extensions_menu.InsertMenu("profiler", _('&Profiler'))
147  profiler_menu.InsertItem("time_screen_renderer")  profiler_menu.InsertItem("time_screen_renderer")

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26