simple_plotter.py 1.57 KB
Newer Older
Mario Hock's avatar
Mario Hock committed
1
2
3
4
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import sys
Mario Hock's avatar
Mario Hock committed
5
import matplotlib.pyplot as plt
Mario Hock's avatar
Mario Hock committed
6
7
8
9

from cnl_library import CNLParser


Mario Hock's avatar
Mario Hock committed
10
11
12
13
14
15
16
17
18
19
20
def append_twice(base_list, extend_list):
    if ( isinstance(extend_list, list) ):
        for x in extend_list:
            base_list.append(x)
            base_list.append(x)
    else:
        base_list.append(extend_list)
        base_list.append(extend_list)



Mario Hock's avatar
Mario Hock committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## MAIN ##
if __name__ == "__main__":

    ### DEMO:

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

    ## * Parse input file. *
    cnl_file = CNLParser(filename)


    ## Display header informations.
    print( cnl_file.get_type() )

    print( "CPUs: " + str(cnl_file.get_cpus()) )
    print( "NICs: " + str(cnl_file.get_nics()) )

    ## Display some csv/data fields.
    names = None
Mario Hock's avatar
Mario Hock committed
41
    names = ["begin", "end", "eth0.send", "eth0.receive"]
Mario Hock's avatar
Mario Hock committed
42
43
    print( names )

Mario Hock's avatar
Mario Hock committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    ### Prepare lists for matplotlib.
    #x_values = list()
    #y1_values = list()
    #y2_values = list()
    #for x in cnl_file.get_csv_iterator(names):
        #x_values.extend( x[0:2] )

        #append_twice( y1_values, x[2] )
        #append_twice( y2_values, x[3] )


    ## Prepare lists for matplotlib.
    x_values = list()
    y1_values = list()
    y2_values = list()
Mario Hock's avatar
Mario Hock committed
59
    for x in cnl_file.get_csv_iterator(names):
Mario Hock's avatar
Mario Hock committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        x_values.append( x[1] )

        y1_values.append( x[2] )
        y2_values.append( x[3] )

    ## Plot with matplotlib.

    print( x_values )
    print( y1_values )
    print( y2_values )

    plt.plot(x_values, y1_values)
    plt.plot(x_values, y2_values)
    #plt.ylabel('some numbers')
    plt.show()