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.

Community
  • 1
  • 1
max
  • 49,282
  • 56
  • 208
  • 355

3 Answers3

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.

Youcha
  • 1,534
  • 2
  • 16
  • 30
  • 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... – max Jun 24 '12 at 05:42
  • 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? – Youcha Jun 24 '12 at 18:34
  • nVidia, so I'm going to try it. Thanks. – max Jun 25 '12 at 15:27
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.

max
  • 49,282
  • 56
  • 208
  • 355
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.

Community
  • 1
  • 1
Di Zou
  • 4,469
  • 13
  • 59
  • 88