-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_field.py
35 lines (28 loc) · 890 Bytes
/
sort_field.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
#!/usr/bin/python3.3-sp
import fileinput
FIELD_NAMES = []
FIELD_NAMES_LINE = ''
def process(line, count, stats_dict):
global FIELD_NAMES
global FIELD_NAMES_LINE
# snarf the col headers
if count == 4:
FIELD_NAMES = line.split()
FIELD_NAMES_LINE = line
# Start noting data after line 4
if count > 4:
stats_part = line[:46]
desc_part = line[46:]
stats_dict[desc_part] = dict(zip(FIELD_NAMES, stats_part.split()))
stats_dict[desc_part]['line'] = line
if __name__ == '__main__':
count = 0
stats_dict = {}
for line in fileinput.input():
process(line, count, stats_dict)
count += 1
# Sort by tottime
sorted_keys = sorted(stats_dict.keys(), key=lambda k: float(stats_dict[k]['cumtime']))
print(FIELD_NAMES_LINE)
for key in sorted_keys:
print(stats_dict[key]['line'])