-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem_parser.py
46 lines (28 loc) · 1.16 KB
/
mem_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import msparser
import os
import argparse
import csv
def calculate_total_memory(path_to_file):
data = msparser.parse_file(path_to_file)
heap = 0
stack = 0
for snapshot in data['snapshots']:
heap += snapshot['mem_heap']
heap += snapshot['mem_heap_extra']
stack += snapshot['mem_stack']
return heap, stack
def main(directory,file):
with open(directory + "/data_mem_" + file + ".csv","w") as file:
writer = csv.writer(file)
writer.writerow(['heap','stack'])
for root,dirs,files in os.walk(directory):
for file in files:
if file.startswith("mem_"):
heap, stack = calculate_total_memory(root + "/" +file)
writer.writerow([heap,stack])
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Parses total memory consumption from massif files")
parser.add_argument('path', type=str, help='The path of the files to parse')
parser.add_argument('file', type=str, help='File naming convention')
args = parser.parse_args()
main(args.path,args.file)