simple_plotter.py 1.83 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
35
36
37
38
39
## 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()) )


Mario Hock's avatar
Mario Hock committed
40

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

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

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


    ## Plot with matplotlib.

Mario Hock's avatar
Mario Hock committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    # Twin plot
    #   (see http://matplotlib.org/examples/api/two_scales.html)

    fig, ax1 = plt.subplots()
    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)")


    ax2 = ax1.twinx()
    plt.ylim(0,100)
    ax2.set_ylabel('CPU util (%)')

76
    for col_name in cpu_cols:
Mario Hock's avatar
Mario Hock committed
77
78
        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)")
79

Mario Hock's avatar
Mario Hock committed
80
    ## TODO twinx:
Mario Hock's avatar
Mario Hock committed
81

82
    plt.legend()
Mario Hock's avatar
Mario Hock committed
83
    plt.show()