-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_dmtcp_logs.py
executable file
·51 lines (42 loc) · 1.9 KB
/
parse_dmtcp_logs.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
#!/usr/bin/python3.5
import json
import collections
import argparse as ap
from grako import parse
from grako.util import asjson
from dmtcp_log_parser import DmtcpLogLanguageParser
from dmtcp_log_semantics import DmtcpLogLanguageSemantics
HELP='This program implements a parser for DMTCP Jalib log format\n\n'\
def main():
parser = ap.ArgumentParser(prog='./parse_dmtcp_logs.py',
description=HELP,
formatter_class=ap.RawTextHelpFormatter)
logtypes = set(("TRACE", "WARNING", "NOTE", "ERROR", "ALL"))
parser.add_argument('-l', '--log-filename',
help='DMTCP log file', required=True)
parser.add_argument('-p', '--filter-pids', nargs='+',
help='List of process ids to filter', required=False)
parser.add_argument('-n', '--filter-filenames', nargs='+',
help='List of filenames (without extension) to filter',
required=False)
parser.add_argument('-f', '--filter-functions', nargs='+',
help='List of function names to filter', required=False)
parser.add_argument('-m', '--filter-logtypes', nargs='+', choices=logtypes,
help='List of log message types to filter', required=False)
args = parser.parse_args()
text = open(args.log_filename, 'r').read()
semantics_obj = semantics=DmtcpLogLanguageSemantics()
if args.filter_pids:
semantics_obj.add_pid_filter(args.filter_pids)
if args.filter_logtypes and not("ALL" in args.filter_logtypes):
semantics_obj.add_logtype_filter(args.filter_logtypes)
if args.filter_filenames:
semantics_obj.add_filename_filter(args.filter_filenames)
if args.filter_functions:
semantics_obj.add_function_filter(args.filter_functions)
parser = DmtcpLogLanguageParser(semantics=semantics_obj)
ast = parser.parse(text)
print('Results:')
print(ast)
if __name__ == '__main__':
main()