log_parser.py 2.36 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Copyright 2021 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Jonas Kaufmann's avatar
Jonas Kaufmann committed
23
import json
Hejing Li's avatar
Hejing Li committed
24
25
import os
import pathlib
Hejing Li's avatar
Hejing Li committed
26
import re
Jonas Kaufmann's avatar
Jonas Kaufmann committed
27
28
import shutil
import sys
Hejing Li's avatar
Hejing Li committed
29
30

# How to use
Jonas Kaufmann's avatar
Jonas Kaufmann committed
31
# $ python3 pyexps/parser.py out/qemu-wire-ib-TCPs-1.json
Hejing Li's avatar
Hejing Li committed
32
33
34
35
36
37
#

log_file = sys.argv[1]
log = open(log_file, 'r')

exp_log = json.load(log)
Hejing Li's avatar
Hejing Li committed
38
run_num = re.split('-|\.', log_file)[-2]
Hejing Li's avatar
Hejing Li committed
39
40
#Name, starting & ending time
exp_name = exp_log['exp_name']
41
42
43
44

p = pathlib.Path(log_file)
tooutdir = f'/{exp_name}/{run_num}'
outdir = '/'.join(list(p.parts)[0:-1]) + tooutdir
Hejing Li's avatar
Hejing Li committed
45
46

if not os.path.exists(outdir):
Jonas Kaufmann's avatar
Jonas Kaufmann committed
47
    raise Exception('no such directory')
Hejing Li's avatar
Hejing Li committed
48
49
50

start_end_path = os.path.join(outdir, 'start_end.txt')
start_end_file = open(start_end_path, 'w')
Jonas Kaufmann's avatar
Jonas Kaufmann committed
51
52
53
start_end_file.write('start time: ' + str(exp_log['start_time']) + '\n')
start_end_file.write('end time: ' + str(exp_log['end_time']) + '\n')
start_end_file.write('success: ' + str(exp_log['success']))
Hejing Li's avatar
Hejing Li committed
54
55
start_end_file.close()

Jonas Kaufmann's avatar
Jonas Kaufmann committed
56
for i in exp_log['sims']:
Hejing Li's avatar
Hejing Li committed
57
58
59
    #print(i)
    simdir = os.path.join(outdir, i)
    sim_out_file = open(simdir, 'w')
Jonas Kaufmann's avatar
Jonas Kaufmann committed
60
61

    for j in exp_log['sims'][i]:
Hejing Li's avatar
Hejing Li committed
62
        #print(j)
Jonas Kaufmann's avatar
Jonas Kaufmann committed
63
64
65
66
        sim_out_file.write(j + '\n')

        if (j == 'class'):
            sim_out_file.write(exp_log['sims'][i][j] + '\n')
Hejing Li's avatar
Hejing Li committed
67
68

        else:
Jonas Kaufmann's avatar
Jonas Kaufmann committed
69
70

            for k in exp_log['sims'][i][j]:
Hejing Li's avatar
Hejing Li committed
71
                sim_out_file.write(k + '\n')
Jonas Kaufmann's avatar
Jonas Kaufmann committed
72

Hejing Li's avatar
Hejing Li committed
73
    sim_out_file.close()