profiling¶
The profile of a command of a model, with the sampling profiler of python 3.15.
--profile after the model package runs a command of the models under the
statistical sampling profiler of python 3.15 (profiling.sampling, PEP 799)
and writes the profile into the results of the model:
The profiler samples the stack of the command at a fixed rate from a process of
its own, so the command runs at nearly its normal speed. The command runs as a
child of the profiler (python -m profiling.sampling run -m pkpdsim.cli ...),
whose binary profile is converted afterwards (replay) into the files of the
folder profiling/<command>_<time>/ of the results of the model:
flamegraph.html: the interactive flame graph of the sampled stacks;heatmap/: the source code of the sampled lines with their sample counts;profile.pstats: the statistics of the functions, forpstatsand its viewers;summary.txt: the functions with the most samples;profile.bin: the samples, from which other formats are made and against which a later profile is compared (replay --diff-flamegraph profile.bin).
The profiler is part of python 3.15; with an older python --profile is an
error and the command does not run.
profiler_available
¶
Check whether the python has the sampling profiler profiling.sampling.
record_exit_code
¶
Write the exit code of a profiled command, see EXIT_CODE_FILE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
int | str | None
|
the code of |
required |
profile_dir
¶
Get a new folder of the profile of a command in the results of a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PKPDModel
|
the model. |
required |
command
|
str
|
the name of the command, e.g. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
|
run_profiled
¶
Run a command of a model under the sampling profiler, see the module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PKPDModel
|
the model. |
required |
command
|
str
|
the name of the command, a key of |
required |
args
|
Sequence[str]
|
the arguments of the command after the model package, without
|
required |
output
|
Path | None
|
the folder of the profile, |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The exit code of the command. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the python has no sampling profiler. |