Reputation: 52273
I would like to obtain, from within the Python program, the maximum physical memory used by a Python program (ActiveState Python 3.2, under Windows 7).
Ideally, every 0.1 sec or so, I'd like to have memory usage polled, and if it exceeds the maximum seen so far, the maximum value (a global variable stored somewhere), updated.
UPDATE:
I realize my question is a close duplicate of Which Python memory profiler is recommended?.
Sorry for being unclear. I have two specific problems that are not, to my knowledge, addressed by a regular memory profiler:
I need to see not only the memory allocated by Python, but the total memory used by the Python program (under Windows, this would include DLLs, etc.). In other words, under Windows, this is exactly what you'd see in the Task Manager.
I need to see the maximum memory rather than the memory at any given instant. I can't think of a way to do that other than to place numerous memory checks all around the code whenever I think I'm allocating something large.
Upvotes: 1
Views: 2615
Reputation: 1564
I think you could go under Control Panel, Admin Tools, Performances, click on the '+', select 'Processor' under 'Performance Object', Pool Paged Bytes or Pool Unpaged Bytes under the left column and you select your process under the right column. You can generate a log file with the Performance monitor.
Upvotes: 2
Reputation: 52273
I did not find any way to do precisely what I want with Python.
However, in playing with Windows 7 Task Manager, I found I can add a column "Peak Working Set (Memory)". So if I simply pause the python program before it can exit (and catch exceptions from main()
to pause for the same reason), I can see the peak memory in the task manager.
I know it's stupid (e.g., it doesn't allow me to print it to a log file, do something based on how memory I'm using, etc.), but it's better than nothing.
Upvotes: 1
Reputation: 4609
Here's a link to a similar question:
Which Python memory profiler is recommended?
I've used Guppy/Heapy and Meliae. They're a little different, but I've found both are quite useful.
Upvotes: 0