Skip to main content

profile-decorator

Problem/Motivation

Find memory leaks in Python code quickly without significant code changes in a quickly digestible manner such that the root cause can be easily diagnosed.

Until open-telemetry Adds metrics API, I want a quick and dirty decorator that will give me the memory usage of the process in scope before and after a function is run.

Usage

# example.py
from profile_decorator import profile_decorator

profile_decorator.init()


@profile_decorator.profile_memory
def my_func():
    print("hello, world")


if __name__ == "__main__":
    my_func()
$ poetry run python example.py
hello, world
{
  "start_time": "2021-08-29T13:20:31.435036",
  "uss_memory_before": 6852608,
  "end_time": "2021-08-29T13:20:31.435892",
  "uss_memory_after": 6995968,
  "lines": [
    {
      "filename": "/home/harry/projects/GitHub/hkiang01/profile-decorator/example.py",
      "lineno": 7,
      "size": 752,
      "size_diff": 0
    },
    {
      "filename": "/home/harry/projects/GitHub/hkiang01/profile-decorator/example.py",
      "lineno": 12,
      "size": 560,
      "size_diff": 0
    }
  ]
}

Design

The decorator will collect the following information:

  • name of function
  • filepath
  • line number
  • memory usage before function is run
  • timestamp when function is called
  • timestamp when function is finished
  • memory usage after function is run

It will expose this in json or other easily digestble format for reporting purposes.

Metadata

Release files for profile-decorator 0.1.0

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

Source distribution (sdist)

Source distribution for profile-decorator 0.1.0
File Size Uploaded Provenance
profile-decorator-0.1.0.tar.gz 3.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for profile-decorator 0.1.0
File Interpreter ABI Platform
profile_decorator-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.7 kB

Release files / profile-decorator-0.1.0.tar.gz

Download URL profile-decorator-0.1.0.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c260c0ecbab054070c1f7d941d7139cf945c644dc07b1e060d165060020a2684
BLAKE2b-256 checksum
How to use checksums
c9f8087550d97c083575067fefc802a0e4e4bc6dc29ff3d53cedab0a5e716614
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.8 CPython/3.9.5 Linux/5.11.0-31-generic

Release files / profile_decorator-0.1.0-py3-none-any.whl

Download URL profile_decorator-0.1.0-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d3c117192dd482fa99ecd7a2d0fbd04f157e769eb3c100242d6b52ff247ee73
BLAKE2b-256 checksum
How to use checksums
972a6c0f2483878a524356533b448c25e7949e2b40481363ed9db1b14b785994
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.8 CPython/3.9.5 Linux/5.11.0-31-generic

Security for profile-decorator 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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