generated from pypa/sampleproject
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# pstats | ||
|
||
My documentation of python pstats objects. | ||
|
||
# docs | ||
|
||
`pstats` has type `dict[tuple[str, int, str], tuple[int, int, int, int, list[tuple[int, int, int, int]]]]`. | ||
|
||
The `pstats` object is marshal-ed dictionary object with tuple of `(filename, lineno, funcname)` of keys and tuple of `(cc, nc, tt, ct, callers)` as values. | ||
|
||
The tuple elements of `pstats[func]` hold: | ||
- `cc` is the number of primitive calls to the function. Primitive calls are all calls minus recursive calls. | ||
- `nc` is the number of all calls to the function. | ||
- `tt` is the time spent in the function excluding the time spent in subfunctions. | ||
- If a function calls itself recursively, then this time is summed. | ||
- `ct` is the time spent in the function. | ||
- If a function calls itself recursively, then this time is effectively ignored. | ||
- `callers` is a list of a nested tuple of `(cc, nc, tt, ct)`. The tuple elements `pstats[func].callers[func2]` hold: | ||
- `cc` - the the number of calls `func2` made to `func` | ||
- `nc` - always equal to `cc`, just ignore | ||
- `tt` - the time spent in such `func2` calls that at least one called `func` excluding the time spent in subfunction | ||
- `ct` - the time spent in such `func2` calls that at least one called `func` | ||
|
||
The following properties hold: | ||
- `pstats.keys()` holds __all__ functions that were executed in the script | ||
- `set(c for s in pstats.values() for c in s.callers).issubset(stats.keys())` | ||
- `all(s.nc >= s.cc for s in pstats.values())` | ||
- `all(f.nc == sum(c.nc for s in stats.values() for c in stats.callers.values()))` | ||
|
||
# links | ||
|
||
- https://github.com/python/cpython/blob/main/Lib/cProfile.py#L63 | ||
- https://github.com/python/cpython/blob/main/Modules/_lsprof.c#L31 | ||
- https://github.com/python/cpython/blob/main/Lib/pstats.py#L160 | ||
- https://docs.python.org/3/library/profile.html | ||
- https://zameermanji.com/blog/2012/6/30/undocumented-cprofile-features/ | ||
- https://stackoverflow.com/questions/15816415/in-python-cprofile-what-is-the-difference-between-calls-count-and-primitive-cal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
MAKEFLAGS = -rR --warn-undefined-variables --no-show-directories | ||
SHELL = bash | ||
$(shell mkdir -vp build) | ||
|
||
compare_script1: build/a build/b | ||
paste -d'@' build/a build/b | column -t -s '@' | ||
build/script1.py.prof: ./script.1py | ||
@mkdir -vp build | ||
build/script1.py.prof: ./script1.py | ||
python -m cProfile -o $@ script1.py | ||
build/script1.sh.txt: ../src/L_bash_profile.py ./script1.py | ||
@mkdir -vp build | ||
L_bash_profile profile -o $@ '. ./script1.sh' | ||
build/script1.sh.prof: build/script1.sh.txt | ||
@mkdir -vp build | ||
L_bash_profile analyze --pstats $^ $@ | ||
build/a: build/script1.sh.prof | ||
@mkdir -vp build | ||
L_bash_profile showpstats -r $^ > $@ | ||
build/b: build/script1.py.prof | ||
@mkdir -vp build | ||
L_bash_profile showpstats -r $^ > $@ | ||
build/script1.sh.prof: build/script1.sh.txt | ||
L_bash_profile analyze --pstats $@ $< | ||
build/a: build/script1.sh.prof ../src/L_bash_profile.py | ||
L_bash_profile showpstats -r $< > $@ | ||
build/b: build/script1.py.prof ../src/L_bash_profile.py | ||
L_bash_profile showpstats -r $< > $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters