Registry / observability / memory-profiler

memory-profiler

JSON →
library0.61.0pypypi✓ verified 24d ago

memory-profiler is a Python module designed for monitoring the memory consumption of a Python process, including detailed line-by-line analysis of memory usage within Python programs. It is built purely in Python and depends on the `psutil` module. The current version is 0.61.0. As of the latest information, the package is no longer actively maintained by its original developers.

pip install -U memory-profiler
INSTALL
IMPORT
SIG · MEMORY-PROFILER
M
memory-profiler
observabilitypythonv0.61.0
Install
1.8s avg
Import
320ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.61.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.336s · 18.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.304s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

profile
from memory_profiler import profile
from memory_profiler import profile # when running with mprof run
When using `mprof run` to collect time-based memory usage with timestamps, do NOT import `profile` within your script. Only apply the `@profile` decorator to functions you want to profile. Importing `profile` will prevent timestamps from being recorded by `mprof`.
memory_usage
from memory_profiler import memory_usage

To perform a line-by-line memory usage analysis, decorate the function you want to profile with `@profile`. Then, run your script using the `python -m memory_profiler` command. The output will be printed to standard output, showing memory usage and increments for each line within the decorated function.

import time from memory_profiler import profile # Save this as 'my_script.py' @profile def create_large_lists(): a = [0] * (10 ** 6) # Allocates ~8MB time.sleep(0.1) b = [1] * (2 * 10 ** 7) # Allocates ~160MB time.sleep(0.1) c = [2] * (5 * 10 ** 6) # Allocates ~40MB del b # Frees ~160MB return a, c if __name__ == '__main__': print("Starting memory intensive task...") lists = create_large_lists() print("Task completed.") # The profiling output will be printed to stdout when run via python -m memory_profiler
mprof --version
Debug
Known issues
deprecatedThe `memory-profiler` package is no longer actively maintained by its original developers. While functional, new features or active issue resolution are unlikely.
fix
For new projects, consider exploring more actively maintained memory profiling alternatives (e.g., `memray`, `fil-profiler`). For existing projects, be aware that support might be limited.
affects: 0.61.0 onwards
gotchaWhen using the `mprof run` command-line utility for time-based memory usage with timestamps, importing `@profile` directly in your Python script (`from memory_profiler import profile`) will prevent timestamps from being recorded.
fix
Comment out the `from memory_profiler import profile` statement when running with `mprof run` to ensure timestamps are captured, leaving only the `@profile` decorator on functions.
affects: All versions
gotchaUsing `memory-profiler` introduces overhead and consumes additional memory itself. It is not recommended for production environments due to its intrusive nature.
fix
Use `memory-profiler` exclusively for development and debugging. For production memory monitoring, consider less intrusive system-level tools or Python's built-in `tracemalloc` for lower overhead.
affects: All versions
gotchaBy default, `memory-profiler` only tracks the memory usage of the parent process. Memory consumed by forked child processes (e.g., when using `multiprocessing`) is not automatically included in the report.
fix
Use the `mprof run --include-children` or `--multiprocess` flags to track child processes. When using the `memory_usage` API directly, the return value will include child memory in a nested list that needs to be manually processed.
affects: All versions
gotchaApplying the `@profile` decorator can sometimes subtly change the behavior of the decorated function, particularly when interacting with complex data structures or libraries like Pandas, potentially leading to unexpected errors or different outputs than when run un-profiled.
fix
If encountering unusual behavior when profiling, test the function without the `@profile` decorator. If the issue resolves, consider using the `memory_usage` function for profiling specific code blocks, or explore non-intrusive profilers like `fil-profiler`.
affects: All versions
Upgrade
Version history
0.61.0latest on PyPI · released Nov 15, 2022
Audit
Dependencies
psutilrequiredRequired for process memory monitoring capabilities.
Agent activity
26 hits · last 30 days
node
18
OpenAI (training)
2
Resources
memory-profiler — pip install memory-profiler · libregistry