simple_plotter.py 1.57 KB
Newer Older
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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import sys
from io import StringIO

import json
import csv



def cnl_slice(file, start_delimiter, end_delimiter):

    ## Find beginning
    for line in file:
        if ( line.startswith(start_delimiter) ):
            break

    ## Skip comments and quit on end
    for line in file:
        if ( line.startswith(end_delimiter) ):
            return

        # skip empty or commented lines
        if ( not line or line[0] == "%" or line[0] == "#" ):
            continue

        yield line





def read_header(f):
    str_io = StringIO()

    for line in cnl_slice(f, "%% Begin_Header", "%% End_Header"):
        str_io.write(line)

    str_io.seek(0)
    header = json.load( str_io )

    return header






## MAIN ##
if __name__ == "__main__":

    filename = sys.argv[1]
    print( filename )

    with open( filename ) as in_file:
        assert( in_file.readline() == "%% CPUnetLOGv1\n" )

        header = read_header(in_file)
        print( json.dumps(header, sort_keys=True, indent=4) )  ## XXX

Mario Hock's avatar
Mario Hock committed
62
        ## XXX
63
64
65
        print ("///")
        print()

Mario Hock's avatar
Mario Hock committed
66
67
68
69
70
71
72
73
74
75
        ## Read as lists
        #csv_reader = csv.reader( cnl_slice(in_file, "%% Begin_Body", "%% End_Body"), skipinitialspace=True )
        #csv_header = next(csv_reader)
        #print( csv_header )

        ## Read as dicts
        csv_reader = csv.DictReader( cnl_slice(in_file, "%% Begin_Body", "%% End_Body"), skipinitialspace=True )

        ## print
        for l in csv_reader:
76
            print( l )
Mario Hock's avatar
Mario Hock committed
77
            #print( l["eth0.send"] + ", " + l["eth0.receive"] )
78
79
80
81
82
            pass