blob: b86ef6782d7f6e5e4143043df06e0fd519491486 [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(),
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800266 legend.key.size = unit( 1.5, 'lines' ),
267 plot.subtitle = element_text( size=16, hjust=1.0 ) )
268
269subtitle <- paste( "Last Updated: ", format( Sys.time(), format = "%b %d, %Y at %I:%M %p %Z" ), sep="" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700270
271barGraphFormat <- geom_bar( stat = "identity",
272 width = barWidth )
273
274# -----------------------
275# Post Generate Main Plot
276# -----------------------
277
278print( "Creating main plot for Post graph." )
279
280mainPlot <- ggplot( data = postDataFrame, aes( x = iterative,
281 y = ms,
282 fill = type ) )
283
284# -----------------------------------
285# Post Fundamental Variables Assigned
286# -----------------------------------
287
288print( "Generating fundamental graph data for Post graph." )
289
290xScaleConfig <- scale_x_continuous( breaks = postDataFrame$iterative,
291 label = postDataFrame$date )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000292
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800293title <- labs( title = postChartTitle, subtitle = subtitle )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000294
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700295fundamentalGraphData <- mainPlot +
296 xScaleConfig +
297 xLabel +
298 yLabel +
299 fillLabel +
300 theme +
301 wrapLegend +
302 colors +
303 title
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000304
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700305# --------------------------------
306# Post Generating Bar Graph Format
307# --------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000308
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700309print( "Generating bar graph for Post graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000310
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700311sum <- fileData[ 'posttoconfrm' ] +
312 fileData[ 'elapsepost' ]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000313
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700314values <- geom_text( aes( x = postDataFrame$iterative,
315 y = sum + 0.03 * max( sum ),
316 label = format( sum,
317 digits = 3,
318 big.mark = ",",
319 scientific = FALSE ) ),
320 size = 7.0,
321 fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000322
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700323result <- fundamentalGraphData +
324 barGraphFormat +
325 values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000326
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700327# ----------------------------
328# Post Exporting Graph to File
329# ----------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000330
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700331print( paste( "Saving Post bar chart to", postOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000332
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800333tryCatch( ggsave( postOutputFile,
334 width = imageWidth,
335 height = imageHeight,
336 dpi = imageDPI ),
337 error = function( e ){
338 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
339 print( e )
340 quit( status = 1 )
341 }
342 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000343
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700344print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", postOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000345
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700346# ----------------------
347# Del Generate Main Plot
348# ----------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000349
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700350print( "Creating main plot for Del graph." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700351
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700352mainPlot <- ggplot( data = delDataFrame, aes( x = iterative,
353 y = ms,
354 fill = type ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000355
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700356# ----------------------------------
357# Del Fundamental Variables Assigned
358# ----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000359
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700360print( "Generating fundamental graph data for Del graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000361
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700362xScaleConfig <- scale_x_continuous( breaks = delDataFrame$iterative,
363 label = delDataFrame$date )
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800364
365title <- labs( title = delChartTitle, subtitle = subtitle )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700366
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700367fundamentalGraphData <- mainPlot +
368 xScaleConfig +
369 xLabel +
370 yLabel +
371 fillLabel +
372 theme +
373 wrapLegend +
374 colors +
375 title
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000376
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700377# -------------------------------
378# Del Generating Bar Graph Format
379# -------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000380
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700381print( "Generating bar graph for Del graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000382
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700383sum <- fileData[ 'deltoconfrm' ] +
384 fileData[ 'elapsedel' ]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000385
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700386values <- geom_text( aes( x = delDataFrame$iterative,
387 y = sum + 0.03 * max( sum ),
388 label = format( sum,
389 digits = 3,
390 big.mark = ",",
391 scientific = FALSE ) ),
392 size = 7.0,
393 fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000394
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700395result <- fundamentalGraphData +
396 barGraphFormat +
397 title +
398 values
399
400# ---------------------------
401# Del Exporting Graph to File
402# ---------------------------
403
404print( paste( "Saving Del bar chart to", delOutputFile ) )
405
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800406tryCatch( ggsave( delOutputFile,
407 width = imageWidth,
408 height = imageHeight,
409 dpi = imageDPI ),
410 error = function( e ){
411 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
412 print( e )
413 quit( status = 1 )
414 }
415 )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700416
Devin Lim0e967162017-11-03 15:59:53 -0700417print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", delOutputFile ) )
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800418quit( status = 0 )