total_mem_sampled.py revision a8af9a7a2462b00e72deff99327bdb452a715277
1#! /usr/bin/python
2"""Parses the total amount of sampled memory from log files.
3
4This file outputs the total amount of memory that has been sampled by tcmalloc.
5The output is of the format:
6
7time in seconds from a base time, amount of memory that has been sampled
8
9"""
10
11import argparse
12from cros_utils import compute_total_diff
13from datetime import datetime
14
15parser = argparse.ArgumentParser()
16parser.add_argument('filename')
17args = parser.parse_args()
18
19my_file = open(args.filename)
20output_file = open('memory_data.csv', 'a')
21
22base_time = datetime(2014, 6, 11, 0, 0)
23prev_line = ''
24half_entry = (None, None)
25
26for 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