Python objgraph.show_most_common_types() Examples

The following are 9 code examples of objgraph.show_most_common_types(). 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: misc.py    From DueUtil with GNU General Public License v3.0 6 votes vote down vote up
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()) 
Example #2
Source File: memusage.py    From autopush with Mozilla Public License 2.0 5 votes vote down vote up
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() 
Example #3
Source File: profiling.py    From CloudBot with GNU General Public License v3.0 5 votes vote down vote up
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" 
Example #4
Source File: bot.py    From rhinobot_heroku with MIT License 5 votes vote down vote up
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') 
Example #5
Source File: profiling.py    From CloudBot with GNU General Public License v3.0 5 votes vote down vote up
def show_types():
    if objgraph is None:
        return "objgraph not installed"
    objgraph.show_most_common_types(limit=20)
    return "Printed to console" 
Example #6
Source File: test_mem_1.py    From pyaf with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #7
Source File: bot.py    From MusicBot with MIT License 5 votes vote down vote up
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') 
Example #8
Source File: memory.py    From cocrawler with Apache License 2.0 5 votes vote down vote up
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) 
Example #9
Source File: runserver.py    From oio-swift with Apache License 2.0 5 votes vote down vote up
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()))