0

I need help using Pympler and getting the memory usage of an object. I am using it like this:

from pympler import classtracker

myObj = SomeClass()
tr = classtracker.ClassTracker()
tr.track_object(myObj)

# Do stuff with object here

# Print stats
tr.create_snapshot()
tr.stats.print_summary()

This works fine and I get these results:

---- SUMMARY ------------------------------------------------------------------
                                         active      0     B      average   pct
  SomeClass                                   1    136.45 KB    136.45 KB    0%
-------------------------------------------------------------------------------

My question is how do I get the average number and put it in a variable? I can't find anything in the documentation. I'm running some tests and want to get the average over the lifetime of the tests. If you know of a way to do that or if there is any other package I can use to accomplish what I want, please let me know. Thank you.

1 Answer 1

1

You can do it with the asizeof function, you don't even need to use classtracker (unless you are using some of the more complex functionality)

from pympler.asizeof import asizeof

class SomeClass:
    def __init__(self):
        self.list = []
    def append(self, i):
        self.list.append(i)

myObj = SomeClass()

myObj.append("Hello")
myObj.append("World")

print 'Sizeof myObj is {}'.format(asizeof(myObj))
Sign up to request clarification or add additional context in comments.

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.