blob: a2166c1ee3119025400d3b5f32fccacd92a989ff [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
60 print( paste( "Usage: Rscript SCPFbatchFlowResp",
61 "<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 Ronquillo6df87812017-08-28 16:17:36 +000071 q() # basically exit(), but in R
72}
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 Ronquillo7673f802017-10-30 09:42:44 -0700152postAvgs <- c( fileData[ 'posttoconfrm' ],
153 fileData[ 'elapsepost' ] )
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" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000169
170# 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 -0700171postDataFrame$type <- as.character( postDataFrame$type )
172postDataFrame$type <- factor( postDataFrame$type,
173 levels = unique( postDataFrame$type ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000174
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700175postDataFrame <- na.omit( postDataFrame ) # Omit any data that doesn't exist
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700176
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700177print( "Post Data Frame Results:" )
178print( postDataFrame )
179
180# ----------------
181# Del Data Sorting
182# ----------------
183
184print( "Sorting data for Del." )
185avgs <- c( fileData[ 'deltoconfrm' ],
186 fileData[ 'elapsedel' ] )
187
188# ------------------------
189# Del Construct Data Frame
190# ------------------------
191
192delDataFrame <- melt( avgs )
193delDataFrame$scale <- fileData$scale
194delDataFrame$date <- fileData$date
195delDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
196
197colnames( delDataFrame ) <- c( "ms",
198 "type",
199 "scale",
200 "date",
201 "iterative" )
202
203# Format data frame so that the data is in the same order as it appeared in the file.
204delDataFrame$type <- as.character( delDataFrame$type )
205delDataFrame$type <- factor( delDataFrame$type,
206 levels = unique( delDataFrame$type ) )
207
208delDataFrame <- na.omit( delDataFrame ) # Omit any data that doesn't exist
209
210print( "Del Data Frame Results:" )
211print( delDataFrame )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700212
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000213# **********************************************************
214# STEP 3: Generate graphs.
215# **********************************************************
216
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700217print( "**********************************************************" )
218print( "STEP 3: Generate Graph." )
219print( "**********************************************************" )
220
221# ------------------------------------------
222# Initializing variables used in both graphs
223# ------------------------------------------
224
225print( "Initializing variables used in both graphs." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000226
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700227theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillob6268842017-10-03 13:02:58 -0700228xLabel <- xlab( "Build Date" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000229yLabel <- ylab( "Latency (ms)" )
230fillLabel <- labs( fill="Type" )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700231colors <- scale_fill_manual( values=c( "#F77670", "#619DFA" ) )
232wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700233barWidth <- 0.3
234imageWidth <- 15
235imageHeight <- 10
236imageDPI <- 200
237
238theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
239 legend.position = "bottom",
240 legend.text = element_text( size = 22 ),
241 legend.title = element_blank(),
242 legend.key.size = unit( 1.5, 'lines' ) )
243
244barGraphFormat <- geom_bar( stat = "identity",
245 width = barWidth )
246
247# -----------------------
248# Post Generate Main Plot
249# -----------------------
250
251print( "Creating main plot for Post graph." )
252
253mainPlot <- ggplot( data = postDataFrame, aes( x = iterative,
254 y = ms,
255 fill = type ) )
256
257# -----------------------------------
258# Post Fundamental Variables Assigned
259# -----------------------------------
260
261print( "Generating fundamental graph data for Post graph." )
262
263xScaleConfig <- scale_x_continuous( breaks = postDataFrame$iterative,
264 label = postDataFrame$date )
265title <- ggtitle( postChartTitle )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000266
267
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700268fundamentalGraphData <- mainPlot +
269 xScaleConfig +
270 xLabel +
271 yLabel +
272 fillLabel +
273 theme +
274 wrapLegend +
275 colors +
276 title
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000277
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700278# --------------------------------
279# Post Generating Bar Graph Format
280# --------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000281
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700282print( "Generating bar graph for Post graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000283
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700284sum <- fileData[ 'posttoconfrm' ] +
285 fileData[ 'elapsepost' ]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000286
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700287values <- geom_text( aes( x = postDataFrame$iterative,
288 y = sum + 0.03 * max( sum ),
289 label = format( sum,
290 digits = 3,
291 big.mark = ",",
292 scientific = FALSE ) ),
293 size = 7.0,
294 fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000295
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700296result <- fundamentalGraphData +
297 barGraphFormat +
298 values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000299
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700300# ----------------------------
301# Post Exporting Graph to File
302# ----------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000303
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700304print( paste( "Saving Post bar chart to", postOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000305
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700306ggsave( postOutputFile,
307 width = imageWidth,
308 height = imageHeight,
309 dpi = imageDPI )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000310
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700311print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", postOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000312
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700313# ----------------------
314# Del Generate Main Plot
315# ----------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000316
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700317print( "Creating main plot for Del graph." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700318
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700319mainPlot <- ggplot( data = delDataFrame, aes( x = iterative,
320 y = ms,
321 fill = type ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000322
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700323# ----------------------------------
324# Del Fundamental Variables Assigned
325# ----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000326
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700327print( "Generating fundamental graph data for Del graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000328
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700329xScaleConfig <- scale_x_continuous( breaks = delDataFrame$iterative,
330 label = delDataFrame$date )
331title <- ggtitle( delChartTitle )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700332
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700333fundamentalGraphData <- mainPlot +
334 xScaleConfig +
335 xLabel +
336 yLabel +
337 fillLabel +
338 theme +
339 wrapLegend +
340 colors +
341 title
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000342
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700343# -------------------------------
344# Del Generating Bar Graph Format
345# -------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000346
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700347print( "Generating bar graph for Del graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000348
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700349sum <- fileData[ 'deltoconfrm' ] +
350 fileData[ 'elapsedel' ]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000351
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700352values <- geom_text( aes( x = delDataFrame$iterative,
353 y = sum + 0.03 * max( sum ),
354 label = format( sum,
355 digits = 3,
356 big.mark = ",",
357 scientific = FALSE ) ),
358 size = 7.0,
359 fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000360
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700361result <- fundamentalGraphData +
362 barGraphFormat +
363 title +
364 values
365
366# ---------------------------
367# Del Exporting Graph to File
368# ---------------------------
369
370print( paste( "Saving Del bar chart to", delOutputFile ) )
371
372ggsave( delOutputFile,
373 width = imageWidth,
374 height = imageHeight,
375 dpi = imageDPI )
376
Devin Lim0e967162017-11-03 15:59:53 -0700377print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", delOutputFile ) )