Name | python-memory-profiler JSON |
Version |
0.4.4
JSON |
| download |
home_page | None |
Summary | A Python library for memory usage profiling and visualization. |
upload_time | 2025-01-18 13:36:21 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.6 |
license | MIT License Copyright (c) 2024 Ghassene Jebali Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
memory
profiling
monitoring
performance
python
|
VCS |
|
bugtrack_url |
|
requirements |
psutil
numpy
matplotlib
pyyaml
tqdm
omegaconf
pytest
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Python Memory Profiler
Python Memory Profiler is a Python package designed for efficient and customizable memory usage monitoring of Python programs. It allows developers to track memory metrics such as data, RSS (Resident Set Size), swap usage, and USS (Unique Set Size) for specific functions in their applications.
## Features
- **Lightweight Memory Profiling**: Monitors memory metrics for specific functions.
- **Configurable Settings**: Adjustable sampling frequency and profiling duration.
- **Visualization**: Automatically generates plots of memory usage trends.
- **Data Persistence**: Saves memory metrics for further analysis.
## Installation
```bash
pip install python-memory-profiler
```
### From source
If you want to install the dev version, clone the repository and install the dependencies:
```bash
$ git clone https://github.com/GhasseneJebali/python-memory-profiler.git
$ cd python-memory-profiler
$ pip install -e . -r requirements.txt
```
## Usage
### Decorator-Based Profiling
You can use the `@profile_memory_decorator` to profile memory usage for specific functions.
```python
from memory_profiler.decorators import memory_profiler_decorator
@memory_profiler_decorator
def my_function():
# Your code here
pass
if __name__ == "__main__":
my_function()
```
This will:
- Monitor the memory usage of `my_function`.
- Save the memory metrics in the `data` folder.
- Generate a memory usage plot.
### Custom Profiling with `Profiler` Class
For more control, you can directly use the `Profiler` class:
```python
import os
from memory_profiler.src.profiler import Profiler
if __name__ == "__main__":
pid = os.getpid()
profiler = Profiler(pid, "my_function")
profiler.start()
# Your code here
# If monitor is not specified, all metrics will be logged
# Logged metrics are data, rss, uss and swap
profiler.save(monitor=None)
profiler.plot(monitor=None)
```
### Configuration
If you installed the package from source, you can adjust default profiling parameters such as sampling frequency and output path by modifying the `src/configs/config.yaml` configuration file:
```yaml
max_timer: 0 # Maximum time (in seconds) to profile the process
path: profiler_data # Directory where profiling data and plots will be saved
frequency: 0.1 # Sampling frequency (in seconds)
metrics: ["data", "rss", "swap", "uss"]
```
For more information, check `Profiler` class documentation.
## Output
The profiling results are saved as `.dat` files in the specified output directory and as `.png` plots showing memory usage trends over time.
### Example Plot
![Memory Usage Example](https://github.com/GhasseneJebali/python-memory-profiler/blob/main/examples/profiler_data/array_handler/memory_plot_array_handler_450155_data.png?raw=true)
## Contributing
Contributions are welcome! If you encounter any issues or have suggestions, feel free to open an issue or submit a pull request.
1. Fork the repository.
2. Create a new branch.
3. Make your changes.
4. Submit a pull request.
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## Author
Developed by [Ghassene Jebali](https://github.com/GhasseneJebali).
Raw data
{
"_id": null,
"home_page": null,
"name": "python-memory-profiler",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "memory, profiling, monitoring, performance, python",
"author": null,
"author_email": "Ghassene Jebali <ghassene.jebali@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/21/17/9802f567868d79c6baf1d5631a78279507a3bfdba63b83830b1b143cc59a/python_memory_profiler-0.4.4.tar.gz",
"platform": null,
"description": "# Python Memory Profiler\n\nPython Memory Profiler is a Python package designed for efficient and customizable memory usage monitoring of Python programs. It allows developers to track memory metrics such as data, RSS (Resident Set Size), swap usage, and USS (Unique Set Size) for specific functions in their applications.\n\n## Features\n\n- **Lightweight Memory Profiling**: Monitors memory metrics for specific functions.\n- **Configurable Settings**: Adjustable sampling frequency and profiling duration.\n- **Visualization**: Automatically generates plots of memory usage trends.\n- **Data Persistence**: Saves memory metrics for further analysis.\n\n## Installation\n\n```bash\npip install python-memory-profiler\n```\n\n### From source\nIf you want to install the dev version, clone the repository and install the dependencies:\n\n```bash\n$ git clone https://github.com/GhasseneJebali/python-memory-profiler.git\n$ cd python-memory-profiler\n$ pip install -e . -r requirements.txt\n```\n\n## Usage\n\n### Decorator-Based Profiling\n\nYou can use the `@profile_memory_decorator` to profile memory usage for specific functions.\n\n```python\nfrom memory_profiler.decorators import memory_profiler_decorator\n\n@memory_profiler_decorator\ndef my_function():\n # Your code here\n pass\n\nif __name__ == \"__main__\":\n my_function()\n```\n\nThis will:\n- Monitor the memory usage of `my_function`.\n- Save the memory metrics in the `data` folder.\n- Generate a memory usage plot.\n\n### Custom Profiling with `Profiler` Class\n\nFor more control, you can directly use the `Profiler` class:\n\n```python\nimport os\n\nfrom memory_profiler.src.profiler import Profiler\n\n\nif __name__ == \"__main__\":\n \n pid = os.getpid()\n\n profiler = Profiler(pid, \"my_function\")\n profiler.start()\n\n # Your code here\n\n # If monitor is not specified, all metrics will be logged\n # Logged metrics are data, rss, uss and swap \n profiler.save(monitor=None)\n profiler.plot(monitor=None)\n```\n\n### Configuration\n\nIf you installed the package from source, you can adjust default profiling parameters such as sampling frequency and output path by modifying the `src/configs/config.yaml` configuration file:\n\n```yaml\nmax_timer: 0 # Maximum time (in seconds) to profile the process\npath: profiler_data # Directory where profiling data and plots will be saved\nfrequency: 0.1 # Sampling frequency (in seconds)\n\nmetrics: [\"data\", \"rss\", \"swap\", \"uss\"]\n```\n\nFor more information, check `Profiler` class documentation.\n\n## Output\n\nThe profiling results are saved as `.dat` files in the specified output directory and as `.png` plots showing memory usage trends over time.\n\n### Example Plot\n\n![Memory Usage Example](https://github.com/GhasseneJebali/python-memory-profiler/blob/main/examples/profiler_data/array_handler/memory_plot_array_handler_450155_data.png?raw=true)\n\n## Contributing\n\nContributions are welcome! If you encounter any issues or have suggestions, feel free to open an issue or submit a pull request.\n\n1. Fork the repository.\n2. Create a new branch.\n3. Make your changes.\n4. Submit a pull request.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Author\n\nDeveloped by [Ghassene Jebali](https://github.com/GhasseneJebali).\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Ghassene Jebali Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "A Python library for memory usage profiling and visualization.",
"version": "0.4.4",
"project_urls": {
"Homepage": "https://github.com/GhasseneJebali/python-memory-profiler",
"Repository": "https://github.com/GhasseneJebali/python-memory-profiler"
},
"split_keywords": [
"memory",
" profiling",
" monitoring",
" performance",
" python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3bffa1a2877b30198adbe153bf6ee3e5a8583760fca09779eb6b5d8c80b17e27",
"md5": "be0555f20fb587fc6665cfb559597ccc",
"sha256": "46b457ec2d23758071a55e716aa9db93b0d4b65046a022139199d4da7ee3b2fc"
},
"downloads": -1,
"filename": "python_memory_profiler-0.4.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "be0555f20fb587fc6665cfb559597ccc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 124971,
"upload_time": "2025-01-18T13:36:18",
"upload_time_iso_8601": "2025-01-18T13:36:18.712065Z",
"url": "https://files.pythonhosted.org/packages/3b/ff/a1a2877b30198adbe153bf6ee3e5a8583760fca09779eb6b5d8c80b17e27/python_memory_profiler-0.4.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "21179802f567868d79c6baf1d5631a78279507a3bfdba63b83830b1b143cc59a",
"md5": "693fb6dbd66c1868f04ffa827314baa3",
"sha256": "d43b6dd5aefcf3835bca89a73d2e758c7c5fb248dcbf485708d055fe16d9ce02"
},
"downloads": -1,
"filename": "python_memory_profiler-0.4.4.tar.gz",
"has_sig": false,
"md5_digest": "693fb6dbd66c1868f04ffa827314baa3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 125401,
"upload_time": "2025-01-18T13:36:21",
"upload_time_iso_8601": "2025-01-18T13:36:21.444078Z",
"url": "https://files.pythonhosted.org/packages/21/17/9802f567868d79c6baf1d5631a78279507a3bfdba63b83830b1b143cc59a/python_memory_profiler-0.4.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-18 13:36:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "GhasseneJebali",
"github_project": "python-memory-profiler",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "psutil",
"specs": []
},
{
"name": "numpy",
"specs": []
},
{
"name": "matplotlib",
"specs": []
},
{
"name": "pyyaml",
"specs": []
},
{
"name": "tqdm",
"specs": []
},
{
"name": "omegaconf",
"specs": []
},
{
"name": "pytest",
"specs": []
}
],
"lcname": "python-memory-profiler"
}