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