Skip to main content

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 to 0.
  • time_delta (float): Time to wait (in second) between two RAM / VRAM consumption logging. Defaults to 0.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 (see name above).

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>.json if name was specified.
  • profile.json if the profiler is a context manager and name was NOT specified.
  • <module>::<function>.json if the profiler is a decorator and name was 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.

Metadata

Release files for tmprofile 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tmprofile 0.0.5
File Size Uploaded
tmprofile-0.0.5.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tmprofile 0.0.5
File Interpreter ABI Platform
tmprofile-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / tmprofile-0.0.5.tar.gz

Download URL tmprofile-0.0.5.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
13c4df505d22e7e10044937addfd2def280f922aa8abc99ac71c51bb914a9c9f
BLAKE2b-256 checksum
How to use checksums
bcb2d0bbea0e8c77d8f63b94347f3e23663dedf7c982035b36d35662bf4c5d31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.18

Release files / tmprofile-0.0.5-py3-none-any.whl

Download URL tmprofile-0.0.5-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe8ba7f8c3da8ab2dd414953218ef46ad90ef54c432c7a248a9cfdf985a60a45
BLAKE2b-256 checksum
How to use checksums
9f82309c6f25e25bf3493893aa69682d51c53e757c15df876997806c09578140
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.18

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page