Back to index

python3.2  3.2.2
Classes | Functions | Variables
profile Namespace Reference

Classes

class  Profile

Functions

def run
def runctx
def _get_time_times
def _get_time_resource
def main

Variables

list __all__ = ["run", "runctx", "Profile"]
int _has_res = 0
tuple resgetrusage = lambda:resource.getrusage(resource.RUSAGE_SELF)

Function Documentation

def profile._get_time_resource (   timer = resgetrusage) [private]

Definition at line 99 of file profile.py.

00099 
00100     def _get_time_resource(timer=resgetrusage):
00101         t = timer()
        return t[0] + t[1]

Here is the call graph for this function:

def profile._get_time_times (   timer = os.times) [private]

Definition at line 87 of file profile.py.

00087 
00088     def _get_time_times(timer=os.times):
00089         t = timer()
00090         return t[0] + t[1]
00091 
00092 # Using getrusage(3) is better than clock(3) if available:
00093 # on some systems (e.g. FreeBSD), getrusage has a higher resolution
00094 # Furthermore, on a POSIX system, returns microseconds, which
# wrap around after 36min.

Here is the call graph for this function:

def profile.main ( void  )

Definition at line 569 of file profile.py.

00569 
00570 def main():
00571     usage = "profile.py [-o output_file_path] [-s sort] scriptfile [arg] ..."
00572     parser = OptionParser(usage=usage)
00573     parser.allow_interspersed_args = False
00574     parser.add_option('-o', '--outfile', dest="outfile",
00575         help="Save stats to <outfile>", default=None)
00576     parser.add_option('-s', '--sort', dest="sort",
00577         help="Sort order when printing to stdout, based on pstats.Stats class",
00578         default=-1)
00579 
00580     if not sys.argv[1:]:
00581         parser.print_usage()
00582         sys.exit(2)
00583 
00584     (options, args) = parser.parse_args()
00585     sys.argv[:] = args
00586 
00587     if len(args) > 0:
00588         progname = args[0]
00589         sys.path.insert(0, os.path.dirname(progname))
00590         with open(progname, 'rb') as fp:
00591             code = compile(fp.read(), progname, 'exec')
00592         globs = {
00593             '__file__': progname,
00594             '__name__': '__main__',
00595             '__package__': None,
00596             '__cached__': None,
00597         }
00598         runctx(code, globs, None, options.outfile, options.sort)
00599     else:
00600         parser.print_usage()
00601     return parser
00602 
# When invoked as main program, invoke the profiler on a script

Here is the call graph for this function:

def profile.run (   statement,
  filename = None,
  sort = -1 
)
Run statement under profiler optionally saving results in filename

This function takes a single argument that can be passed to the
"exec" statement, and an optional file name.  In all cases this
routine attempts to "exec" its first argument and gather profiling
statistics from the execution. If no file name is present, then this
function automatically prints a simple profiling report, sorted by the
standard name string (file/line/function-name) that is presented in
each line.

Definition at line 48 of file profile.py.

00048 
00049 def run(statement, filename=None, sort=-1):
00050     """Run statement under profiler optionally saving results in filename
00051 
00052     This function takes a single argument that can be passed to the
00053     "exec" statement, and an optional file name.  In all cases this
00054     routine attempts to "exec" its first argument and gather profiling
00055     statistics from the execution. If no file name is present, then this
00056     function automatically prints a simple profiling report, sorted by the
00057     standard name string (file/line/function-name) that is presented in
00058     each line.
00059     """
00060     prof = Profile()
00061     try:
00062         prof = prof.run(statement)
00063     except SystemExit:
00064         pass
00065     if filename is not None:
00066         prof.dump_stats(filename)
00067     else:
00068         return prof.print_stats(sort)

def profile.runctx (   statement,
  globals,
  locals,
  filename = None,
  sort = -1 
)
Run statement under profiler, supplying your own globals and locals,
optionally saving results in filename.

statement and filename have the same semantics as profile.run

Definition at line 69 of file profile.py.

00069 
00070 def runctx(statement, globals, locals, filename=None, sort=-1):
00071     """Run statement under profiler, supplying your own globals and locals,
00072     optionally saving results in filename.
00073 
00074     statement and filename have the same semantics as profile.run
00075     """
00076     prof = Profile()
00077     try:
00078         prof = prof.runctx(statement, globals, locals)
00079     except SystemExit:
00080         pass
00081 
00082     if filename is not None:
00083         prof.dump_stats(filename)
00084     else:
00085         return prof.print_stats(sort)

Here is the caller graph for this function:


Variable Documentation

list profile.__all__ = ["run", "runctx", "Profile"]

Definition at line 33 of file profile.py.

Definition at line 95 of file profile.py.

tuple profile.resgetrusage = lambda:resource.getrusage(resource.RUSAGE_SELF)

Definition at line 98 of file profile.py.