Skip to content
Snippets Groups Projects
Commit 4c995e5e authored by Pawel Dziepak's avatar Pawel Dziepak Committed by Pekka Enberg
Browse files

trace: integrate memory-analyzer with trace.py

parent 43a41db6
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
from collections import Counter
from osv import tree
import re
print("-=[ Mem0ry Allocations Analyz3r ]=-")
def is_malloc(x):
return x.find("malloc ") > 0
......@@ -53,7 +50,8 @@ class Buffer(object):
self.is_freed = True
def process_records(mallocs, trace_records):
for l in trace_records:
for t in trace_records:
l = str(t)
try:
#
# Maintain a hash dictionary that maps between buffer address and
......@@ -192,10 +190,3 @@ def show_results(mallocs):
return key.key.__str__()
tree.print_tree(root, formatter)
if __name__ == "__main__":
mallocs = {}
trace_records = open("trace.txt", "rt").readlines()
process_records(mallocs, trace_records)
show_results(mallocs)
......@@ -11,6 +11,7 @@ from collections import defaultdict
from operator import attrgetter
from osv import trace, debug, prof
import memory_analyzer
class InvalidArgumentsException(Exception):
def __init__(self, message):
......@@ -108,6 +109,12 @@ def list_trace(args):
if t.time in time_range:
print t.format(backtrace_formatter, data_formatter=data_formatter)
def mem_analys(args):
mallocs = {}
with get_trace_reader(args) as reader:
memory_analyzer.process_records(mallocs, reader.get_traces())
memory_analyzer.show_results(mallocs)
def add_time_slicing_options(parser):
group = parser.add_argument_group('time slicing')
group.add_argument("--since", action='store', help="show data starting on this timestamp [ns]")
......@@ -547,6 +554,14 @@ if __name__ == "__main__":
add_trace_source_options(cmd_tcpdump)
cmd_tcpdump.set_defaults(func=tcpdump, paginate=True)
cmd_memory_analyzer = subparsers.add_parser("memory-analyzer",
help="show memory allocation analysis", description="""
Prints profile showing number of memory allocations, their size, alignment and allocator.
Requires memory_* tracepoints enabled.
""")
add_trace_source_options(cmd_memory_analyzer)
cmd_memory_analyzer.set_defaults(func=mem_analys, paginate=True)
args = parser.parse_args()
if getattr(args, 'paginate', False):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment