-
Notifications
You must be signed in to change notification settings - Fork 11
/
grepdebug.py
executable file
·54 lines (45 loc) · 1.43 KB
/
grepdebug.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
#!/usr/bin/python2
#
# Script for parsing GarnetStandalone debug prints
import ntpath
import subprocess
import sys
# Options
in_file = "debug.txt" # default file name in case no args supplied
greps = ["command line:", "vc_busy_counter", "send_allowed=1"]
mixed_greps = False
sorting = True
def exit_verbose(s):
print s
sys.exit(1)
if len(sys.argv) > 1:
in_file = sys.argv[1]
if not ntpath.isfile(in_file):
exit_verbose("File {0} does not exist.".format(in_file))
else:
exit_verbose("Usage: ./grepdebug.py filename")
dir_name, base_name = ntpath.split(in_file)
fn, ext = ntpath.splitext(base_name)
if len(dir_name) > 0:
dir_name += "/"
out_file = ntpath.join(dir_name, fn + "_parsed" + ext)
out_file_sorted = ntpath.join(dir_name, fn + "_parsed_sorted" + ext)
with open(in_file, "rt") as fin, open(out_file, "wt") as fout:
if mixed_greps:
for line in fin:
for grep in greps:
if grep in line:
fout.write(line)
break
else:
for grep in greps:
for line in fin:
if grep in line:
fout.write(line)
fin.seek(0)
print "Parsed debug info written to: " + out_file
if sorting:
proc = subprocess.Popen("sort -rV " + out_file + " -o " + out_file_sorted,
shell=True)
proc.wait()
print "Sorted debug info written to: " + out_file_sorted