Tiny timing helper for printing elapsed times with call-site context
Project description
gadget
A tiny helper for quick timing/debug prints with file and line context.
Install
From PyPI
pip install gadget-timer
To enable memory profiling features:
pip install 'gadget-timer[mem]'
From a local checkout
pip install .
Directly from GitHub
pip install "git+https://github.com/s-maddrellmander/gadget.git"
Editable install (for development)
pip install -e .
Usage
Functional API
from gadget import gadget, gadget_reset, gadget_config
gadget("start")
# ... some code ...
gadget("after step")
gadget("phase 1", group="build")
gadget("phase 2", group="build")
gadget_reset("build")
gadget_config(verbose=False) # disable output globally
Class-based API
from gadget import Gadget
timer = Gadget(verbose=True)
timer("start")
# ... some code ...
timer("step", group="build")
timer.reset("build")
timer.reset() # reset all groups
Memory Profiling
Track memory usage at key checkpoints with color-coded output.
Installation
Memory profiling requires psutil:
pip install 'gadget-timer[mem]'
Functional API
from gadget import gadget_mem
gadget_mem("after_data_load")
# Output: [mem:after_data_load] RSS=2.34GB(7%) swap=0.50GB(6%) sys=10.2/32.0GB(32%) → script.py:42
Class-based API
from gadget import Gadget
timer = Gadget()
timer.mem("model_initialized")
timer.mem("training_started")
Color Coding
Memory output is color-coded based on the highest usage across all metrics:
- 🟢 Green: All memory usage < 50%
- 🟡 Yellow: Any memory usage between 50-80%
- 🔴 Red: Any memory usage > 80%
Metrics Displayed
- RSS: Resident Set Size (process memory usage)
- swap: Swap memory used
- sys: System memory (used/total)
- gpu: GPU memory (if PyTorch with CUDA is available)
All metrics show percentages for at-a-glance assessment.
Notes
-
Package name on PyPI is
gadget-timer. -
Import path is still
gadget. -
For Git installs, the repository URL is:
pip install "git+https://github.com/s-maddrellmander/gadget.git"
Project details
Release history Release notifications | RSS feed
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 gadget_timer-0.2.0.tar.gz.
File metadata
- Download URL: gadget_timer-0.2.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56f9297c6d6e74f1affe46d8a35527a2f6feb6bfa0dcea34890a74a2eb60238d
|
|
| MD5 |
bd1d0255e2df2eb5a46adf8f53432a0d
|
|
| BLAKE2b-256 |
cef0030b3d2b5ae902dfb90b1fe7d0356a7584bed901bb21e0853fcb345f6588
|
Provenance
The following attestation bundles were made for gadget_timer-0.2.0.tar.gz:
Publisher:
publish-pypi.yml on s-maddrellmander/gadget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gadget_timer-0.2.0.tar.gz -
Subject digest:
56f9297c6d6e74f1affe46d8a35527a2f6feb6bfa0dcea34890a74a2eb60238d - Sigstore transparency entry: 1135452423
- Sigstore integration time:
-
Permalink:
s-maddrellmander/gadget@32da1283567eee41cd831b75a68192769748788a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/s-maddrellmander
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@32da1283567eee41cd831b75a68192769748788a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file gadget_timer-0.2.0-py3-none-any.whl.
File metadata
- Download URL: gadget_timer-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee7c6fbc04873896f563c73fa61b05ef76562ead2e2e13abd8dd58727485e8ca
|
|
| MD5 |
e958a02e0ffd947ff544a5fbc7df6f0b
|
|
| BLAKE2b-256 |
f3e464d0bd3037d48b42e20c29dcfcfc73b1ac1ea8879bd805b4ef65ba5750ed
|
Provenance
The following attestation bundles were made for gadget_timer-0.2.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on s-maddrellmander/gadget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gadget_timer-0.2.0-py3-none-any.whl -
Subject digest:
ee7c6fbc04873896f563c73fa61b05ef76562ead2e2e13abd8dd58727485e8ca - Sigstore transparency entry: 1135452459
- Sigstore integration time:
-
Permalink:
s-maddrellmander/gadget@32da1283567eee41cd831b75a68192769748788a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/s-maddrellmander
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@32da1283567eee41cd831b75a68192769748788a -
Trigger Event:
workflow_dispatch
-
Statement type: