1

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:

  1. 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.

  2. 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.

2
  • possible duplicate of Python memory profiler Commented Feb 3, 2012 at 19:14
  • thx.. question updated to address this Commented Jun 22, 2012 at 23:45

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Wow this far better than I expected. By any chance, do you know if this or a similar tool can monitor the clock speed of a discrete graphics card in my laptop? I am trying to diagnose some lag...
I think there are several tools like RivaTuner for nVidia cards but they are specific to the card you're using. What card do you have?
nVidia, so I'm going to try it. Thanks.
1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.