1#! /usr/bin/python 2"""Parses the actual memory usage from TCMalloc. 3 4This goes through logs that have the actual allocated memory (not sampled) in 5the logs. The output is of the form of: 6 7time (in seconds from some base time), amount of memory allocated by the 8application 9 10""" 11 12import argparse 13from cros_utils import compute_total_diff 14from datetime import datetime 15 16pretty_print = True 17 18parser = argparse.ArgumentParser() 19parser.add_argument('filename') 20args = parser.parse_args() 21 22my_file = open(args.filename) 23output_file = open('raw_memory_data.csv', 'a') 24 25base_time = datetime(2014, 6, 11, 0, 0) 26prev_line = '' 27half_entry = (None, None) 28 29for line in my_file: 30 if 'Output Heap Stats:' in line: 31 total_diff = compute_total_diff(line, base_time) 32 half_entry = (total_diff, None) 33 if 'Bytes in use by application' in line: 34 total_diff = half_entry[0] 35 memory_used = int(line.strip().split()[1]) 36 half_entry = (None, None) 37 output_file.write('{0},{1}\n'.format(total_diff, memory_used)) 38