A simple time, ram & vram python profiler.
Project description
A simple time and memory Python profiler
Installation
pip install tmprofile
Usage
1. As a context manager
from tmprofile import Profile
with Profile() as profiler:
f(...) # some intensive code
# profile is automatically saved as a json file.
# display elapsed time, RAM & VRAM consumption evolution
profiler.print()
profiler.plot()
2. As a decorator
from tmprofile import profile
@profile()
f(...) # some intensive code
# profile is automatically saved as a json file.
Parameters
name (str): Name of the profiler. Will be used to name the saved file. Required for context manager. For decorator, will use fonction' name if no name is provided.verbose (bool): If True, will print logged values at the end of profiling (i.e. on exit as a context manager, on function's return as a decorator). Defaults to False.gpu_idx (int): Which gpu's VRAM consumption has to be monitored. Default to0.time_delta (float): Time to wait (in second) between two RAM / VRAM consumption logging. Defaults to0.2.output_dir (str | Path): Where to write the logged values (as json). Defaults to.tmprofile.filename (str | Path, optional): Name of the saved json file. If no name is given, will used the profiler name (seenameabove).
Saved logs
Each time it is called, the profiler will saved a file.
The filepath will be <output_dir>/filename.json. By default, <output_dir> is .tmprofile/ and <filename> is:
<name>.jsonifnamewas specified.profile.jsonif the profiler is a context manager andnamewas NOT specified.<module>::<function>.jsonif the profiler is a decorator andnamewas NOT specified.
Interrupt
Since this profiler runs in a separate process, it will gracefully shutdown if the main programm is interrupted.
Disclaimer
The core of this code (asynchronous RAM/VRAM logging) is taken from Thomas Rouch's code here.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tmprofile-0.0.5.tar.gz.
File metadata
- Download URL: tmprofile-0.0.5.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13c4df505d22e7e10044937addfd2def280f922aa8abc99ac71c51bb914a9c9f
|
|
| MD5 |
d547807519499fe36d95d8df91500c96
|
|
| BLAKE2b-256 |
bcb2d0bbea0e8c77d8f63b94347f3e23663dedf7c982035b36d35662bf4c5d31
|
File details
Details for the file tmprofile-0.0.5-py3-none-any.whl.
File metadata
- Download URL: tmprofile-0.0.5-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe8ba7f8c3da8ab2dd414953218ef46ad90ef54c432c7a248a9cfdf985a60a45
|
|
| MD5 |
2860647f58766cc14161f8d8a5337c6c
|
|
| BLAKE2b-256 |
9f82309c6f25e25bf3493893aa69682d51c53e757c15df876997806c09578140
|