A Python script profiler using @profile decorators
Project description
Line Profiler Extension for Python (lprof_ext)
lprof_ext is a lightweight Python script profiler that seamlessly integrates with the line_profiler library. It simplifies performance analysis by automatically adding @profile decorators to your Python code and collecting detailed line-by-line performance statistics. This tool is ideal for developers looking to identify bottlenecks and optimize their Python scripts efficiently.
Features
- Automatic Profiling: Adds
@profiledecorators to your code without manual intervention. - Line-by-Line Analysis: Leverages line_profiler to provide granular performance metrics for each line of code.
- Easy Integration: Works with any Python script via a simple command-line interface.
- Lightweight: Minimal dependencies and straightforward setup.
- Open Source: Freely available for contributions and customization.
Installation
From PyPI
Install the latest stable version of lprof_ext using pip:
pip3 install --no-cache-dir lprof_ext
Prerequisites
- Python 3.8 or higher
line_profiler(automatically installed as a dependency)
Usage
To profile a Python script, run the following command, replacing <entrypoint.py> with the path to your script:
lprof_ext <entrypoint.py>
Example
Suppose you have a script named example.py:
def compute_fibonacci(n):
if n <= 1:
return n
return compute_fibonacci(n-1) + compute_fibonacci(n-2)
def main():
result = compute_fibonacci(30)
print(f"Result: {result}")
if __name__ == "__main__":
main()
Run the profiler:
lprof_ext example.py
After execution, lprof_ext will output performance statistics into profile.json, showing execution time, number of calls, and percentage of time spent on each line of code in the profiled functions.
Output
The output will be store in JSON format. You can visualize it using our GUI tool prof_gui
docker run --rm -d --name prof_gui \
-v ./profile.json:/profile.json \
-p 8080:8080 \
ruprof/prof_gui:rs
Build from Source
If you prefer to build lprof_ext from source (e.g., to use the latest development version or contribute), follow these steps:
- Clone the repository (replace with the actual URL):
git clone https://github.com/RuProf/lprof_ext
cd lprof_ext
- Set up a virtual environment (optional but recommended):
python3 -m venv .venv
source .venv/bin/activate
- Install dependencies and build the package using uv (or pip if uv is unavailable):
uv sync
pip3 install .
- Verify the installation:
lprof_ext -h
Requirements for Building
- uv (optional, for dependency management; install via pip install uv)
- setuptools and wheel (for building the package)
Reference
lprof_ext is built on top of the excellent line_profiler library. For more details on how line-by-line profiling works, refer to the official documentation:
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
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 lprof_ext-0.1.0.tar.gz.
File metadata
- Download URL: lprof_ext-0.1.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aad69135733d974a1899774332706dd1cf4c81e2ff4be79ac0d986ba25a0ce7e
|
|
| MD5 |
bbbbdfe4a8a2903159aca89923d8763e
|
|
| BLAKE2b-256 |
38ab6a0cbbe80949dc100035043ed059efcb5b033e4abd29988ecc3ebe41573a
|
File details
Details for the file lprof_ext-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lprof_ext-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ce71c802334eb42294377ca182251407b32d45b6bd304319be6ff6e6b14a959
|
|
| MD5 |
1fcd7e891b30861411bdde3112a94174
|
|
| BLAKE2b-256 |
849c619e7610b90c7ca03f8b464281ef54f25bc34d5574622e6568e12b714ab0
|