memory usage of a specific function

Stephen Kellett snail at objmedia.demon.co.uk
Thu Jan 5 06:54:46 EST 2006


In message <1136404488.446011.291980 at g44g2000cwa.googlegroups.com>,
Sverker Nilsson <sverker.is at home.se> writes
>> Python Memory Validator.
>>
>> Run your program to completion.
>> Switch to the hotspots tab.
>> Search for your function.
>> All memory used in that function will be shown in the tree (with the
>> effective callstack) underneath that function node in the tree.
>
>>
>> http://www.softwareverify.com
>
>I can't try it out easily since it doesn't seem to support Linux.

Correct. Windows NT and above only at this time.

>Also
>looking at the home page I couldn't find any description of what it
>was actually doing. The info links didn't work, they showed blank
>pages with my browser (Netscape 3.01.)

IE 6, Opera and Firefox. No idea with NS 3.0

Maybe this more direct link helps.

http://www.softwareverify.com/pythonMemoryValidator/index.html

>So if you would like to explain here, it would be helpful.
>Especially, it isn't clear to me what this means (requoting):
>
>> All memory used in that function

Exactly that. In a GC language (Python, Ruby, Java, Javascript) each
object needs to memory to exist. PMV tracks the creation/destruction of
objects (and in the case of Python, the other special non-object
datatypes such as integers that have their own pool).

Consider the following psuedo code

Func 1
        allocates A
        calls Func 2
        calls Func 3
        calls Func 4

Func 2
        allocates B
        allocates C

Func 3
        allocates B
        calls Func 5
        allocates C

Func 4
        allocates D
        allocates E

Func 5
        loop 5 times
                allocates F
                allocates G

This gives you the following tree showing all memory allocations

Func1
        A
        Func 2
                B
                C
        Func 3
                B
                Func 5
                        5 x F
                        5 x G
                C
        Func 4
                D
                E

The tree also includes stats so that you know which node has more (in %
terms) data in it (in bytes) that another node. From that tree we can
see that the following objects are created.
        A       1
        B       2
        C       2
        D       1
        E       1
        F       5
        G       5

>memory usage could be tested using heapy and the following function.

You cannot reliably use native GC language code to monitor the same
application's memory usage. You need to do this externally (from C or
what takes your fancy - something that won't create/destroy objects on
the native language).

>On the other hand, test for memory usage according to alternative (1)
>would be harder to add, and it is somewhat undefined what it
>means. And it is perhaps not so useful as the 2nd alternative?

PMV provides both. If you want stats on the number of objects created,
no problem. If you want callstacks for all objects created and stats for
the memory allocated at these locations, no problem. If you want stats
for each generation of objects (a generation being the group allocated
between GC invocations), no problem. Plus a whole load of analysis and
query functions to allow you to find information on particular object
types etc, plus data export functions (HTML and XML).

Stephen
-- 
Stephen Kellett
Object Media Limited    http://www.objmedia.demon.co.uk/software.html
Computer Consultancy, Software Development
Windows C++, Java, Assembler, Performance Analysis, Troubleshooting



More information about the Python-list mailing list