示例#1
0
 def invoke(self, args, from_tty):
     ms = glibc_arenas.get_ms()
     chunks_by_size = {}
     num_chunks = 0
     total_size = 0
     try:
         for chunk in ms.iter_chunks():
             if not chunk.is_inuse():
                 continue
             size = int(chunk.chunksize())
             num_chunks += 1
             total_size += size
             if size in chunks_by_size:
                 chunks_by_size[size] += 1
             else:
                 chunks_by_size[size] = 1
     except KeyboardInterrupt:
         pass # FIXME
     t = Table(['Chunk size', 'Num chunks', 'Allocated size'])
     for size in sorted(chunks_by_size.keys(),
                        lambda s1, s2: chunks_by_size[s2] * s2 - chunks_by_size[s1] * s1):
         t.add_row([fmt_size(size),
                    chunks_by_size[size],
                    fmt_size(chunks_by_size[size] * size)])
     t.add_row(['TOTALS', num_chunks, fmt_size(total_size)])
     t.write(sys.stdout)
     print()
示例#2
0
 def invoke(self, args, from_tty):
     ms = glibc_arenas.get_ms()
     chunks_by_size = {}
     num_chunks = 0
     total_size = 0
     try:
         for chunk in ms.iter_chunks():
             if not chunk.is_inuse():
                 continue
             size = int(chunk.chunksize())
             num_chunks += 1
             total_size += size
             if size in chunks_by_size:
                 chunks_by_size[size] += 1
             else:
                 chunks_by_size[size] = 1
     except KeyboardInterrupt:
         pass # FIXME
     t = Table(['Chunk size', 'Num chunks', 'Allocated size'])
     for size in sorted(chunks_by_size.keys(),
                        lambda s1, s2: chunks_by_size[s2] * s2 - chunks_by_size[s1] * s1):
         t.add_row([fmt_size(size),
                    chunks_by_size[size],
                    fmt_size(chunks_by_size[size] * size)])
     t.add_row(['TOTALS', num_chunks, fmt_size(total_size)])
     t.write(sys.stdout)
     print()
示例#3
0
 def invoke(self, args, from_tty):
     t = Table(columnheadings=('struct arena_object*', '256KB buffer location', 'Free pools'))
     for arena in ArenaObject.iter_arenas():
         t.add_row([fmt_addr(arena.as_address()),
                    fmt_addr(arena.address),
                    '%i / %i ' % (arena.field('nfreepools'),
                                  arena.field('ntotalpools'))
                    ])
     print 'Objects/obmalloc.c: %i arenas' % len(t.rows)
     t.write(sys.stdout)
     print
示例#4
0
 def invoke(self, args, from_tty):
     t = Table(columnheadings=('struct arena_object*', '256KB buffer location', 'Free pools'))
     for arena in ArenaObject.iter_arenas():
         t.add_row([fmt_addr(arena.as_address()),
                    fmt_addr(arena.address),
                    '%i / %i ' % (arena.field('nfreepools'),
                                  arena.field('ntotalpools'))
                    ])
     print('Objects/obmalloc.c: %i arenas' % len(t.rows))
     t.write(sys.stdout)
     print()
示例#5
0
文件: query.py 项目: fwugist/gdb-heap
def do_query(args):
    from heap import fmt_addr, Table
    from heap.parser import parse_query

    if args == '':
        # if no query supplied, select everything:
        filter_ = Constant(True)
    else:
        filter_ = parse_query(args)

    if False:
        print args
        print filter_

    columns = [
        Column('Start', lambda u: u.start, fmt_addr),
        Column('End', lambda u: u.start + u.size - 1, fmt_addr),
        Column('Domain', lambda u: u.category.domain, None),
        Column('Kind', lambda u: u.category.kind, None),
        Column('Detail', lambda u: u.category.detail, None),
        Column('Hexdump', lambda u: u.hexdump, None),
    ]

    t = Table([col.name for col in columns])

    for u in Query(filter_):
        u.ensure_hexdump()
        u.ensure_category()

        if u.category:
            domain = u.category.domain
            kind = u.category.kind
            detail = u.category.detail
            if not detail:
                detail = ''
        else:
            domain = ''
            kind = ''
            detail = ''

        t.add_row([
            fmt_addr(u.start),
            fmt_addr(u.start + u.size - 1), domain, kind, detail, u.hd
        ])

    t.write(sys.stdout)
    print
