simple_plotter.py 2.11 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

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


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
## 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
35
    print( cnl_file.get_comment() )
Mario Hock's avatar
Mario Hock committed
36
37
38
39
40

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


Mario Hock's avatar
Mario Hock committed
41

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

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

52
53
54
55
    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
56
    #print( cols )   ## XXX
Mario Hock's avatar
Mario Hock committed
57
58
59
60


    ## Plot with matplotlib.

Mario Hock's avatar
Mario Hock committed
61
62
63
    # Twin plot
    #   (see http://matplotlib.org/examples/api/two_scales.html)

Mario Hock's avatar
Mario Hock committed
64
65
66
67
    #fig, ax1 = plt.subplots()  ## twin
    fig, axes = plt.subplots(2, 1, sharex=True)
    (ax1, ax2) = axes

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


Mario Hock's avatar
Mario Hock committed
73
74
75
76
77
78
79
    plt.ylim(0,10**10)
    ax1.set_ylabel('Throughput (Bit/s)')

    for col_name in net_cols:
        ax1.plot(x_values , cols[col_name], label=col_name)
        ax1.plot(x_values , calc_ema(cols[col_name], 0.2), label=col_name+" (ema)")

Mario Hock's avatar
Mario Hock committed
80
    ax1.legend()
Mario Hock's avatar
Mario Hock committed
81

Mario Hock's avatar
Mario Hock committed
82
    #ax2 = ax1.twinx()      ## twin
Mario Hock's avatar
Mario Hock committed
83
84
85
    plt.ylim(0,100)
    ax2.set_ylabel('CPU util (%)')

86
    for col_name in cpu_cols:
Mario Hock's avatar
Mario Hock committed
87
88
        ax2.plot(x_values , cols[col_name], label=col_name)
        #ax2.plot(x_values , calc_ema(cols[col_name], 0.2), label=col_name+" (ema)")
89

Mario Hock's avatar
Mario Hock committed
90
    ax2.legend()
Mario Hock's avatar
Mario Hock committed
91
92

    plt.show()