blob: 93e9e00a3f43d7c6132adc11a359614f508db047 [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# **********************************************************
26
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070027print( "**********************************************************" )
28print( "STEP 1: Data management." )
29print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000030
Jeremy Ronquillob6268842017-10-03 13:02:58 -070031# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000032print( "Reading commmand-line args." )
33args <- commandArgs( trailingOnly=TRUE )
34
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070035# ----------------
36# Import Libraries
37# ----------------
38
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000039print( "Importing libraries." )
40library( ggplot2 )
41library( reshape2 )
42library( RPostgreSQL ) # For databases
43
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070044# -------------------
45# Check CLI Arguments
46# -------------------
47
48print( "Verifying CLI args." )
49
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000050if ( is.na( args[ 9 ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070051
52 print( paste( "Usage: Rscript SCPFIntentInstallWithdrawRerouteLat.R",
53 "<isFlowObj>" ,
54 "<database-host>",
55 "<database-port>",
56 "<database-user-id>",
57 "<database-password>",
58 "<test-name>",
59 "<branch-name>",
60 "<batch-size>",
61 "<directory-to-save-graphs>",
62 sep=" " ) )
63
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000064 q() # basically exit(), but in R
65}
66
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070067# -----------------------------------
68# Create File Name and Title of Graph
69# -----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000070
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070071print( "Creating filename and title of graph." )
72
73chartTitle <- "Intent Install, Withdraw, & Reroute Latencies"
74flowObjFileModifier <- ""
75errBarOutputFile <- paste( args[ 9 ],
76 "SCPFIntentInstallWithdrawRerouteLat_",
77 args[ 7 ],
78 sep="" )
79
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000080if ( args[ 1 ] == "y" ){
81 errBarOutputFile <- paste( errBarOutputFile, "_fobj", sep="" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070082 flowObjFileModifier <- "fobj_"
83 chartTitle <- paste( chartTitle, "w/ FlowObj" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000084}
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000085
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070086errBarOutputFile <- paste( errBarOutputFile,
87 "_",
88 args[ 8 ],
89 "-batchSize_graph.jpg",
90 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000091
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070092chartTitle <- paste( chartTitle,
93 "\nBatch Size =",
94 args[ 8 ],
95 sep=" " )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000096
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070097# ------------------
98# SQL Initialization
99# ------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000100
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700101print( "Initializing SQL" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000102
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700103con <- dbConnect( dbDriver( "PostgreSQL" ),
104 dbname = "onostest",
105 host = args[ 2 ],
106 port = strtoi( args[ 3 ] ),
107 user = args[ 4 ],
108 password = args[ 5 ] )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000109
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700110# ---------------------------------------
111# Intent Install and Withdraw SQL Command
112# ---------------------------------------
113print( "Generating Intent Install and Withdraw SQL Command" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000114
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700115installWithdrawSQLCommand <- paste( "SELECT * FROM intent_latency_",
116 flowObjFileModifier,
117 "tests WHERE batch_size=",
118 args[ 8 ],
119 " AND branch = '",
120 args[ 7 ],
121 "' AND date IN ( SELECT MAX( date ) FROM intent_latency_",
122 flowObjFileModifier,
123 "tests WHERE branch='",
124 args[ 7 ],
125 "')",
126 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000127
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700128print( "Sending Intent Install and Withdraw SQL command:" )
129print( installWithdrawSQLCommand )
130installWithdrawData <- dbGetQuery( con, installWithdrawSQLCommand )
131
132# --------------------------
133# Intent Reroute SQL Command
134# --------------------------
135
136print( "Generating Intent Reroute SQL Command" )
137
138rerouteSQLCommand <- paste( "SELECT * FROM intent_reroute_latency_",
139 flowObjFileModifier,
140 "tests WHERE batch_size=",
141 args[ 8 ],
142 " AND branch = '",
143 args[ 7 ],
144 "' AND date IN ( SELECT MAX( date ) FROM intent_reroute_latency_",
145 flowObjFileModifier,
146 "tests WHERE branch='",
147 args[ 7 ],
148 "')",
149 sep="" )
150
151print( "Sending Intent Reroute SQL command:" )
152print( rerouteSQLCommand )
153rerouteData <- dbGetQuery( con, rerouteSQLCommand )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000154
155# **********************************************************
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700156# STEP 2: Organize Data.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000157# **********************************************************
158
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700159print( "**********************************************************" )
160print( "STEP 2: Organize Data." )
161print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000162
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700163# -------------------------------------------------------
164# Combining Install, Withdraw, and Reroute Latencies Data
165# -------------------------------------------------------
166
167print( "Combining Install, Withdraw, and Reroute Latencies Data" )
168
169if ( ncol( rerouteData ) == 0 ){ # Checks if rerouteData exists, so we can exclude it if necessary
170 avgs <- c( installWithdrawData[ 'install_avg' ],
171 installWithdrawData[ 'withdraw_avg' ] )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000172} else{
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700173 colnames( rerouteData ) <- c( "date",
174 "name",
175 "date",
176 "branch",
177 "commit",
178 "scale",
179 "batch_size",
180 "reroute_avg",
181 "reroute_std" )
182
183 avgs <- c( installWithdrawData[ 'install_avg' ],
184 installWithdrawData[ 'withdraw_avg' ],
185 rerouteData[ 'reroute_avg' ] )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000186}
187
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700188# Combine lists into data frames.
189dataFrame <- melt( avgs )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000190
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700191# --------------------
192# Construct Data Frame
193# --------------------
194
195print( "Constructing data frame." )
196
197if ( ncol( rerouteData ) == 0 ){ # Checks if rerouteData exists (due to batch size) for the dataFrame this time
198 dataFrame$scale <- c( installWithdrawData$scale,
199 installWithdrawData$scale )
200
201 dataFrame$stds <- c( installWithdrawData$install_std,
202 installWithdrawData$withdraw_std )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000203} else{
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700204 dataFrame$scale <- c( installWithdrawData$scale,
205 installWithdrawData$scale,
206 rerouteData$scale )
207
208 dataFrame$stds <- c( installWithdrawData$install_std,
209 installWithdrawData$withdraw_std,
210 rerouteData$reroute_std )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000211}
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700212
213colnames( dataFrame ) <- c( "ms",
214 "type",
215 "scale",
216 "stds" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000217
218# Format data frame so that the data is in the same order as it appeared in the file.
219dataFrame$type <- as.character( dataFrame$type )
220dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
221
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700222dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700223
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700224print( "Data Frame Results:" )
225print( dataFrame )
226
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000227# **********************************************************
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700228# STEP 3: Generate graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000229# **********************************************************
230
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700231print( "**********************************************************" )
232print( "STEP 3: Generate Graph." )
233print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000234
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700235# -------------------
236# Main Plot Generated
237# -------------------
238
239print( "Creating the main plot." )
240
241mainPlot <- ggplot( data = dataFrame, aes( x = scale,
242 y = ms,
243 ymin = ms,
244 ymax = ms + stds,
245 fill = type ) )
246
247# ------------------------------
248# Fundamental Variables Assigned
249# ------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000250
251print( "Generating fundamental graph data." )
252
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700253theme_set( theme_grey( base_size = 22 ) )
254barWidth <- 1.3
255xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000256xLabel <- xlab( "Scale" )
257yLabel <- ylab( "Latency (ms)" )
258fillLabel <- labs( fill="Type" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700259title <- ggtitle( chartTitle )
260imageWidth <- 15
261imageHeight <- 10
262imageDPI <- 200
263errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000264
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700265theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ),
266 legend.position="bottom",
267 legend.text=element_text( size=22 ),
268 legend.title = element_blank(),
269 legend.key.size = unit( 1.5, 'lines' ) )
270
271colors <- scale_fill_manual( values=c( "#F77670",
272 "#619DFA",
273 "#18BA48" ) )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700274
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000275# Store plot configurations as 1 variable
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700276fundamentalGraphData <- mainPlot +
277 xScaleConfig +
278 xLabel +
279 yLabel +
280 fillLabel +
281 theme +
282 title +
283 colors
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000284
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700285# ---------------------------
286# Generating Bar Graph Format
287# ---------------------------
288
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000289print( "Generating bar graph with error bars." )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700290
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700291barGraphFormat <- geom_bar( stat = "identity",
292 width = barWidth,
293 position = "dodge" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000294
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700295errorBarFormat <- geom_errorbar( width = barWidth,
296 position = position_dodge( barWidth ),
297 color = errorBarColor )
298
299values <- geom_text( aes( x = dataFrame$scale,
300 y = dataFrame$ms + 0.035 * max( dataFrame$ms ),
301 label = format( dataFrame$ms,
302 digits = 3,
303 big.mark = ",",
304 scientific = FALSE ) ),
305 position = position_dodge( width = barWidth ),
306 size = 5.5,
307 fontface = "bold" )
308
309wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) )
310
311result <- fundamentalGraphData +
312 barGraphFormat +
313 errorBarFormat +
314 values +
315 wrapLegend
316
317# -----------------------
318# Exporting Graph to File
319# -----------------------
320
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000321print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700322
323ggsave( errBarOutputFile,
324 width = imageWidth,
325 height = imageHeight,
326 dpi = imageDPI )
327
328print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) )