-
Notifications
You must be signed in to change notification settings - Fork 0
/
results_parser.py
74 lines (53 loc) · 2.48 KB
/
results_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import json
import argparse
import os.path as path
def parse(filename):
with open(filename) as results_file:
results = results_file.read()
results = results.replace('let results = ', '')
results = results.replace(';', '')
results_json = json.loads(results)
stats = results_json['stats']
print("")
print("Processes per group")
print("-----------------------")
groups = []
for group in results_json['groups']:
processes_in_group = results_json['processes']
tmp = [x for x in processes_in_group if x['group'] == group['id']]
unique_child_procs = {}
for proc in tmp:
name = proc['content']
if unique_child_procs.get(name):
unique_child_procs[name] += 1
else:
unique_child_procs[name] = 1
g = {}
g['name'] = group['content']
g['frequency'] = len(tmp)
g['unique_children'] = dict(sorted(unique_child_procs.items(), key=lambda item: item[1], reverse=True))
groups.append(g)
for group in sorted(groups, key=lambda k: k['frequency'], reverse=True):
print(f"{group['name']}: {group['frequency']}")
for child in group['unique_children']:
print(f"\t|- {child}: {group['unique_children'][child]} ({round(group['unique_children'][child] / group['frequency'] * 100, 2)}%)")
print("Top systemd services")
print("-----------------------")
for service in sorted(stats['services'], key=lambda k: k['frequency'], reverse=True):
print(f"{service['serviceName']}: {service['frequency']}")
print("")
print("Top unique processes")
print("-----------------------")
for process in sorted(stats['processes'], key=lambda k: k['frequency'], reverse=True):
print(f"{process['process']}: {process['frequency']}")
def main():
parser = argparse.ArgumentParser(prog='ProcessMonitor results parser',
description='Tool to quickly parse the results from ProcessMonitor without needing to load the timeline')
parser.add_argument('filename', help="Path to the results file generated by ProcessMonitor")
args = parser.parse_args()
if not path.isfile(args.filename):
print(f"Cannot find file {args.filename}")
return
parse(args.filename)
if __name__ == "__main__":
main()