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

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

Mario Hock's avatar
Mario Hock committed
8
from cnl_library import CNLParser, calc_ema
Mario Hock's avatar
Mario Hock committed
9
10


Mario Hock's avatar
Mario Hock committed
11
12
13
14
15
16
17
18
19
20
21
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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## 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() )
Mario Hock's avatar
Mario Hock committed
36
    print( cnl_file.get_comment() )
Mario Hock's avatar
Mario Hock committed
37
38
39
40
41

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


Mario Hock's avatar
Mario Hock committed
42

43
    ## Prepare data for matplotlib
Mario Hock's avatar
Mario Hock committed
44

Mario Hock's avatar
Mario Hock committed
45
46
    #nics = cnl_file.get_nics()
    nics = ("eth1", "eth2")
47
48
    net_cols = list()
    nic_fields = [".send", ".receive"]
Mario Hock's avatar
Mario Hock committed
49
    for nic_name in nics:
50
51
        for nic_field in nic_fields:
            net_cols.append( nic_name + nic_field )
Mario Hock's avatar
Mario Hock committed
52

53
54
55
56
    cpu_cols = [ cpu_name + ".util" for cpu_name in cnl_file.get_cpus() ]

    cols = cnl_file.get_csv_columns()
    x_values = cols["end"]
Mario Hock's avatar
Mario Hock committed
57
    #print( cols )   ## XXX
Mario Hock's avatar
Mario Hock committed
58
59
60
61


    ## Plot with matplotlib.

62
63
    ## Create figure (window/file)
    fig = plt.figure()
Mario Hock's avatar
Mario Hock committed
64

65
66
67
    ## Draw comment on the figure.
    t = matplotlib.text.Text(10,10, "Comment: " + cnl_file.get_comment(), figure=fig)
    fig.texts.append(t)
Mario Hock's avatar
Mario Hock committed
68

Mario Hock's avatar
Mario Hock committed
69
    #plt.title( cnl_file.get_comment() )
70
    #plt.figtext(0.01, 0.02, "Comment: " + cnl_file.get_comment())
Mario Hock's avatar
Mario Hock committed
71
72


73
74
75
76
77
78
    ax_net = fig.add_subplot(211)
    #ax_net = fig.add_subplot(111)  ## twin


    ax_net.set_ylim(0,10**10)
    ax_net.set_ylabel('Throughput (Bit/s)')
Mario Hock's avatar
Mario Hock committed
79
80

    for col_name in net_cols:
81
82
83
84
        ax_net.plot(x_values , cols[col_name], label=col_name)
        ax_net.plot(x_values , calc_ema(cols[col_name], 0.2), label=col_name+" (ema)")

    ax_net.legend()
Mario Hock's avatar
Mario Hock committed
85
86


87
88
89
90
    #ax_cpu = ax_net.twinx()      ## twin
    ax_cpu = fig.add_subplot(212, sharex=ax_net)
    ax_cpu.set_ylim(0,100)
    ax_cpu.set_ylabel('CPU util (%)')
Mario Hock's avatar
Mario Hock committed
91

92
    for col_name in cpu_cols:
93
        ax_cpu.plot(x_values , cols[col_name], label=col_name)
Mario Hock's avatar
Mario Hock committed
94
        #ax2.plot(x_values , calc_ema(cols[col_name], 0.2), label=col_name+" (ema)")
95

96
    ax_cpu.legend()
Mario Hock's avatar
Mario Hock committed
97
98

    plt.show()