/[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 1914 by jan, Fri Oct 31 16:05:29 2003 UTC revision 1915 by bh, Mon Nov 3 14:19:40 2003 UTC
# Line 48  profiler_bias = 0 Line 48  profiler_bias = 0
48  tempfile.mktemp()  tempfile.mktemp()
49  profile_dir = tempfile.tempdir  profile_dir = tempfile.tempdir
50    
51    # Wether to pop up a dialog box with the result.
52    popup_dialog_box = True
53    
54    
55  #  #
56  #       Timing and profiling a complete redraw  #       Timing and profiling a complete redraw
# Line 81  def profile_screen_renderer(context): Line 84  def profile_screen_renderer(context):
84      how to access the data in the generated .profile file.      how to access the data in the generated .profile file.
85      """      """
86      print "profiling screen renderer...",      print "profiling screen renderer...",
87        sys.stdout.flush()
88      prof = profile.Profile(bias = profiler_bias)      prof = profile.Profile(bias = profiler_bias)
89      prof.runctx("do_redraw(context)", globals(), locals())      prof.runctx("do_redraw(context)", globals(), locals())
90      filename = os.path.join(profile_dir, "thuban-render.profile")      filename = os.path.join(profile_dir, "thuban-render.profile")
91      prof.dump_stats(filename)      prof.dump_stats(filename)
92      print "done and saved to", filename      print "done and saved to", filename
93    
94      # catch the printout to stdout so that we can present the      if popup_dialog_box:
95      # text in a dialog          # catch the printout to stdout so that we can present the
96      f = StringIO.StringIO()          # text in a dialog
97      orig_stdout = sys.stdout          f = StringIO.StringIO()
98      sys.stdout = f          orig_stdout = sys.stdout
99      try:          sys.stdout = f
100          p = pstats.Stats(filename)          try:
101          msg = _('These are the statistics sorted by cumulative time:')              p = pstats.Stats(filename)
102          p.strip_dirs().sort_stats('cumulative').print_stats()              msg = _('These are the statistics sorted by cumulative time:')
103          m = f.getvalue()              p.strip_dirs().sort_stats('cumulative').print_stats()
104          msg = '%s\n\n%s' % (msg, m)              m = f.getvalue()
105      finally:              msg = '%s\n\n%s' % (msg, m)
106          sys.stdout = orig_stdout          finally:
107                sys.stdout = orig_stdout
108      dlg = wxScrolledMessageDialog(context.mainwindow, msg,  
109                                    _('Profile Screen Render'))          dlg = wxScrolledMessageDialog(context.mainwindow, msg,
110      dlg.ShowModal()                                        _('Profile Screen Render'))
111            dlg.ShowModal()
112    
113    
114  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 129  def time_screen_renderer(context):
129      do_redraw(context)      do_redraw(context)
130      duration = time.clock() - start      duration = time.clock() - start
131      msg = _('Redraw finished in %g seconds.') % duration      msg = _('Redraw finished in %g seconds.') % duration
132      context.mainwindow.RunMessageBox(_('Time Screen Render'), msg)      if popup_dialog_box:
133            context.mainwindow.RunMessageBox(_('Time Screen Render'), msg)
134        else:
135            print msg
136    
137    
138  registry.Add(Command("time_screen_renderer", _('Time Screen Render'),  registry.Add(Command("time_screen_renderer", _('Time Screen Render'),

Legend:
Removed from v.1914  
changed lines
  Added in v.1915

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26