Skip to main content

Tiny timing helper for printing elapsed times with call-site context

Project description

gadget

Tests

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gadget_timer-0.2.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gadget_timer-0.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

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

Hashes for gadget_timer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 56f9297c6d6e74f1affe46d8a35527a2f6feb6bfa0dcea34890a74a2eb60238d
MD5 bd1d0255e2df2eb5a46adf8f53432a0d
BLAKE2b-256 cef0030b3d2b5ae902dfb90b1fe7d0356a7584bed901bb21e0853fcb345f6588

See more details on using hashes here.

Provenance

The following attestation bundles were made for gadget_timer-0.2.0.tar.gz:

Publisher: publish-pypi.yml on s-maddrellmander/gadget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for gadget_timer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee7c6fbc04873896f563c73fa61b05ef76562ead2e2e13abd8dd58727485e8ca
MD5 e958a02e0ffd947ff544a5fbc7df6f0b
BLAKE2b-256 f3e464d0bd3037d48b42e20c29dcfcfc73b1ac1ea8879bd805b4ef65ba5750ed

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page