1 #! /usr/bin/python 2 """Parses the actual memory usage from TCMalloc. 3 4 This goes through logs that have the actual allocated memory (not sampled) in 5 the logs. The output is of the form of: 6 7 time (in seconds from some base time), amount of memory allocated by the 8 application 9 10 """ 11 12 import argparse 13 from cros_utils import compute_total_diff 14 from datetime import datetime 15 16 pretty_print = True 17 18 parser = argparse.ArgumentParser() 19 parser.add_argument('filename') 20 args = parser.parse_args() 21 22 my_file = open(args.filename) 23 output_file = open('raw_memory_data.csv', 'a') 24 25 base_time = datetime(2014, 6, 11, 0, 0) 26 prev_line = '' 27 half_entry = (None, None) 28 29 for 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