1 #! /usr/bin/python 2 """Parses the total amount of sampled memory from log files. 3 4 This file outputs the total amount of memory that has been sampled by tcmalloc. 5 The output is of the format: 6 7 time in seconds from a base time, amount of memory that has been sampled 8 9 """ 10 11 import argparse 12 from cros_utils import compute_total_diff 13 from datetime import datetime 14 15 parser = argparse.ArgumentParser() 16 parser.add_argument('filename') 17 args = parser.parse_args() 18 19 my_file = open(args.filename) 20 output_file = open('memory_data.csv', 'a') 21 22 base_time = datetime(2014, 6, 11, 0, 0) 23 prev_line = '' 24 half_entry = (None, None) 25 26 for line in my_file: 27 if 'heap profile: ' not in line: 28 continue 29 memory_used = line.strip().split(':')[-1].strip().split(']')[0].strip() 30 total_diff = compute_total_diff(line, base_time) 31 output_file.write('{0},{1}\n'.format(int(total_diff), memory_used)) 32