blob: 1bcf551ab8043c354898fef90a3adf8a82613749 [file] [log] [blame]
Jeremy Ronquillodae11042018-02-21 09:21:44 -08001# Copyright 2017 Open Networking Foundation (ONF)
2#
3# Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
4# the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
5# or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
6#
7# TestON is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 2 of the License, or
10# (at your option) any later version.
11#
12# TestON is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with TestON. If not, see <http://www.gnu.org/licenses/>.
19#
20# If you have any questions, or if you don't understand R,
21# please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu
22#
23# Example script:
24# Single Bench Flow Latency Graph with Eventually Consistent Flow Rule Store (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFbatchFlowResp_master_OldFlow_PostGraph.jpg):
25# Rscript SCPFbatchFlowResp.R <url> <port> <username> <pass> SCPFbatchFlowResp.R master y /path/to/save/directory/
26
27# **********************************************************
28# STEP 1: Data management.
29# **********************************************************
30
31old_flow <- 7
32save_directory <- 8
33
34print( "**********************************************************" )
35print( "STEP 1: Data management." )
36print( "**********************************************************" )
37
38# Command line arguments are read.
39print( "Reading commmand-line args." )
40args <- commandArgs( trailingOnly=TRUE )
41
42# ----------------
43# Import Libraries
44# ----------------
45
46print( "Importing libraries." )
47library( ggplot2 )
48library( reshape2 )
49library( RPostgreSQL ) # For databases
Devin Lim324806b2018-05-11 15:36:52 -070050source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" )
51source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" )
52source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" )
53source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" )
Jeremy Ronquillodae11042018-02-21 09:21:44 -080054
55# -------------------
56# Check CLI Arguments
57# -------------------
58
59print( "Verifying CLI args." )
60
61if ( length( args ) != save_directory ){
62 usage( "SCPFbatchFlowResp.R", c( "using-old-flow" ) )
63 quit( status = 1 )
64}
65
66# -----------------
67# Create File Names
68# -----------------
69
70print( "Creating filenames and title of graph." )
71
72postOutputFile <- paste( args[ save_directory ],
73 args[ graph_title ],
74 "_",
75 args[ branch_name ],
76 if( args[ old_flow ] == "y" ) "_OldFlow" else "",
77 "_PostGraph.jpg",
78 sep="" )
79
80delOutputFile <- paste( args[ save_directory ],
81 args[ graph_title ],
82 "_",
83 args[ branch_name ],
84 if( args[ old_flow ] == "y" ) "_OldFlow" else "",
85 "_DelGraph.jpg",
86 sep="" )
87
88postChartTitle <- paste( "Single Bench Flow Latency - Post\n",
89 "Last 3 Builds",
90 if( args[ old_flow ] == "y" ) "\nWith Eventually Consistent Flow Rule Store" else "",
91 sep = "" )
92delChartTitle <- paste( "Single Bench Flow Latency - Del\n",
93 "Last 3 Builds",
94 if( args[ old_flow ] == "y" ) "\nWith Eventually Consistent Flow Rule Store" else "",
95 sep = "" )
96
97# ------------------
98# SQL Initialization
99# ------------------
100
101print( "Initializing SQL" )
102
103con <- initSQL( args[ database_host ],
104 args[ database_port ],
105 args[ database_u_id ],
106 args[ database_pw ] )
107
108# ---------------------------
109# Batch Flow Resp SQL Command
110# ---------------------------
111
112print( "Generating Batch Flow Resp SQL Command" )
113
114command <- paste( "SELECT * FROM batch_flow_tests WHERE branch='",
115 args[ branch_name ],
116 "' AND " ,
117 ( if( args[ old_flow ] == 'y' ) "" else "NOT " ) ,
118 "is_old_flow",
119 " ORDER BY date DESC LIMIT 3",
120 sep="" )
121
122fileData <- retrieveData( con, command )
123
124# **********************************************************
125# STEP 2: Organize data.
126# **********************************************************
127
128print( "**********************************************************" )
129print( "STEP 2: Organize Data." )
130print( "**********************************************************" )
131
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800132latestBuildDate <- fileData$date[1]
133
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800134# -----------------
135# Post Data Sorting
136# -----------------
137
138print( "Sorting data for Post." )
139
140requiredColumns <- c( "posttoconfrm", "elapsepost" )
141
142tryCatch( postAvgs <- c( fileData[ requiredColumns] ),
143 error = function( e ) {
144 print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." )
145 print( "Required columns: " )
146 print( requiredColumns )
147 print( "Actual columns: " )
148 print( names( fileData ) )
149 print( "Error dump:" )
150 print( e )
151 quit( status = 1 )
152 }
153 )
154
155# -------------------------
156# Post Construct Data Frame
157# -------------------------
158
159postDataFrame <- melt( postAvgs )
160postDataFrame$scale <- fileData$scale
161postDataFrame$date <- fileData$date
162postDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
163
164colnames( postDataFrame ) <- c( "ms",
165 "type",
166 "scale",
167 "date",
168 "iterative" )
169
170# Format data frame so that the data is in the same order as it appeared in the file.
171postDataFrame$type <- as.character( postDataFrame$type )
172postDataFrame$type <- factor( postDataFrame$type,
173 levels = unique( postDataFrame$type ) )
174
175postDataFrame <- na.omit( postDataFrame ) # Omit any data that doesn't exist
176
177print( "Post Data Frame Results:" )
178print( postDataFrame )
179
180# ----------------
181# Del Data Sorting
182# ----------------
183
184requiredColumns <- c( "deltoconfrm", "elapsedel" )
185
186tryCatch( delAvgs <- c( fileData[ requiredColumns] ),
187 error = function( e ) {
188 print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." )
189 print( "Required columns: " )
190 print( requiredColumns )
191 print( "Actual columns: " )
192 print( names( fileData ) )
193 print( "Error dump:" )
194 print( e )
195 quit( status = 1 )
196 }
197 )
198
199
200# ------------------------
201# Del Construct Data Frame
202# ------------------------
203
204delDataFrame <- melt( delAvgs )
205delDataFrame$scale <- fileData$scale
206delDataFrame$date <- fileData$date
207delDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
208
209colnames( delDataFrame ) <- c( "ms",
210 "type",
211 "scale",
212 "date",
213 "iterative" )
214
215# Format data frame so that the data is in the same order as it appeared in the file.
216delDataFrame$type <- as.character( delDataFrame$type )
217delDataFrame$type <- factor( delDataFrame$type,
218 levels = unique( delDataFrame$type ) )
219
220delDataFrame <- na.omit( delDataFrame ) # Omit any data that doesn't exist
221
222print( "Del Data Frame Results:" )
223print( delDataFrame )
224
225# **********************************************************
226# STEP 3: Generate graphs.
227# **********************************************************
228
229print( "**********************************************************" )
230print( "STEP 3: Generate Graph." )
231print( "**********************************************************" )
232
233# ------------------------------------------
234# Initializing variables used in both graphs
235# ------------------------------------------
236
237print( "Initializing variables used in both graphs." )
238
239defaultTextSize()
240xLabel <- xlab( "Build Date" )
241yLabel <- ylab( "Latency (ms)" )
242fillLabel <- labs( fill="Type" )
243
244colors <- scale_fill_manual( values=c( webColor( "redv2" ),
245 webColor( "light_blue" ) ) )
246
247wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
248
249barWidth <- 0.3
250
251theme <- graphTheme()
252
253barGraphFormat <- geom_bar( stat = "identity",
254 width = barWidth )
255
256# -----------------------
257# Post Generate Main Plot
258# -----------------------
259
260print( "Creating main plot for Post graph." )
261
262mainPlot <- ggplot( data = postDataFrame, aes( x = iterative,
263 y = ms,
264 fill = type ) )
265
266# -----------------------------------
267# Post Fundamental Variables Assigned
268# -----------------------------------
269
270print( "Generating fundamental graph data for Post graph." )
271
272xScaleConfig <- scale_x_continuous( breaks = postDataFrame$iterative,
273 label = postDataFrame$date )
274
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800275title <- labs( title = postChartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800276
277fundamentalGraphData <- mainPlot +
278 xScaleConfig +
279 xLabel +
280 yLabel +
281 fillLabel +
282 theme +
283 wrapLegend +
284 colors +
285 title
286
287# --------------------------------
288# Post Generating Bar Graph Format
289# --------------------------------
290
291print( "Generating bar graph for Post graph." )
292
293sum <- fileData[ 'posttoconfrm' ] +
294 fileData[ 'elapsepost' ]
295
296values <- geom_text( aes( x = postDataFrame$iterative,
297 y = sum + 0.03 * max( sum ),
298 label = format( sum,
299 digits = 3,
300 big.mark = ",",
301 scientific = FALSE ) ),
302 size = 7.0,
303 fontface = "bold" )
304
305result <- fundamentalGraphData +
306 barGraphFormat +
307 values
308
309# ----------------------------
310# Post Exporting Graph to File
311# ----------------------------
312
313saveGraph( postOutputFile )
314
315# ----------------------
316# Del Generate Main Plot
317# ----------------------
318
319print( "Creating main plot for Del graph." )
320
321mainPlot <- ggplot( data = delDataFrame, aes( x = iterative,
322 y = ms,
323 fill = type ) )
324
325# ----------------------------------
326# Del Fundamental Variables Assigned
327# ----------------------------------
328
329print( "Generating fundamental graph data for Del graph." )
330
331xScaleConfig <- scale_x_continuous( breaks = delDataFrame$iterative,
332 label = delDataFrame$date )
333
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800334title <- labs( title = delChartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800335
336fundamentalGraphData <- mainPlot +
337 xScaleConfig +
338 xLabel +
339 yLabel +
340 fillLabel +
341 theme +
342 wrapLegend +
343 colors +
344 title
345
346# -------------------------------
347# Del Generating Bar Graph Format
348# -------------------------------
349
350print( "Generating bar graph for Del graph." )
351
352sum <- fileData[ 'deltoconfrm' ] +
353 fileData[ 'elapsedel' ]
354
355values <- geom_text( aes( x = delDataFrame$iterative,
356 y = sum + 0.03 * max( sum ),
357 label = format( sum,
358 digits = 3,
359 big.mark = ",",
360 scientific = FALSE ) ),
361 size = 7.0,
362 fontface = "bold" )
363
364result <- fundamentalGraphData +
365 barGraphFormat +
366 title +
367 values
368
369# ---------------------------
370# Del Exporting Graph to File
371# ---------------------------
372
373saveGraph( delOutputFile )
374quit( status = 0 )