Skip to content

Instantly share code, notes, and snippets.

@blazetopher
Created January 7, 2013 18:58
Show Gist options
  • Save blazetopher/4477463 to your computer and use it in GitHub Desktop.
Save blazetopher/4477463 to your computer and use it in GitHub Desktop.
Utilities for working with objgraph
#!/usr/bin/env python
"""
@package
@file objgraph_utils
@author Christopher Mueller
@brief
"""
import objgraph
max_depth = 5
too_many = 100
def show_refs(obj=None, obj_id=None):
if obj is None and obj_id is not None:
obj = get_obj_by_id(obj_id)
objgraph.show_refs(obj, max_depth=max_depth, too_many=too_many, extra_info=lambda x: id(x), filter=lambda x: not isinstance(x, type), refcounts=True)
def show_backrefs(obj=None, obj_id=None):
if obj is None and obj_id is not None:
obj = get_obj_by_id(obj_id)
objgraph.show_backrefs(obj, max_depth=max_depth, too_many=too_many, extra_info=lambda x: id(x), filter=lambda x: not isinstance(x, type), refcounts=True)
def get_obj_by_id(obj_id):
return objgraph.at(obj_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment