blob: d90c53e07a570c95a5cbc48f897565119d3844b7 [file] [log] [blame]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +00001# 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,
Jeremy Ronquillob6268842017-10-03 13:02:58 -070021# please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000022
23# **********************************************************
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070024# STEP 1: Data management.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000025# **********************************************************
Devin Lim0e967162017-11-03 15:59:53 -070026database_host = 1
27database_port = 2
28database_u_id = 3
29database_pw = 4
30test_name = 5
31branch_name = 6
32old_flow = 7
33save_directory = 8
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000034
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070035print( "**********************************************************" )
36print( "STEP 1: Data management." )
37print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000038
Jeremy Ronquillob6268842017-10-03 13:02:58 -070039# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000040print( "Reading commmand-line args." )
41args <- commandArgs( trailingOnly=TRUE )
42
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070043# ----------------
44# Import Libraries
45# ----------------
46
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000047print( "Importing libraries." )
48library( ggplot2 )
49library( reshape2 )
50library( RPostgreSQL ) # For databases
51
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070052# -------------------
53# Check CLI Arguments
54# -------------------
55
56print( "Verifying CLI args." )
57
Devin Lim0e967162017-11-03 15:59:53 -070058if ( is.na( args[ save_directory ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070059
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -080060 print( paste( "Usage: Rscript SCPFbatchFlowResp.R",
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070061 "<database-host>",
62 "<database-port>",
63 "<database-user-id>",
64 "<database-password>",
65 "<test-name>",
66 "<branch-name>",
Devin Lim0e967162017-11-03 15:59:53 -070067 "<using-old-flow>",
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070068 "<directory-to-save-graphs>",
69 sep=" " ) )
70
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -080071 quit( status = 1 ) # basically exit(), but in R
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000072}
73
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070074# -----------------
75# Create File Names
76# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000077
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070078print( "Creating filenames and title of graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000079
Devin Lim0e967162017-11-03 15:59:53 -070080postOutputFile <- paste( args[ save_directory ],
81 args[ test_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070082 "_",
Devin Lim0e967162017-11-03 15:59:53 -070083 args[ branch_name ],
84 if( args[ old_flow ] == "y" ) "_OldFlow" else "",
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070085 "_PostGraph.jpg",
86 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000087
Devin Lim0e967162017-11-03 15:59:53 -070088delOutputFile <- paste( args[ save_directory ],
89 args[ test_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070090 "_",
Devin Lim0e967162017-11-03 15:59:53 -070091 args[ branch_name ],
92 if( args[ old_flow ] == "y" ) "_OldFlow" else "",
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070093 "_DelGraph.jpg",
94 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000095
Devin Lim0e967162017-11-03 15:59:53 -070096postChartTitle <- paste( "Single Bench Flow Latency - Post\n",
97 "Last 3 Builds",
Devin Lim1bba7622017-11-14 16:31:41 -080098 if( args[ old_flow ] == "y" ) "\nWith Eventually Consistent Flow Rule Store" else "",
Devin Lim0e967162017-11-03 15:59:53 -070099 sep = "" )
100delChartTitle <- paste( "Single Bench Flow Latency - Del\n",
101 "Last 3 Builds",
Devin Lim1bba7622017-11-14 16:31:41 -0800102 if( args[ old_flow ] == "y" ) "\nWith Eventually Consistent Flow Rule Store" else "",
Devin Lim0e967162017-11-03 15:59:53 -0700103 sep = "" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700104
105# ------------------
106# SQL Initialization
107# ------------------
108
109print( "Initializing SQL" )
110
111con <- dbConnect( dbDriver( "PostgreSQL" ),
112 dbname = "onostest",
Devin Lim0e967162017-11-03 15:59:53 -0700113 host = args[ database_host ],
114 port = strtoi( args[ database_port ] ),
115 user = args[ database_u_id ],
116 password = args[ database_pw ] )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700117
118# ---------------------------
119# Batch Flow Resp SQL Command
120# ---------------------------
121
122print( "Generating Batch Flow Resp SQL Command" )
123
124command <- paste( "SELECT * FROM batch_flow_tests WHERE branch='",
Devin Lim0e967162017-11-03 15:59:53 -0700125 args[ branch_name ],
126 "' AND " ,
127 ( if( args[ old_flow ] == 'y' ) "" else "NOT " ) ,
128 "is_old_flow",
129 " ORDER BY date DESC LIMIT 3",
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700130 sep="" )
131
132print( "Sending SQL command:" )
133print( command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000134
135fileData <- dbGetQuery( con, command )
136
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000137
138# **********************************************************
139# STEP 2: Organize data.
140# **********************************************************
141
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700142print( "**********************************************************" )
143print( "STEP 2: Organize Data." )
144print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000145
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700146# -----------------
147# Post Data Sorting
148# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000149
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700150print( "Sorting data for Post." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000151
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800152requiredColumns <- c( "posttoconfrm", "elapsepost" )
153
154tryCatch( postAvgs <- c( fileData[ requiredColumns] ),
155 error = function( e ) {
156 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." )
157 print( "Required columns: " )
158 print( requiredColumns )
159 print( "Actual columns: " )
160 print( names( fileData ) )
161 print( "Error dump:" )
162 print( e )
163 quit( status = 1 )
164 }
165 )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700166
167# -------------------------
168# Post Construct Data Frame
169# -------------------------
170
171postDataFrame <- melt( postAvgs )
172postDataFrame$scale <- fileData$scale
173postDataFrame$date <- fileData$date
174postDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
175
176colnames( postDataFrame ) <- c( "ms",
177 "type",
178 "scale",
179 "date",
180 "iterative" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000181
182# Format data frame so that the data is in the same order as it appeared in the file.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700183postDataFrame$type <- as.character( postDataFrame$type )
184postDataFrame$type <- factor( postDataFrame$type,
185 levels = unique( postDataFrame$type ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000186
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700187postDataFrame <- na.omit( postDataFrame ) # Omit any data that doesn't exist
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700188
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700189print( "Post Data Frame Results:" )
190print( postDataFrame )
191
192# ----------------
193# Del Data Sorting
194# ----------------
195
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800196requiredColumns <- c( "deltoconfrm", "elapsedel" )
197
198tryCatch( delAvgs <- c( fileData[ requiredColumns] ),
199 error = function( e ) {
200 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." )
201 print( "Required columns: " )
202 print( requiredColumns )
203 print( "Actual columns: " )
204 print( names( fileData ) )
205 print( "Error dump:" )
206 print( e )
207 quit( status = 1 )
208 }
209 )
210
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700211
212# ------------------------
213# Del Construct Data Frame
214# ------------------------
215
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800216delDataFrame <- melt( delAvgs )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700217delDataFrame$scale <- fileData$scale
218delDataFrame$date <- fileData$date
219delDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
220
221colnames( delDataFrame ) <- c( "ms",
222 "type",
223 "scale",
224 "date",
225 "iterative" )
226
227# Format data frame so that the data is in the same order as it appeared in the file.
228delDataFrame$type <- as.character( delDataFrame$type )
229delDataFrame$type <- factor( delDataFrame$type,
230 levels = unique( delDataFrame$type ) )
231
232delDataFrame <- na.omit( delDataFrame ) # Omit any data that doesn't exist
233
234print( "Del Data Frame Results:" )
235print( delDataFrame )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700236
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000237# **********************************************************
238# STEP 3: Generate graphs.
239# **********************************************************
240
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700241print( "**********************************************************" )
242print( "STEP 3: Generate Graph." )
243print( "**********************************************************" )
244
245# ------------------------------------------
246# Initializing variables used in both graphs
247# ------------------------------------------
248
249print( "Initializing variables used in both graphs." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000250
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700251theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillob6268842017-10-03 13:02:58 -0700252xLabel <- xlab( "Build Date" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000253yLabel <- ylab( "Latency (ms)" )
254fillLabel <- labs( fill="Type" )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700255colors <- scale_fill_manual( values=c( "#F77670", "#619DFA" ) )
256wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700257barWidth <- 0.3
258imageWidth <- 15
259imageHeight <- 10
260imageDPI <- 200
261
262theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
263 legend.position = "bottom",
264 legend.text = element_text( size = 22 ),
265 legend.title = element_blank(),
266 legend.key.size = unit( 1.5, 'lines' ) )
267
268barGraphFormat <- geom_bar( stat = "identity",
269 width = barWidth )
270
271# -----------------------
272# Post Generate Main Plot
273# -----------------------
274
275print( "Creating main plot for Post graph." )
276
277mainPlot <- ggplot( data = postDataFrame, aes( x = iterative,
278 y = ms,
279 fill = type ) )
280
281# -----------------------------------
282# Post Fundamental Variables Assigned
283# -----------------------------------
284
285print( "Generating fundamental graph data for Post graph." )
286
287xScaleConfig <- scale_x_continuous( breaks = postDataFrame$iterative,
288 label = postDataFrame$date )
289title <- ggtitle( postChartTitle )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000290
291
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700292fundamentalGraphData <- mainPlot +
293 xScaleConfig +
294 xLabel +
295 yLabel +
296 fillLabel +
297 theme +
298 wrapLegend +
299 colors +
300 title
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000301
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700302# --------------------------------
303# Post Generating Bar Graph Format
304# --------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000305
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700306print( "Generating bar graph for Post graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000307
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700308sum <- fileData[ 'posttoconfrm' ] +
309 fileData[ 'elapsepost' ]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000310
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700311values <- geom_text( aes( x = postDataFrame$iterative,
312 y = sum + 0.03 * max( sum ),
313 label = format( sum,
314 digits = 3,
315 big.mark = ",",
316 scientific = FALSE ) ),
317 size = 7.0,
318 fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000319
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700320result <- fundamentalGraphData +
321 barGraphFormat +
322 values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000323
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700324# ----------------------------
325# Post Exporting Graph to File
326# ----------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000327
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700328print( paste( "Saving Post bar chart to", postOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000329
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800330tryCatch( ggsave( postOutputFile,
331 width = imageWidth,
332 height = imageHeight,
333 dpi = imageDPI ),
334 error = function( e ){
335 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
336 print( e )
337 quit( status = 1 )
338 }
339 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000340
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700341print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", postOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000342
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700343# ----------------------
344# Del Generate Main Plot
345# ----------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000346
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700347print( "Creating main plot for Del graph." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700348
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700349mainPlot <- ggplot( data = delDataFrame, aes( x = iterative,
350 y = ms,
351 fill = type ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000352
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700353# ----------------------------------
354# Del Fundamental Variables Assigned
355# ----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000356
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700357print( "Generating fundamental graph data for Del graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000358
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700359xScaleConfig <- scale_x_continuous( breaks = delDataFrame$iterative,
360 label = delDataFrame$date )
361title <- ggtitle( delChartTitle )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700362
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700363fundamentalGraphData <- mainPlot +
364 xScaleConfig +
365 xLabel +
366 yLabel +
367 fillLabel +
368 theme +
369 wrapLegend +
370 colors +
371 title
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000372
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700373# -------------------------------
374# Del Generating Bar Graph Format
375# -------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000376
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700377print( "Generating bar graph for Del graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000378
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700379sum <- fileData[ 'deltoconfrm' ] +
380 fileData[ 'elapsedel' ]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000381
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700382values <- geom_text( aes( x = delDataFrame$iterative,
383 y = sum + 0.03 * max( sum ),
384 label = format( sum,
385 digits = 3,
386 big.mark = ",",
387 scientific = FALSE ) ),
388 size = 7.0,
389 fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000390
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700391result <- fundamentalGraphData +
392 barGraphFormat +
393 title +
394 values
395
396# ---------------------------
397# Del Exporting Graph to File
398# ---------------------------
399
400print( paste( "Saving Del bar chart to", delOutputFile ) )
401
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800402tryCatch( ggsave( delOutputFile,
403 width = imageWidth,
404 height = imageHeight,
405 dpi = imageDPI ),
406 error = function( e ){
407 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
408 print( e )
409 quit( status = 1 )
410 }
411 )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700412
Devin Lim0e967162017-11-03 15:59:53 -0700413print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", delOutputFile ) )
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800414quit( status = 0 )