本文整理匯總了Python中objgraph.by_type方法的典型用法代碼示例。如果您正苦於以下問題:Python objgraph.by_type方法的具體用法?Python objgraph.by_type怎麽用?Python objgraph.by_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類objgraph
的用法示例。
在下文中一共展示了objgraph.by_type方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: print_objects
# 需要導入模塊: import objgraph [as 別名]
# 或者: from objgraph import by_type [as 別名]
def print_objects(f):
gc.collect()
with open(f, 'r') as fd:
for line in fd:
line = line.strip()
try:
obj = random.choice(objgraph.by_type(line))
except Exception as e:
LOGGER.info('exception trying to objgraph a random %s: %s', line, str(e))
break
with tempfile.NamedTemporaryFile(dir='/tmp', prefix=line, suffix='.dot', mode='w') as out:
try:
objgraph.show_chain(objgraph.find_backref_chain(obj, objgraph.is_proper_module), output=out)
LOGGER.info('object %s file %s', line, out.name)
except Exception as e:
LOGGER.info('exception trying to show_chain a random %s: %s', line, str(e))
try:
os.remove(f)
except Exception as e:
LOGGER.info('exception %s removing memory_crawler file %s', str(e), f)
示例2: pytest_runtest_teardown
# 需要導入模塊: import objgraph [as 別名]
# 或者: from objgraph import by_type [as 別名]
def pytest_runtest_teardown(item, nextitem):
# The following is a check to make sure that once the viewer and
# application have been closed, there are no leftover references to data
# viewers or application. This was introduced because there were
# previously circular references that meant that viewer instances were
# not properly garbage collected, which in turn meant they still reacted
# in some cases to events.
if OBJGRAPH_INSTALLED and hasattr(item, '_viewer_count'):
app.processEvents()
for viewer_cls in VIEWER_CLASSES:
obj = objgraph.by_type(viewer_cls)
if len(obj) > item._viewer_count:
objgraph.show_backrefs(objgraph.by_type(viewer_cls))
raise ValueError("No net viewers should be created in tests")
示例3: _check
# 需要導入模塊: import objgraph [as 別名]
# 或者: from objgraph import by_type [as 別名]
def _check(type_name):
"""Utility function to debug references"""
import objgraph
objects = objgraph.by_type(type_name)
if objects:
obj = objects[0]
objgraph.show_backrefs(obj, max_depth=3, filename='graph.png')
示例4: get
# 需要導入模塊: import objgraph [as 別名]
# 或者: from objgraph import by_type [as 別名]
def get(name):
objs = objgraph.by_type(name)
if objs:
return objs[0]
return None
示例5: trace_memory_stop
# 需要導入模塊: import objgraph [as 別名]
# 或者: from objgraph import by_type [as 別名]
def trace_memory_stop(self):
""" Stops measuring memory consumption """
self.trace_memory_clean_caches()
objgraph.show_growth(limit=30)
trace_type = context.get_current_config()["trace_memory_type"]
if trace_type:
filename = '%s/%s-%s.png' % (
context.get_current_config()["trace_memory_output_dir"],
trace_type,
self.id)
chain = objgraph.find_backref_chain(
random.choice(
objgraph.by_type(trace_type)
),
objgraph.is_proper_module
)
objgraph.show_chain(chain, filename=filename)
del filename
del chain
gc.collect()
self._memory_stop = self.worker.get_memory()["total"]
diff = self._memory_stop - self._memory_start
context.log.debug("Memory diff for job %s : %s" % (self.id, diff))
# We need to update it later than the results, we need them off memory
# already.
self.collection.update(
{"_id": self.id},
{"$set": {
"memory_diff": diff
}},
w=1
)
示例6: _refcounting
# 需要導入模塊: import objgraph [as 別名]
# 或者: from objgraph import by_type [as 別名]
def _refcounting(type_):
"""
Perform the body of a with statement with reference counting for the
given type (given by class name)--raises an assertion error if there
are more unfreed objects of the given type than when we entered the
with statement.
"""
gc.collect()
refcount = len(objgraph.by_type(type_))
yield refcount
gc.collect()
assert len(objgraph.by_type(type_)) <= refcount, \
"More {0!r} objects still in memory than before."
示例7: pytest_runtest_setup
# 需要導入模塊: import objgraph [as 別名]
# 或者: from objgraph import by_type [as 別名]
def pytest_runtest_setup(item):
if OBJGRAPH_INSTALLED:
app.processEvents()
for viewer_cls in VIEWER_CLASSES:
obj = objgraph.by_type(viewer_cls)
item._viewer_count = len(obj)
示例8: run_objgraph
# 需要導入模塊: import objgraph [as 別名]
# 或者: from objgraph import by_type [as 別名]
def run_objgraph(types):
import objgraph
import os
import random
objgraph.show_most_common_types(limit=50, shortnames=False)
for type_ in types:
count = objgraph.count(type_)
print('%s objects: %d' % (type_, count))
if count:
objgraph.show_backrefs(
random.choice(objgraph.by_type(type_)), max_depth=20,
filename='/tmp/backrefs_%s_%d.dot' % (type_, os.getpid()))