simple_plotter.py 1.35 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
## 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

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

49
50
51
52
53
    cpu_cols = [ cpu_name + ".util" for cpu_name in cnl_file.get_cpus() ]

    cols = cnl_file.get_csv_columns()
    x_values = cols["end"]
    print( cols )
Mario Hock's avatar
Mario Hock committed
54
55
56
57


    ## Plot with matplotlib.

58
59
60
61
62
    #for col_name in net_cols:
    for col_name in cpu_cols:
        plt.plot(x_values , cols[col_name], label=col_name)

    ## TODO twinx: http://matplotlib.org/examples/api/two_scales.html
Mario Hock's avatar
Mario Hock committed
63

64
    plt.legend()
Mario Hock's avatar
Mario Hock committed
65
    plt.show()