scope-profiler


Namescope-profiler JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryProfile code regions in python, optionally with LIKWID markers.
upload_time2025-11-15 11:47:40
maintainerNone
docs_urlNone
authorMax
requires_python>=3.8
licenseNone
keywords python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # scope-profiler

This module provides a unified profiling system for Python applications, with optional integration of [LIKWID](https://github.com/RRZE-HPC/likwid) markers using the [pylikwid](https://github.com/RRZE-HPC/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.

Documentation: https://max-models.github.io/scope-profiler/

## Install

Install from [PyPI](https://pypi.org/project/scope-profiler/):

```
pip install scope-profiler
```

## Usage

To set up the configuration, create an instance of `ProfilingConfig`, 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.

```python
from scope_profiler import ProfilingConfig, ProfileManager

# Setup global profiling configuration
config = ProfilingConfig(
    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()    

# Print summary of profiling results
ProfileManager.print_summary()

# Finalize profiler
ProfileManager.finalize()
```

Execution:

```bash
❯ python test.py
Profiling Summary:
========================================
Region: main
  Number of Calls: 1
  Total Duration: 0.000315 seconds
  Average Duration: 0.000315 seconds
  Min Duration: 0.000315 seconds
  Max Duration: 0.000315 seconds
  Std Deviation: 0.000000 seconds
----------------------------------------
Region: iteration
  Number of Calls: 10
  Total Duration: 0.000007 seconds
  Average Duration: 0.000001 seconds
  Min Duration: 0.000000 seconds
  Max Duration: 0.000003 seconds
  Std Deviation: 0.000001 seconds
----------------------------------------
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "scope-profiler",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "python",
    "author": "Max",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/ba/91/da1affadb03e1c2c3f31fe3c81faf7ef9de277dfc717cc0146fad87b463e/scope_profiler-0.1.2.tar.gz",
    "platform": null,
    "description": "# scope-profiler\n\nThis module provides a unified profiling system for Python applications, with optional integration of [LIKWID](https://github.com/RRZE-HPC/likwid) markers using the [pylikwid](https://github.com/RRZE-HPC/pylikwid) marker API for hardware performance counters.\n\nIt allows you to:\n\n- Configure profiling globally via a singleton ProfilingConfig.\n- Collect timing data via context-managed profiling regions.\n- Use a clean decorator syntax to profile functions.\n- Optionally record time traces in HDF5 files.\n- Automatically initialize and close LIKWID markers only when needed.\n- Print aggregated summaries of all profiling regions.\n\nDocumentation: https://max-models.github.io/scope-profiler/\n\n## Install\n\nInstall from [PyPI](https://pypi.org/project/scope-profiler/):\n\n```\npip install scope-profiler\n```\n\n## Usage\n\nTo set up the configuration, create an instance of `ProfilingConfig`, 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.\n\n```python\nfrom scope_profiler import ProfilingConfig, ProfileManager\n\n# Setup global profiling configuration\nconfig = ProfilingConfig(\n    use_likwid=False,\n    time_trace=True,\n    flush_to_disk=True,\n)\n\n# Profile the main() function with a decorator\n@ProfileManager.profile(\"main\")\ndef main():\n    x = 0\n    for i in range(10):\n        # Profile each iteration with a context manager\n        with ProfileManager.profile_region(region_name=\"iteration\"):\n            x += 1\n\n# Call main\nmain()    \n\n# Print summary of profiling results\nProfileManager.print_summary()\n\n# Finalize profiler\nProfileManager.finalize()\n```\n\nExecution:\n\n```bash\n\u276f python test.py\nProfiling Summary:\n========================================\nRegion: main\n  Number of Calls: 1\n  Total Duration: 0.000315 seconds\n  Average Duration: 0.000315 seconds\n  Min Duration: 0.000315 seconds\n  Max Duration: 0.000315 seconds\n  Std Deviation: 0.000000 seconds\n----------------------------------------\nRegion: iteration\n  Number of Calls: 10\n  Total Duration: 0.000007 seconds\n  Average Duration: 0.000001 seconds\n  Min Duration: 0.000000 seconds\n  Max Duration: 0.000003 seconds\n  Std Deviation: 0.000001 seconds\n----------------------------------------\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Profile code regions in python, optionally with LIKWID markers.",
    "version": "0.1.2",
    "project_urls": {
        "Source": "https://github.com/max-models/scope_profiler"
    },
    "split_keywords": [
        "python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "17fcc6daf4aa85aa218cbc08741107bdb11d1fc1d05e08ae8ad6901428340a07",
                "md5": "6525a99641fe85977e6d0405a957a41d",
                "sha256": "6eeb9b66f587347392b0ac15f1411ceab5dcd0c076999cc6eadd2d6bbb7f48be"
            },
            "downloads": -1,
            "filename": "scope_profiler-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6525a99641fe85977e6d0405a957a41d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 13416,
            "upload_time": "2025-11-15T11:47:39",
            "upload_time_iso_8601": "2025-11-15T11:47:39.119851Z",
            "url": "https://files.pythonhosted.org/packages/17/fc/c6daf4aa85aa218cbc08741107bdb11d1fc1d05e08ae8ad6901428340a07/scope_profiler-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ba91da1affadb03e1c2c3f31fe3c81faf7ef9de277dfc717cc0146fad87b463e",
                "md5": "a0724e7872f80f5600dc2fa6bc3cb075",
                "sha256": "83b876bdc87d0e09bc6947f9a485a0e9fd2b97da4855e43298e21ce75b07f3d0"
            },
            "downloads": -1,
            "filename": "scope_profiler-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a0724e7872f80f5600dc2fa6bc3cb075",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 12013,
            "upload_time": "2025-11-15T11:47:40",
            "upload_time_iso_8601": "2025-11-15T11:47:40.523696Z",
            "url": "https://files.pythonhosted.org/packages/ba/91/da1affadb03e1c2c3f31fe3c81faf7ef9de277dfc717cc0146fad87b463e/scope_profiler-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-11-15 11:47:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "max-models",
    "github_project": "scope_profiler",
    "github_not_found": true,
    "lcname": "scope-profiler"
}
        
Max
Elapsed time: 2.36151s