示例#6
0
    def invoke(self, args, from_tty):
        total_by_category = {}
        count_by_category = {}
        total_size = 0
        total_count = 0
        try:
            usage_list = list(lazily_get_usage_list())
            for u in usage_list:
                u.ensure_category()
                total_size += u.size
                if u.category in total_by_category:
                    total_by_category[u.category] += u.size
                else:
                    total_by_category[u.category] = u.size

                total_count += 1
                if u.category in count_by_category:
                    count_by_category[u.category] += 1
                else:
                    count_by_category[u.category] = 1

        except KeyboardInterrupt:
            pass  # FIXME

        t = Table(['Domain', 'Kind', 'Detail', 'Count', 'Allocated size'])
        for category in sorted(total_by_category.keys(),
                               key=total_by_category.get,
                               reverse=True):
            detail = category.detail
            if not detail:
                detail = ''
            t.add_row([
                category.domain,
                category.kind,
                detail,
                fmt_size(count_by_category[category]),
                fmt_size(total_by_category[category]),
            ])
        t.add_row(
            ['', '', 'TOTAL',
             fmt_size(total_count),
             fmt_size(total_size)])
        t.write(sys.stdout)
        print()
示例#7
0
    def invoke(self, args, from_tty):
        total_by_category = {}
        count_by_category = {}
        total_size = 0
        total_count = 0
        try:
            usage_list = list(lazily_get_usage_list())
            for u in usage_list:
                u.ensure_category()
                total_size += u.size
                if u.category in total_by_category:
                    total_by_category[u.category] += u.size
                else:
                    total_by_category[u.category] = u.size

                total_count += 1
                if u.category in count_by_category:
                    count_by_category[u.category] += 1
                else:
                    count_by_category[u.category] = 1

        except KeyboardInterrupt:
            pass # FIXME

        t = Table(['Domain', 'Kind', 'Detail', 'Count', 'Allocated size'])
        for category in sorted(total_by_category.keys(),
                               lambda s1, s2: cmp(total_by_category[s2],
                                                  total_by_category[s1])
                               ):
            detail = category.detail
            if not detail:
                detail = ''
            t.add_row([category.domain,
                       category.kind,
                       detail,
                       fmt_size(count_by_category[category]),
                       fmt_size(total_by_category[category]),
                       ])
        t.add_row(['', '', 'TOTAL', fmt_size(total_count), fmt_size(total_size)])
        t.write(sys.stdout)
        print
示例#8
0
def do_query(args):
    from heap import fmt_addr, Table
    from heap.parser import parse_query

    if args == '':
        # if no query supplied, select everything:
        filter_ = Constant(True)
    else:
        filter_ = parse_query(args)

    if False:
        print(args)
        print(filter_)

    columns = [Column('Start',
                      lambda u: u.start,
                      fmt_addr),
               Column('End',
                      lambda u: u.start + u.size - 1,
                      fmt_addr
                      ),
               Column('Domain',
                      lambda u: u.category.domain,
                      None),
               Column('Kind',
                      lambda u: u.category.kind,
                      None),
               Column('Detail',
                      lambda u: u.category.detail,
                      None),
               Column('Hexdump',
                      lambda u: u.hexdump,
                      None),
               ]

    t = Table([col.name for col in columns])

    for u in Query(filter_):
        u.ensure_hexdump()
        u.ensure_category()

        if u.category:
            domain = u.category.domain
            kind = u.category.kind
            detail = u.category.detail
            if not detail:
                detail = ''
        else:
            domain = ''
            kind = ''
            detail = ''

        t.add_row([fmt_addr(u.start),
                   fmt_addr(u.start + u.size - 1),
                   domain,
                   kind,
                   detail,
                   u.hd])

    t.write(sys.stdout)
    print()