pympler.tracker

The tracker module allows you to track changes in the memory usage over time.

Using the SummaryTracker, you can create summaries and compare them with each other. Stored summaries can be ignored during comparison, avoiding the observer effect.

The ObjectTracker allows to monitor object creation. You create objects from one time and compare with objects from an earlier time.

Classes

class pympler.tracker.SummaryTracker(ignore_self=True)

Helper class to track changes between two summaries taken.

Detailed information on single objects will be lost, e.g. object size or object id. But often summaries are sufficient to monitor the memory usage over the lifetime of an application.

On initialisation, a first summary is taken. Every time diff is called, a new summary will be created. Thus, a diff between the new and the last summary can be extracted.

Be aware that filtering out previous summaries is time-intensive. You should therefore restrict yourself to the number of summaries you really need.

diff(summary1=None, summary2=None)

Compute diff between to summaries.

If no summary is provided, the diff from the last to the current summary is used. If summary1 is provided the diff from summary1 to the current summary is used. If summary1 and summary2 are provided, the diff between these two is used.

print_diff(summary1=None, summary2=None)

Compute diff between to summaries and print it.

If no summary is provided, the diff from the last to the current summary is used. If summary1 is provided the diff from summary1 to the current summary is used. If summary1 and summary2 are provided, the diff between these two is used.

store_summary(key)

Store a current summary in self.summaries.

class pympler.tracker.ObjectTracker

Helper class to track changes in the set of existing objects.

Each time you invoke a diff with this tracker, the objects which existed during the last invocation are compared with the objects which exist during the current invocation.

Please note that in order to do so, strong references to all objects will be stored. This means that none of these objects can be garbage collected. A use case for the ObjectTracker is the monitoring of a state which should be stable, but you see new objects being created nevertheless. With the ObjectTracker you can identify these new objects.

get_diff(ignore=())

Get the diff to the last time the state of objects was measured.

keyword arguments ignore – list of objects to ignore

print_diff(ignore=())

Print the diff to the last time the state of objects was measured.

keyword arguments ignore – list of objects to ignore