Lava: Display benchmark results in nsec
[lttng-ci.git] / scripts / lttng-baremetal-tests / generate-plots.py
CommitLineData
b87dc589
FD
1# Copyright (C) 2017 - Francis Deslauriers <francis.deslauriers@efficios.com>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16
17import os, sys
18import numpy as np
19import pandas as pd
20
21#Set Matplotlib to use the PNG non interactive backend
22import matplotlib as mpl
23mpl.use('Agg')
24
25import matplotlib.pyplot as plt
26from matplotlib.ticker import MaxNLocator
27from cycler import cycler
28
29def rename_cols(df):
f758d98b
FD
30 new_cols = {'baseline_1thr_peritermean': 'basel_1thr',
31 'baseline_2thr_peritermean': 'basel_2thr',
32 'baseline_4thr_peritermean': 'basel_4thr',
33 'baseline_8thr_peritermean': 'basel_8thr',
34 'baseline_16thr_peritermean': 'basel_16thr',
35 'lttng_1thr_peritermean': 'lttng_1thr',
36 'lttng_2thr_peritermean': 'lttng_2thr',
37 'lttng_4thr_peritermean': 'lttng_4thr',
38 'lttng_8thr_peritermean': 'lttng_8thr',
39 'lttng_16thr_peritermean': 'lttng_16thr'
b87dc589
FD
40 }
41 df.rename(columns=new_cols, inplace=True)
42 return df
43
c5545ca0
FD
44def convert_us_to_ns(df):
45 cols = [col for col in df.columns if 'periter' in col]
46 df[cols] = df[cols].apply(lambda x: x*1000)
47 return df
48
b87dc589
FD
49def create_plot(df, graph_type):
50 # We split the data into two plots so it's easier to read
51 lower = ['basel_1thr', 'basel_2thr', 'basel_4thr', 'lttng_1thr', 'lttng_2thr', 'lttng_4thr']
52 lower_color = ['lightcoral', 'gray', 'chartreuse', 'red', 'black', 'forestgreen']
53 upper = ['basel_8thr', 'basel_16thr', 'lttng_8thr', 'lttng_16thr']
54 upper_color = ['deepskyblue', 'orange', 'mediumblue', 'saddlebrown']
55
b87dc589
FD
56 title='Meantime per syscalls for {} testcase'.format(graph_type)
57
58 # Create a plot with 2 sub-plots
59 f, arrax = plt.subplots(2, sharex=True, figsize=(12, 14))
60
61 f.suptitle(title, fontsize=18)
62
63 for (ax, sub, colors) in zip(arrax, [lower, upper], [lower_color,upper_color]):
64 curr_df = df[sub]
65 ax.set_prop_cycle(cycler('color', colors))
66 ax.plot(curr_df, marker='o')
67 ax.set_ylim(0)
68 ax.grid()
69 ax.set_xlabel('Jenkins Build ID')
f758d98b 70 ax.set_ylabel('Meantime per syscall [us]')
b87dc589
FD
71 ax.legend(labels=curr_df.columns.values, bbox_to_anchor=(1.2,1))
72 ax.xaxis.set_major_locator(MaxNLocator(integer=True))
73
74 plt.savefig('{}.png'.format(graph_type), bbox_inches='tight')
75
76# Writes a file that contains commit id of all configurations shown in the
77# plots
78def create_metadata_file(res_dir):
79 list_ = []
80 for dirname, dirnames, res_files in os.walk('./'+res_dir):
81 if len(dirnames) > 0:
82 continue
83 metadata = pd.read_csv(os.path.join(dirname, 'metadata.csv'))
84 list_.append(metadata)
85
86 df = pd.concat(list_)
87 df.index=df.build_id
88 df.sort_index(inplace=True)
89 df.to_csv('metadata.csv', index=False)
90
91#Iterates over a result directory and creates the plots for the different
92#testcases
93def create_plots(res_dir):
94 df = pd.DataFrame()
95 metadata_df = pd.DataFrame()
96 list_ = []
97 for dirname, dirnames, res_files in os.walk('./'+res_dir):
98 if len(dirnames) > 0:
99 continue
100 metadata = pd.read_csv(os.path.join(dirname, 'metadata.csv'))
101
102 for res in res_files:
103 if res in 'metadata.csv':
104 continue
105 tmp = pd.read_csv(os.path.join(dirname, res))
106 #Use the build id as the index for the dataframe for filtering
107 tmp.index = metadata.build_id
108 #Add the testcase name to the row for later filtering
109 tmp['testcase'] = res.split('.')[0]
110 list_.append(tmp)
111
112 df = pd.concat(list_)
c5545ca0 113 df = convert_us_to_ns(df)
b87dc589
FD
114 df = rename_cols(df)
115 df.sort_index(inplace=True)
116
117 #Go over the entire dataframe by testcase and create a plot for each type
118 for testcase in df.testcase.unique():
119 df_testcase = df.loc[df['testcase'] == testcase]
120 create_plot(df=df_testcase, graph_type=testcase)
121
122def main():
123 res_path = sys.argv[1]
124 create_plots(os.path.join(res_path))
125 create_metadata_file(os.path.join(res_path))
126
127if __name__ == '__main__':
128 main()
This page took 0.027221 seconds and 4 git commands to generate.