summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Smith <bruce@nanorex.com>2008-10-16 00:55:49 +0000
committerBruce Smith <bruce@nanorex.com>2008-10-16 00:55:49 +0000
commitd04f955bb402e125b9e3b1863432e270eaa96b81 (patch)
tree044fe8548b1860fc6749cfc2dffb2689412f8ac3
parent28d913f8e6cc55b902052c28e1c7144d18b4c835 (diff)
downloadnanoengineer-d04f955bb402e125b9e3b1863432e270eaa96b81.tar.gz
nanoengineer-d04f955bb402e125b9e3b1863432e270eaa96b81.zip
misc trivial cleanups in profiling code
-rw-r--r--cad/src/graphics/widgets/GLPane_rendering_methods.py6
-rwxr-xr-xcad/src/ne1_startup/main_startup.py46
-rwxr-xr-xcad/src/utilities/debug.py4
-rw-r--r--cad/src/widgets/DebugMenuMixin.py7
4 files changed, 37 insertions, 26 deletions
diff --git a/cad/src/graphics/widgets/GLPane_rendering_methods.py b/cad/src/graphics/widgets/GLPane_rendering_methods.py
index faf03eaef..fb852618a 100644
--- a/cad/src/graphics/widgets/GLPane_rendering_methods.py
+++ b/cad/src/graphics/widgets/GLPane_rendering_methods.py
@@ -42,8 +42,6 @@ from utilities import debug_flags
from utilities.debug import print_compact_traceback, print_compact_stack
-### from utilities.debug import profile, doProfile ###
-
from utilities.Comparison import same_vals
import foundation.env as env
@@ -122,10 +120,6 @@ class GLPane_rendering_methods(GLPane_image_methods):
"""
return True
- ### def _paintGL(self): ###
- ### profile( self.paintGL2) ###
- ### doProfile(False) ###
-
def _paintGL(self):
"""
[private; the body of paintGL in GLPane.py]
diff --git a/cad/src/ne1_startup/main_startup.py b/cad/src/ne1_startup/main_startup.py
index a87e873ca..32fb01ba3 100755
--- a/cad/src/ne1_startup/main_startup.py
+++ b/cad/src/ne1_startup/main_startup.py
@@ -325,37 +325,55 @@ def startup_script( main_globals):
# to record the decision, which are used later when running
# the Qt event loop.
- # If the user's .atom-debug-rc specifies PROFILE_WITH_HOTSHOT = True, use hotshot, otherwise
- # fall back to vanilla Python profiler.
+ # If the user's .atom-debug-rc specifies PROFILE_WITH_HOTSHOT = True,
+ # use hotshot, otherwise fall back to vanilla Python profiler.
+ # (Note: to work, it probably has to import this module
+ # and set this variable in this module's namespace.)
try:
PROFILE_WITH_HOTSHOT
except NameError:
PROFILE_WITH_HOTSHOT = False
try:
- # user can set this to a filename in .atom-debug-rc,
- # to enable profiling into that file
+ # user can set atom_debug_profile_filename to a filename in .atom-debug-rc,
+ # to enable profiling into that file. For example:
+ # % cd
+ # % cat > .atom-debug-rc
+ # atom_debug_profile_filename = '/tmp/profile-output'
+ # ^D
+ # ... then run NE1, and quit it
+ # ... then in a python shell:
+ # import pstats
+ # p = pstats.Stats('<filename>')
+ # p.strip_dirs().sort_stats('time').print_stats(100) # order by internal time (top 100 functions)
+ # p.strip_dirs().sort_stats('cumulative').print_stats(100) # order by cumulative time
atom_debug_profile_filename = main_globals['atom_debug_profile_filename']
if atom_debug_profile_filename:
print ("\nUser's .atom-debug-rc requests profiling into file %r" %
(atom_debug_profile_filename,))
if not type(atom_debug_profile_filename) in [type("x"), type(u"x")]:
- print ("error: atom_debug_profile_filename must be a string;" +
- "running without profiling")
+ print "error: atom_debug_profile_filename must be a string"
assert 0 # caught and ignored, turns off profiling
if PROFILE_WITH_HOTSHOT:
try:
import hotshot
except:
- print "error during 'import hotshot'; running without profiling"
+ print "error during 'import hotshot'"
raise # caught and ignored, turns off profiling
else:
try:
- import cProfile
- except:
- print "error during 'import profile'; running without profiling"
- raise # caught and ignored, turns off profiling
+ import cProfile as py_Profile
+ except ImportError:
+ print "Unable to import cProfile. Using profile module instead."
+ py_Profile = None
+ if py_Profile is None:
+ try:
+ import profile as py_Profile
+ except:
+ print "error during 'import profile'"
+ raise # caught and ignored, turns off profiling
except:
+ print "exception setting up profiling (hopefully reported above); running without profiling"
atom_debug_profile_filename = None
@@ -395,12 +413,12 @@ def startup_script( main_globals):
profile = hotshot.Profile(atom_debug_profile_filename)
profile.run('app.exec_()')
else:
- cProfile.run('from ne1_startup.main_startup import app; app.exec_()',
- atom_debug_profile_filename)
+ py_Profile.run('from ne1_startup.main_startup import app; app.exec_()',
+ atom_debug_profile_filename)
print ("\nProfile data was presumably saved into %r" %
(atom_debug_profile_filename,))
else:
- # if you change this code, also change the string literals just above
+ # if you change this code, also change both string literals just above
app.exec_()
diff --git a/cad/src/utilities/debug.py b/cad/src/utilities/debug.py
index 44d0e9033..bab90443a 100755
--- a/cad/src/utilities/debug.py
+++ b/cad/src/utilities/debug.py
@@ -744,14 +744,14 @@ def profile(func, *args, **keywordArgs):
try:
import cProfile as py_Profile
except ImportError:
- print "Unable to import cProfile. using profile module instead."
+ print "Unable to import cProfile. Using profile module instead."
import profile as py_Profile
filePath = os.path.dirname(os.path.abspath(sys.argv[0])) + "/" + _profile_output_file
filePath = os.path.normpath(filePath)
print "Capturing profile..."
- print "Profile output file: %s"%(filePath)
+ print "Profile output file: %s" % (filePath,)
py_Profile.run('from utilities.debug import _run_profile; _run_profile()', _profile_output_file)
print "...end of profile capture"
diff --git a/cad/src/widgets/DebugMenuMixin.py b/cad/src/widgets/DebugMenuMixin.py
index 6ac552f6b..14e5d88c8 100644
--- a/cad/src/widgets/DebugMenuMixin.py
+++ b/cad/src/widgets/DebugMenuMixin.py
@@ -356,7 +356,6 @@ class DebugMenuMixin:
def _debug_do_benchmark(self):
# simple graphics benchmark, piotr 080311
from time import clock
- from utilities.debug import profile
print "Entering graphics benchmark. Drawing 100 frames... please wait."
win = self._debug_win
self.win.resize(1024,768) # resize the window to a constant size
@@ -412,10 +411,10 @@ class DebugMenuMixin:
tm0 = clock()
profile(meth, commandName)
tm1 = clock()
- print "Profiling complete. Total time to enter %s = %s"%(commandName,
- (tm1-tm0))
+ print "Profiling complete. Total time to enter %s = %s" % \
+ (commandName, (tm1 - tm0))
doProfile(False)
-
+ return
def debug_menu_source_name(self): #bruce 050112
"""