Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 1 | # 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 Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 21 | # please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 22 | |
| 23 | # ********************************************************** |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 24 | # STEP 1: Data management. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 25 | # ********************************************************** |
| 26 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 27 | print( "**********************************************************" ) |
| 28 | print( "STEP 1: Data management." ) |
| 29 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 30 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 31 | # Command line arguments are read. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 32 | print( "Reading commmand-line args." ) |
| 33 | args <- commandArgs( trailingOnly=TRUE ) |
| 34 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 35 | # ---------------- |
| 36 | # Import Libraries |
| 37 | # ---------------- |
| 38 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 39 | print( "Importing libraries." ) |
| 40 | library( ggplot2 ) |
| 41 | library( reshape2 ) |
| 42 | library( RPostgreSQL ) # For databases |
| 43 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 44 | # ------------------- |
| 45 | # Check CLI Arguments |
| 46 | # ------------------- |
| 47 | |
| 48 | print( "Verifying CLI args." ) |
| 49 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 50 | if ( is.na( args[ 9 ] ) ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 51 | |
| 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 Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 64 | q() # basically exit(), but in R |
| 65 | } |
| 66 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 67 | # ----------------------------------- |
| 68 | # Create File Name and Title of Graph |
| 69 | # ----------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 70 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 71 | print( "Creating filename and title of graph." ) |
| 72 | |
| 73 | chartTitle <- "Intent Install, Withdraw, & Reroute Latencies" |
| 74 | flowObjFileModifier <- "" |
| 75 | errBarOutputFile <- paste( args[ 9 ], |
| 76 | "SCPFIntentInstallWithdrawRerouteLat_", |
| 77 | args[ 7 ], |
| 78 | sep="" ) |
| 79 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 80 | if ( args[ 1 ] == "y" ){ |
| 81 | errBarOutputFile <- paste( errBarOutputFile, "_fobj", sep="" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 82 | flowObjFileModifier <- "fobj_" |
| 83 | chartTitle <- paste( chartTitle, "w/ FlowObj" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 84 | } |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 85 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 86 | errBarOutputFile <- paste( errBarOutputFile, |
| 87 | "_", |
| 88 | args[ 8 ], |
| 89 | "-batchSize_graph.jpg", |
| 90 | sep="" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 91 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 92 | chartTitle <- paste( chartTitle, |
| 93 | "\nBatch Size =", |
| 94 | args[ 8 ], |
| 95 | sep=" " ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 96 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 97 | # ------------------ |
| 98 | # SQL Initialization |
| 99 | # ------------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 100 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 101 | print( "Initializing SQL" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 102 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 103 | con <- dbConnect( dbDriver( "PostgreSQL" ), |
| 104 | dbname = "onostest", |
| 105 | host = args[ 2 ], |
| 106 | port = strtoi( args[ 3 ] ), |
| 107 | user = args[ 4 ], |
| 108 | password = args[ 5 ] ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 109 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 110 | # --------------------------------------- |
| 111 | # Intent Install and Withdraw SQL Command |
| 112 | # --------------------------------------- |
| 113 | print( "Generating Intent Install and Withdraw SQL Command" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 114 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 115 | installWithdrawSQLCommand <- 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 Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 127 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 128 | print( "Sending Intent Install and Withdraw SQL command:" ) |
| 129 | print( installWithdrawSQLCommand ) |
| 130 | installWithdrawData <- dbGetQuery( con, installWithdrawSQLCommand ) |
| 131 | |
| 132 | # -------------------------- |
| 133 | # Intent Reroute SQL Command |
| 134 | # -------------------------- |
| 135 | |
| 136 | print( "Generating Intent Reroute SQL Command" ) |
| 137 | |
| 138 | rerouteSQLCommand <- 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 | |
| 151 | print( "Sending Intent Reroute SQL command:" ) |
| 152 | print( rerouteSQLCommand ) |
| 153 | rerouteData <- dbGetQuery( con, rerouteSQLCommand ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 154 | |
| 155 | # ********************************************************** |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 156 | # STEP 2: Organize Data. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 157 | # ********************************************************** |
| 158 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 159 | print( "**********************************************************" ) |
| 160 | print( "STEP 2: Organize Data." ) |
| 161 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 162 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 163 | # ------------------------------------------------------- |
| 164 | # Combining Install, Withdraw, and Reroute Latencies Data |
| 165 | # ------------------------------------------------------- |
| 166 | |
| 167 | print( "Combining Install, Withdraw, and Reroute Latencies Data" ) |
| 168 | |
| 169 | if ( 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 Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 172 | } else{ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 173 | 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 Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 188 | # Combine lists into data frames. |
| 189 | dataFrame <- melt( avgs ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 190 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 191 | # -------------------- |
| 192 | # Construct Data Frame |
| 193 | # -------------------- |
| 194 | |
| 195 | print( "Constructing data frame." ) |
| 196 | |
| 197 | if ( 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 Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 203 | } else{ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 204 | 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 Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 211 | } |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 212 | |
| 213 | colnames( dataFrame ) <- c( "ms", |
| 214 | "type", |
| 215 | "scale", |
| 216 | "stds" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 217 | |
| 218 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 219 | dataFrame$type <- as.character( dataFrame$type ) |
| 220 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 221 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 222 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 223 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 224 | print( "Data Frame Results:" ) |
| 225 | print( dataFrame ) |
| 226 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 227 | # ********************************************************** |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 228 | # STEP 3: Generate graph. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 229 | # ********************************************************** |
| 230 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 231 | print( "**********************************************************" ) |
| 232 | print( "STEP 3: Generate Graph." ) |
| 233 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 234 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 235 | # ------------------- |
| 236 | # Main Plot Generated |
| 237 | # ------------------- |
| 238 | |
| 239 | print( "Creating the main plot." ) |
| 240 | |
| 241 | mainPlot <- 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 Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 250 | |
| 251 | print( "Generating fundamental graph data." ) |
| 252 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 253 | theme_set( theme_grey( base_size = 22 ) ) |
| 254 | barWidth <- 1.3 |
| 255 | xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 256 | xLabel <- xlab( "Scale" ) |
| 257 | yLabel <- ylab( "Latency (ms)" ) |
| 258 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 259 | title <- ggtitle( chartTitle ) |
| 260 | imageWidth <- 15 |
| 261 | imageHeight <- 10 |
| 262 | imageDPI <- 200 |
| 263 | errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 264 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 265 | theme <- 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 | |
| 271 | colors <- scale_fill_manual( values=c( "#F77670", |
| 272 | "#619DFA", |
| 273 | "#18BA48" ) ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 274 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 275 | # Store plot configurations as 1 variable |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 276 | fundamentalGraphData <- mainPlot + |
| 277 | xScaleConfig + |
| 278 | xLabel + |
| 279 | yLabel + |
| 280 | fillLabel + |
| 281 | theme + |
| 282 | title + |
| 283 | colors |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 284 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 285 | # --------------------------- |
| 286 | # Generating Bar Graph Format |
| 287 | # --------------------------- |
| 288 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 289 | print( "Generating bar graph with error bars." ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 290 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 291 | barGraphFormat <- geom_bar( stat = "identity", |
| 292 | width = barWidth, |
| 293 | position = "dodge" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 294 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 295 | errorBarFormat <- geom_errorbar( width = barWidth, |
| 296 | position = position_dodge( barWidth ), |
| 297 | color = errorBarColor ) |
| 298 | |
| 299 | values <- 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 | |
| 309 | wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) ) |
| 310 | |
| 311 | result <- fundamentalGraphData + |
| 312 | barGraphFormat + |
| 313 | errorBarFormat + |
| 314 | values + |
| 315 | wrapLegend |
| 316 | |
| 317 | # ----------------------- |
| 318 | # Exporting Graph to File |
| 319 | # ----------------------- |
| 320 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 321 | print( paste( "Saving bar chart with error bars to", errBarOutputFile ) ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 322 | |
| 323 | ggsave( errBarOutputFile, |
| 324 | width = imageWidth, |
| 325 | height = imageHeight, |
| 326 | dpi = imageDPI ) |
| 327 | |
| 328 | print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) ) |