https://github.com/vmware/chap (open source code) does what you are requesting here, as long as you can run your application on Linux.
Wait until you believe you are interested in what allocations the application has at that point in time.
Gather a live core (for example using gcore) for your process, but make sure the coredump filter is set first as in:
echo 0x37 >/proc/pid-of-your-python-program/coredump_filter
gcore pid-of-your-python-program
Open the resulting core in chap.
Do the following from the chap prompt:
redirect on
describe used
Edit the resulting file or post-process it using the tool of choice.
The resulting files will have entries for each allocation currently in use. For the ones that correspond to python objects they will generally show the python type, as in:
Anchored allocation at 7f5e7bf2a570 of size 40
This allocation matches pattern ContainerPythonObject.
This has a PyGC_Head at the start so the real PyObject is at offset 0x18.
This has reference count 1 and python type 0x7f5e824c08a0 (dict)
Anchored allocation at 7f5e7bf2a5b0 of size 40
This allocation matches pattern SimplePythonObject.
This has reference count 3 and python type 0x7f5e824cdfe0 (str)
This has a string of length 12 containing
"ETOOMANYREFS".
There are other commands you can use from chap to understand why any allocations of interest to you are anchored, basically because they allow you to traverse backwards by incoming references, but the above should suffice to allow you to figure out which kinds of allocations have high counts.
Suppose, for example, you wanted to understand how that dict in the allocation at 0x7f5e7bf2a570 was referenced. You could do this command:
chap> describe incoming 7f5e7bf2a570 /skipUnfavoredReferences true
Anchored allocation at 17fda90 of size 1a8
This allocation matches pattern PyDictKeysObject.
1 allocations use 0x1a8 (424) bytes.
You could in turn ask what are the references to that PyDictKeysObject (not a python type but used to store the keys for a dictionary)
chap> describe incoming 17fda90 /skipUnfavoredReferences true
Anchored allocation at 7f5e7c0e01f0 of size 40
This allocation matches pattern ContainerPythonObject.
The garbage collector considers this allocation to be reachable.
This has a PyGC_Head at the start so the real PyObject is at offset 0x18.
This has reference count 1 and python type 0x7f5e824c08a0 (dict)
1 allocations use 0x40 (64) bytes.