Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7720e6ea
Commit
7720e6ea
authored
Apr 21, 1992
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial revision
parent
7408da9c
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
479 additions
and
0 deletions
+479
-0
Lib/profile.doc
Lib/profile.doc
+74
-0
Lib/profile.py
Lib/profile.py
+405
-0
No files found.
Lib/profile.doc
0 → 100644
View file @
7720e6ea
The Python Profiler
To use the profiler in its simplest form:
>>> import profile
>>> profile.run(statement)
This will execute the statement and print statistics. To get more
information out of the profiler, use:
>>> import profile
>>> profile.run(statement, dump_file)
where dump_file is a string naming a file to which the (binary)
profile statistics is to be dumped. The binary format is a dump of a
dictionary. The key is the function name in the format described
above; the value is a tuple consisting of, in order, number of calls,
total time spent in the function, total time spent in the function and
all functions called from it, a list of functions called by this
function, and a list of functions that called this function. The dump
can be read back using the following code:
>>> import marshal
>>> f = open(dump_file, 'r')
>>> dict = marshal.load(f)
>>> f.close()
An easier way of doing this is by using the class `Stats' which is
also defined in profile:
>>> import profile
>>> s = profile.Stats().init(dump_file)
The following methods are defined for instances of `Stats':
print_stats() -- Print the statistics in a format similar to
the format profile.run() uses.
print_callers() -- For each function, print all functions
which it calls.
print_callees() -- For each function, print all functions from
which it is called.
sort_stats(n) -- Sort the statistics for subsequent
printing. The argument determines on which
field the output should be sorted.
Possibilities are
-1 function name
0 number of calls
1 total time spent in a function
2 total time spent in a function
plus all functions it called
strip_dirs() -- Strip the directory names off of the file
names which are part of the function names.
This undoes the effect of sort_stats(), but
a subsequent sort_stats() does work.
The methods sort_stats and strip_dirs may change in the future.
Output of profile.run(statement) and of the print_stats() method of
the `Stats' class consists of the following fields.
Number of times the function was called.
Total time spent in the function.
Mean time per function call (second field divided by first).
Total time spent in the function and all functions it called,
recursively.
Mean time time spent in the function and all functions it
called (fourth field divided by first).
Name of the function in the format
<file name>:<line number>(<function name>)
The output of the print_callers and print_callees methods consists of
the name of the function and the names of all function it called or
was called from. The latter names are followed by a parenthesised
number which is the number of calls for this function.
Lib/profile.py
0 → 100755
View file @
7720e6ea
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment