Python objgraph.by_type() Examples
The following are 8
code examples of objgraph.by_type().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
objgraph
, or try the search function
.
Example #1
Source File: memory.py From cocrawler with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: conftest.py From glue-vispy-viewers with BSD 2-Clause "Simplified" License | 6 votes |
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")
Example #3
Source File: test_memory.py From grpclib with BSD 3-Clause "New" or "Revised" License | 5 votes |
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')
Example #4
Source File: tools.py From rssant with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get(name): objs = objgraph.by_type(name) if objs: return objs[0] return None
Example #5
Source File: job.py From mrq with MIT License | 5 votes |
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 )
Example #6
Source File: test_table.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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."
Example #7
Source File: conftest.py From glue-vispy-viewers with BSD 2-Clause "Simplified" License | 5 votes |
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)
Example #8
Source File: runserver.py From oio-swift with Apache License 2.0 | 5 votes |
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()))