Example #1
0
def mem_test(when):
    from core.controllers.profiling.ps_mem import get_memory_usage, human
    sorted_cmds, shareds, _, _ = get_memory_usage(None, True, True, True )
    cmd = sorted_cmds[0]
    msg = "%8sB Private + %8sB Shared = %8sB" % ( human(cmd[1]-shareds[cmd[0]]),
                                                  human(shareds[cmd[0]]), human(cmd[1])
                                                )
    print 'Total memory usage %s: %s' % (when,msg)
Example #2
0
def mem_test(when):
    from core.controllers.profiling.ps_mem import get_memory_usage, human
    sorted_cmds, shareds, _, _ = get_memory_usage(None, True, True, True)
    cmd = sorted_cmds[0]
    msg = "%8sB Private + %8sB Shared = %8sB" % (human(cmd[1] - shareds[cmd[0]]),
                                                 human(shareds[cmd[
                                                               0]]), human(cmd[1])
                                                 )
    print 'Total memory usage %s: %s' % (when, msg)
Example #3
0
def dump_memory_usage():
    '''
    This is a function that prints the memory usage of w3af in real time.
    :author: Andres Riancho ([email protected])
    '''
    if not DEBUG_MEMORY:
        return
    else:
        if DEBUG_REFERENCES:
            print 'Object References:'
            print '=================='
            interesting = ['tuple', 'dict', 'list']
            for interesting_klass in interesting:
                interesting_instances = objgraph.by_type(interesting_klass)

                sample = random.sample(interesting_instances, min(
                    SAMPLE_LEN, len(interesting_instances)))

                for s in sample:
                    fmt = 'memory-refs/%s-backref-graph-%s.png'
                    fname = fmt % (interesting_klass, id(s))

                    ignores = [id(interesting_instances), id(s), id(sample)]
                    ignores.extend([id(v) for v in locals().values()])
                    ignores.extend([id(v) for v in globals().values()])
                    ignores.append(id(locals()))
                    ignores.append(id(globals()))
                    try:
                        objgraph.show_backrefs(s, highlight=inspect.isclass,
                                               extra_ignore=ignores, filename=fname,
                                               extra_info=_extra_info)
                    except:
                        pass

            print

        print 'Most common:'
        print '============'
        objgraph.show_most_common_types()

        print

        print 'Memory delta:'
        print '============='
        objgraph.show_growth(limit=25)

        sorted_cmds, shareds, _, _ = get_memory_usage(None, True, True, True)
        cmd = sorted_cmds[0]
        msg = "%8sB Private + %8sB Shared = %8sB" % (human(cmd[1] - shareds[cmd[0]]),
                                                     human(shareds[cmd[0]
                                                                   ]), human(cmd[1])
                                                     )
        print 'Total memory usage:', msg