Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- import sys, os
- import collections
- def parse_meminfo(filename):
- def parse(filename):
- lines = []
- for line in open(filename):
- line = line[:-1]
- if line.startswith('** MEMINFO in pid '):
- if len(lines) > 3:
- yield get_binder_info(lines)
- lines = []
- lines.append(line)
- yield get_binder_info(lines)
- d = {}
- for pid, name, binder_info in parse(filename):
- d[name] = binder_info
- return d
- def get_binder_info(item):
- l = item[0].split()
- pid = l[4]
- pname = l[5][1:-1]
- proxies = []
- lines = []
- for line in item[2:]:
- if not line.strip():
- proxies.append('\n'.join(lines))
- lines = []
- continue
- if line.startswith(' Shared'):
- break
- lines.append(line)
- return pid, pname, collections.Counter(proxies)
- if __name__ == '__main__':
- def parse_args(argv):
- tags = []
- filenames = []
- for filename in argv:
- if os.access(filename, os.R_OK):
- filenames.append(filename)
- else:
- tags.append(filename)
- return tags, filenames
- tags, filenames = parse_args(sys.argv[1:])
- if not filenames:
- print 'Usage: %s dumpsys_meminfo_a_output1 dumpsys_meminfo_a_output2 ...'%sys.argv[0]
- sys.exit(-1)
- parsed = map(parse_meminfo, filenames)
- now = parsed[-1]
- if not tags:
- tags = now.keys() # ['system', ]
- for tag in tags:
- printed = False
- for k, v in now[tag].most_common(10):
- if v < 4: continue
- if not printed:
- print 'process: ', tag
- printed = True
- print 'count history:', map(lambda x: x.get(tag, {}).get(k, 0), parsed)
- print 'item: ', k
- print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement