本文整理汇总了Python中objgraph.show_most_common_types方法的典型用法代码示例。如果您正苦于以下问题:Python objgraph.show_most_common_types方法的具体用法?Python objgraph.show_most_common_types怎么用?Python objgraph.show_most_common_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类objgraph
的用法示例。
在下文中一共展示了objgraph.show_most_common_types方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: memusage
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_most_common_types [as 别名]
def memusage(do_dump_rpy_heap=True, do_objgraph=True):
# type: (Optional[bool], Optional[bool]) -> str
"""Returning a str of memory usage stats"""
def trap_err(func, *args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e: # pragma: nocover
# include both __str/repr__, sometimes one's useless
buf.writelines([func.__name__, ': ', repr(e), ': ', str(e)])
buf = StringIO()
rusage = trap_err(resource.getrusage, resource.RUSAGE_SELF)
buf.writelines([repr(rusage), '\n\n'])
trap_err(pmap_extended, buf)
trap_err(jemalloc_stats, buf)
trap_err(glibc_malloc_info, buf)
if hasattr(gc, 'get_stats'):
buf.writelines(['\n\n', gc.get_stats(), '\n\n'])
if do_dump_rpy_heap:
# dump rpython's heap before objgraph potentially pollutes the
# heap with its heavy workload
trap_err(dump_rpy_heap, buf)
trap_err(get_stats_asmmemmgr, buf)
buf.write('\n\n')
if do_objgraph:
trap_err(objgraph.show_most_common_types, limit=0, file=buf)
return buf.getvalue()
示例2: show_types
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_most_common_types [as 别名]
def show_types():
"""- Print object type data to the console"""
if objgraph is None:
return "objgraph not installed"
objgraph.show_most_common_types(limit=20)
return "Printed to console"
示例3: meminfo
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_most_common_types [as 别名]
def meminfo(ctx, **_):
mem_info = StringIO()
objgraph.show_most_common_types(file=mem_info)
await util.say(ctx.channel, "```%s```" % mem_info.getvalue())
mem_info = StringIO()
objgraph.show_growth(file=mem_info)
await util.say(ctx.channel, "```%s```" % mem_info.getvalue())
示例4: cmd_objgraph
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_most_common_types [as 别名]
def cmd_objgraph(self, channel, func='most_common_types()'):
import objgraph
await self.send_typing(channel)
if func == 'growth':
f = StringIO()
objgraph.show_growth(limit=10, file=f)
f.seek(0)
data = f.read()
f.close()
elif func == 'leaks':
f = StringIO()
objgraph.show_most_common_types(objects=objgraph.get_leaking_objects(), file=f)
f.seek(0)
data = f.read()
f.close()
elif func == 'leakstats':
data = objgraph.typestats(objects=objgraph.get_leaking_objects())
else:
data = eval('objgraph.' + func)
return Response(data, codeblock='py')
示例5: show_types
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_most_common_types [as 别名]
def show_types():
if objgraph is None:
return "objgraph not installed"
objgraph.show_most_common_types(limit=20)
return "Printed to console"
示例6: display_used_mem
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_most_common_types [as 别名]
def display_used_mem():
print("DISPLAY_USED_MEM_START");
import gc
gc.collect()
import objgraph
objgraph.show_most_common_types(limit=20)
print("DISPLAY_USED_MEM_END");
# import '.' as pyaf_new_name
# pyaf=pyaf_new_name
# from pyaf
示例7: print_summary
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_most_common_types [as 别名]
def print_summary(f):
'''
Log a summary of current memory usage. This is very expensive
when there is a lot of memory used.
'''
if os.path.isfile(f):
print_objects(f)
if not config.read('Crawl', 'DebugMemory'):
return
mem = {}
for d in debugs:
mem.update(d())
LOGGER.info('Memory summary:')
for k in sorted(mem.keys()):
v = mem[k]
LOGGER.info(' %s len %d bytes %s', k, v['len'], _in_millions(v['bytes']))
LOGGER.info('Top objects:')
gc.collect()
lines = io.StringIO()
objgraph.show_most_common_types(limit=20, file=lines)
lines.seek(0)
for l in lines.read().splitlines():
LOGGER.info(' %s', l)
示例8: run_objgraph
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_most_common_types [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()))