Skip to main content

Profile code regions in python, optionally with LIKWID markers.

Project description

scope-profiler

This module provides a unified profiling system for Python applications, with optional integration of LIKWID markers using the pylikwid marker API for hardware performance counters.

It allows you to:

  • Configure profiling globally via a singleton ProfilingConfig.
  • Collect timing data via context-managed profiling regions.
  • Use a clean decorator syntax to profile functions.
  • Optionally record time traces in HDF5 files.
  • Automatically initialize and close LIKWID markers only when needed.
  • Print aggregated summaries of all profiling regions.

Install

Install from PyPI:

pip install scope-profiler

Usage

To set up the configuration, create an instance of ProfilingConfig and add it to the ProfileManager, this should be done once at application startup and will persist until the program exits or is explicitly finalized (see below). Note that the config applies to any profiling contexts created (even in other files) after it has been initialized.

from scope_profiler import ProfileManager

# Setup global profiling configuration
ProfileManager.setup(
    use_likwid=False,
    time_trace=True,
    flush_to_disk=True,
)

# Profile the main() function with a decorator
@ProfileManager.profile("main")
def main():
    x = 0
    for i in range(10):
        # Profile each iteration with a context manager
        with ProfileManager.profile_region(region_name="iteration"):
            x += 1

# Call main
main()

# Finalize profiler
ProfileManager.finalize()

Execution:

 python test.py
Region: main
  Total Calls : 1
  Total Time  : 0.001503709 s
  Avg Time    : 0.001503709 s
  Min Time    : 0.001503709 s
  Max Time    : 0.001503709 s
  Std Dev     : 0.0 s
----------------------------------------
Region: iteration
  Total Calls : 10
  Total Time  : 3.832e-06 s
  Avg Time    : 3.832e-07 s
  Min Time    : 2.08e-07 s
  Max Time    : 8.75e-07 s
  Std Dev     : 2.2431888016838885e-07 s
----------------------------------------

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

scope_profiler-0.1.6.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

scope_profiler-0.1.6-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file scope_profiler-0.1.6.tar.gz.

File metadata

  • Download URL: scope_profiler-0.1.6.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for scope_profiler-0.1.6.tar.gz
Algorithm Hash digest
SHA256 bf8362531f6cf8f42c4e460bedd8e183a01f26f1e374b8128b3a8587b18c99fe
MD5 39199b47a5bf9ec1dbe569c8412a283d
BLAKE2b-256 7e9c4dc0d3f8c732278ec772e6c3aba2d28331c1322612285266c9580ba9b441

See more details on using hashes here.

Provenance

The following attestation bundles were made for scope_profiler-0.1.6.tar.gz:

Publisher: publish.yml on max-models/scope-profiler

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

File details

Details for the file scope_profiler-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: scope_profiler-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for scope_profiler-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 37efaba382b8edee144fe8985ca2d11eaf0cb03626ebde8390883d0844d1e15d
MD5 2e2591c7df63388eba0a77e577f6ca9c
BLAKE2b-256 d3e9923c93db5af36690b307ea79cf719c7552751b796ab41bdca94d5a6b54a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for scope_profiler-0.1.6-py3-none-any.whl:

Publisher: publish.yml on max-models/scope-profiler

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