Here are the examples of the python api sys.getobjects taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
3
View Complete Implementation : commontest.py
Copyright GNU General Public License v2.0
Author : rdiff-backup
Copyright GNU General Public License v2.0
Author : rdiff-backup
def getrefs(i, depth):
"""Get the i'th object in memory, return objects that reference it"""
import sys
import gc
import types
o = sys.getobjects(i)[-1]
for d in range(depth):
for ref in gc.get_referrers(o):
if type(ref) in (list, dict, types.InstanceType):
if type(ref) is dict and 'copyright' in ref:
continue
o = ref
break
else:
print("Max depth ", d)
return o
return o
0
View Complete Implementation : track_refs.py
Copyright GNU General Public License v3.0
Author : CalthorpeAnalytics
Copyright GNU General Public License v3.0
Author : CalthorpeAnalytics
def update(self):
obs = sys.getobjects(0)
type2count = {}
type2all = {}
for o in obs:
all = sys.getrefcount(o)
if type(o) is str and o == '<dummy key>':
# avoid dictionary madness
continue
t = type(o)
if t in type2count:
type2count[t] += 1
type2all[t] += all
else:
type2count[t] = 1
type2all[t] = all
ct = [(type2count[t] - self.type2count.get(t, 0),
type2all[t] - self.type2all.get(t, 0),
t)
for t in type2count.iterkeys()]
ct.sort()
ct.reverse()
printed = False
logger.info("----------------------")
logger.info("Memory profiling")
i = 0
for delta1, delta2, t in ct:
if delta1 or delta2:
if not printed:
logger.info("%-55s %8s %8s" % ('', 'insts', 'refs'))
printed = True
logger.info("%-55s %8d %8d" % (t, delta1, delta2))
i += 1
if i >= self.limit:
break
self.type2count = type2count
self.type2all = type2all