-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmtcp_log_semantics.py
121 lines (94 loc) · 3.03 KB
/
dmtcp_log_semantics.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/python3.5
from __future__ import print_function
import sys
from dmtcp_log_parser import DmtcpLogLanguageParser
class DmtcpLogLanguageSemantics(object):
def __init__(self):
self.filters = []
def apply_filter(self, f, ast):
if ast.dmtcp_msg:
return f(ast.dpid, ast.dmtype, ast.dfname, ast.dfnc)
elif ast.mtcp_msg:
return f(ast.mpid, ast.mmtype, ast.mfname, ast.mfnc)
else:
return False
def add_pid_filter(self, pid_list):
self.filters.append(lambda pid, mtype, fname, fnc: str(pid) in pid_list)
def add_logtype_filter(self, log_list):
self.filters.append(lambda pid, mtype, fname, fnc: mtype in log_list)
def add_filename_filter(self, fname_list):
self.filters.append(lambda pid, mtype, fname, fnc: fname in fname_list)
def add_function_filter(self, fnc_list):
self.filters.append(lambda pid, mtype, fname, fnc: fnc in fnc_list)
def start(self, ast):
outstr = ""
for x in ast:
outstr += x
return outstr
def msg(self, ast):
outstr = ""
for f in self.filters:
if not self.apply_filter(f, ast):
return outstr
if ast.dmtcp_msg:
outstr += "[%d]: %s at %s%s:%d in %s; REASON=%s\n" % (ast.dpid, ast.dmtype, ast.dfname, ast.dfext, ast.dlnum, ast.dfnc, ast.drea)
for x in ast.dargs:
outstr += x
elif ast.mtcp_msg:
outstr += "[%d]: MTCP %s%s:%d in %s; REASON=%s\n" % (ast.mpid, ast.mfname, ast.mfext, ast.mlnum, ast.mfnc, ast.mrea)
for x in ast.margs:
outstr += x
else:
raise Exception("Unknown log message")
return outstr
def pid(self, ast):
return int(ast)
def msg_type(self, ast):
return ast
def fname(self, ast):
return ast
def fext(self, ast):
return ast
def lnum(self, ast):
return int(ast)
def fnc(self, ast):
return ast
def reason(self, ast):
return ast
def args(self, ast):
if ast.avp:
return " %s\n" % (ast.avp)
elif ast.cd:
return " %s\n" % (ast.cd)
elif ast.dl:
return " %s\n" % (ast.dl)
else:
print(ast)
raise Exception("Unknown args expression")
return ""
def dashed_line(self, ast):
return str(ast).strip()
def connection_description(self, ast):
return str(ast).strip()
def arg_val_pair(self, ast):
outstr = ""
if ast.avpa:
outstr += ast.avpa
outstr += " = "
if ast.avpv:
outstr += ast.avpv
else:
print(ast)
raise Exception("Unknown arg-val pair expression")
return outstr
def arg(self, ast):
return str(ast).strip()
def value(self, ast):
return str(ast).strip()
def calc(text):
parser = DmtcpLogLanguageParser(semantics=DmtcpLogLanguageSemantics())
return parser.parse(text)
if __name__ == '__main__':
text = open(sys.argv[1]).read()
result = calc(text)
print(result)