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( "**********************************************************" ) |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 30 | database_host = 1 |
| 31 | database_port = 2 |
| 32 | database_u_id = 3 |
| 33 | database_pw = 4 |
| 34 | test_name = 5 |
| 35 | branch_name = 6 |
| 36 | save_directory = 7 |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 37 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 38 | # Command line arguments are read. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 39 | print( "Reading commmand-line args." ) |
| 40 | args <- commandArgs( trailingOnly=TRUE ) |
| 41 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 42 | # ---------------- |
| 43 | # Import Libraries |
| 44 | # ---------------- |
| 45 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 46 | print( "Importing libraries." ) |
| 47 | library( ggplot2 ) |
| 48 | library( reshape2 ) |
| 49 | library( RPostgreSQL ) # For databases |
| 50 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 51 | # ------------------- |
| 52 | # Check CLI Arguments |
| 53 | # ------------------- |
| 54 | |
| 55 | print( "Verifying CLI args." ) |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 56 | if ( is.na( args[ save_directory ] ) ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 57 | print( paste( "Usage: Rscript SCPFmastershipFailoverLat", |
| 58 | "<database-host>", |
| 59 | "<database-port>", |
| 60 | "<database-user-id>", |
| 61 | "<database-password>", |
| 62 | "<test-name>", |
| 63 | "<branch-name>", |
| 64 | "<directory-to-save-graphs>", |
| 65 | sep=" " ) ) |
| 66 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 67 | quit( status = 1 ) # basically exit(), but in R |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 70 | # ----------------- |
| 71 | # Create File Names |
| 72 | # ----------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 73 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 74 | print( "Creating filenames and title of graph." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 75 | |
| 76 | chartTitle <- "Mastership Failover Latency" |
| 77 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 78 | errBarOutputFile <- paste( args[ save_directory ], |
| 79 | args[ test_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 80 | "_", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 81 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 82 | "_errGraph.jpg", |
| 83 | sep="" ) |
| 84 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 85 | stackedBarOutputFile <- paste( args[ save_directory ], |
| 86 | args[ test_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 87 | "_", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 88 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 89 | "_stackedGraph.jpg", |
| 90 | sep="" ) |
| 91 | |
| 92 | # ------------------ |
| 93 | # SQL Initialization |
| 94 | # ------------------ |
| 95 | |
| 96 | print( "Initializing SQL" ) |
| 97 | |
| 98 | con <- dbConnect( dbDriver( "PostgreSQL" ), |
| 99 | dbname = "onostest", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 100 | host = args[ database_host ], |
| 101 | port = strtoi( args[ database_port ] ), |
| 102 | user = args[ database_u_id ], |
| 103 | password = args[ database_pw ] ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 104 | |
| 105 | # --------------------------------------- |
| 106 | # Mastership Failover Latency SQL Command |
| 107 | # --------------------------------------- |
| 108 | |
| 109 | print( "Generating Mastership Failover Latency SQL command" ) |
| 110 | |
| 111 | command <- paste( "SELECT * FROM mastership_failover_tests WHERE branch = '", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 112 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 113 | "' AND date IN ( SELECT MAX( date ) FROM mastership_failover_tests WHERE branch = '", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 114 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 115 | "' ) ", |
| 116 | sep = "" ) |
| 117 | |
| 118 | print( "Sending SQL command:" ) |
| 119 | print( command ) |
| 120 | |
| 121 | fileData <- dbGetQuery( con, command ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 122 | |
| 123 | # ********************************************************** |
| 124 | # STEP 2: Organize data. |
| 125 | # ********************************************************** |
| 126 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 127 | print( "**********************************************************" ) |
| 128 | print( "STEP 2: Organize Data." ) |
| 129 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 130 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 131 | # ------------ |
| 132 | # Data Sorting |
| 133 | # ------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 134 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 135 | print( "Combining averages into a list." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 136 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 137 | requiredColumns <- c( "kill_deact_avg", "deact_role_avg" ) |
| 138 | |
| 139 | tryCatch( avgs <- c( fileData[ requiredColumns] ), |
| 140 | error = function( e ) { |
| 141 | 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." ) |
| 142 | print( "Required columns: " ) |
| 143 | print( requiredColumns ) |
| 144 | print( "Actual columns: " ) |
| 145 | print( names( fileData ) ) |
| 146 | print( "Error dump:" ) |
| 147 | print( e ) |
| 148 | quit( status = 1 ) |
| 149 | } |
| 150 | ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 151 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 152 | # -------------------- |
| 153 | # Construct Data Frame |
| 154 | # -------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 155 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 156 | print( "Constructing Data Frame from list." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 157 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 158 | dataFrame <- melt( avgs ) |
| 159 | dataFrame$scale <- fileData$scale |
| 160 | dataFrame$stds <- c( fileData$kill_deact_std, |
| 161 | fileData$deact_role_std ) |
| 162 | |
| 163 | colnames( dataFrame ) <- c( "ms", |
| 164 | "type", |
| 165 | "scale", |
| 166 | "stds" ) |
| 167 | |
| 168 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 169 | |
| 170 | sum <- fileData[ 'deact_role_avg' ] + |
| 171 | fileData[ 'kill_deact_avg' ] |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 172 | |
| 173 | print( "Data Frame Results:" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 174 | print( dataFrame ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 175 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 176 | |
| 177 | # ********************************************************** |
| 178 | # STEP 3: Generate graphs. |
| 179 | # ********************************************************** |
| 180 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 181 | print( "**********************************************************" ) |
| 182 | print( "STEP 3: Generate Graph." ) |
| 183 | print( "**********************************************************" ) |
| 184 | |
| 185 | # ------------------------------------ |
| 186 | # Initialize Variables for Both Graphs |
| 187 | # ------------------------------------ |
| 188 | |
| 189 | print( "Initializing variables used in both graphs." ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 190 | |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 191 | theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph. |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 192 | xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 193 | xLabel <- xlab( "Scale" ) |
| 194 | yLabel <- ylab( "Latency (ms)" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 195 | fillLabel <- labs( fill = "Type" ) |
| 196 | barWidth <- 0.9 |
| 197 | imageWidth <- 15 |
| 198 | imageHeight <- 10 |
| 199 | imageDPI <- 200 |
| 200 | |
| 201 | theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face='bold' ), |
| 202 | legend.position = "bottom", |
| 203 | legend.text = element_text( size=22 ), |
| 204 | legend.title = element_blank(), |
| 205 | legend.key.size = unit( 1.5, 'lines' ) ) |
| 206 | |
| 207 | barColors <- scale_fill_manual( values=c( "#F77670", |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 208 | "#619DFA" ) ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 209 | |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 210 | wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) ) |
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 | # Error Bar Graph Generate Main Plot |
| 214 | # ---------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 215 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 216 | print( "Creating main plot." ) |
| 217 | |
| 218 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, |
| 219 | y = ms, |
| 220 | ymin = ms, |
| 221 | ymax = ms + stds, |
| 222 | fill = type ) ) |
| 223 | |
| 224 | # ---------------------------------------------- |
| 225 | # Error Bar Graph Fundamental Variables Assigned |
| 226 | # ---------------------------------------------- |
| 227 | |
| 228 | print( "Generating fundamental graph data for the error bar graph." ) |
| 229 | |
| 230 | errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 ) |
| 231 | |
| 232 | title <- ggtitle( chartTitle ) |
| 233 | |
| 234 | fundamentalGraphData <- mainPlot + |
| 235 | xScaleConfig + |
| 236 | xLabel + |
| 237 | yLabel + |
| 238 | fillLabel + |
| 239 | theme + |
| 240 | title + |
| 241 | wrapLegend |
| 242 | |
| 243 | # ------------------------------------------- |
| 244 | # Error Bar Graph Generating Bar Graph Format |
| 245 | # ------------------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 246 | |
| 247 | print( "Generating bar graph with error bars." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 248 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 249 | barGraphFormat <- geom_bar( stat = "identity", |
| 250 | position = position_dodge(), |
| 251 | width = barWidth ) |
| 252 | |
| 253 | errorBarFormat <- geom_errorbar( width = barWidth, |
| 254 | position = position_dodge(), |
| 255 | color = errorBarColor ) |
| 256 | |
| 257 | values <- geom_text( aes( x = dataFrame$scale, |
| 258 | y = dataFrame$ms + 0.02 * max( dataFrame$ms ), |
| 259 | label = format( dataFrame$ms, |
| 260 | digits = 3, |
| 261 | big.mark = ",", |
| 262 | scientific = FALSE ) ), |
| 263 | size = 7.0, |
| 264 | fontface = "bold", |
| 265 | position = position_dodge( 0.9 ) ) |
| 266 | |
| 267 | result <- fundamentalGraphData + |
| 268 | barGraphFormat + |
| 269 | barColors + |
| 270 | errorBarFormat + |
| 271 | values |
| 272 | |
| 273 | # --------------------------------------- |
| 274 | # Error Bar Graph Exporting Graph to File |
| 275 | # --------------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 276 | |
| 277 | print( paste( "Saving bar chart with error bars to", errBarOutputFile ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 278 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 279 | tryCatch( ggsave( errBarOutputFile, |
| 280 | width = imageWidth, |
| 281 | height = imageHeight, |
| 282 | dpi = imageDPI ), |
| 283 | error = function( e ){ |
| 284 | print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" ) |
| 285 | print( e ) |
| 286 | quit( status = 1 ) |
| 287 | } |
| 288 | ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 289 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 290 | print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 291 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 292 | # ------------------------------------------------ |
| 293 | # Stacked Bar Graph Fundamental Variables Assigned |
| 294 | # ------------------------------------------------ |
| 295 | |
| 296 | print( "Generating fundamental graph data for the stacked bar graph." ) |
| 297 | |
| 298 | title <- ggtitle( chartTitle ) |
| 299 | |
| 300 | fundamentalGraphData <- mainPlot + |
| 301 | xScaleConfig + |
| 302 | xLabel + |
| 303 | yLabel + |
| 304 | fillLabel + |
| 305 | theme + |
| 306 | title + |
| 307 | wrapLegend |
| 308 | |
| 309 | # --------------------------------------------- |
| 310 | # Stacked Bar Graph Generating Bar Graph Format |
| 311 | # --------------------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 312 | |
| 313 | print( "Generating stacked bar chart." ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 314 | stackedBarFormat <- geom_bar( stat = "identity", |
| 315 | width = barWidth ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 316 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 317 | values <- geom_text( aes( x = dataFrame$scale, |
| 318 | y = sum + 0.02 * max( sum ), |
| 319 | label = format( sum, |
| 320 | digits = 3, |
| 321 | big.mark = ",", |
| 322 | scientific = FALSE ) ), |
| 323 | size = 7.0, |
| 324 | fontface = "bold" ) |
| 325 | |
| 326 | result <- fundamentalGraphData + |
| 327 | stackedBarFormat + |
| 328 | barColors + |
| 329 | title + |
| 330 | values |
| 331 | |
| 332 | # ----------------------------------------- |
| 333 | # Stacked Bar Graph Exporting Graph to File |
| 334 | # ----------------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 335 | |
| 336 | print( paste( "Saving stacked bar chart to", stackedBarOutputFile ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 337 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 338 | tryCatch( ggsave( stackedBarOutputFile, |
| 339 | width = imageWidth, |
| 340 | height = imageHeight, |
| 341 | dpi = imageDPI ), |
| 342 | error = function( e ){ |
| 343 | print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" ) |
| 344 | print( e ) |
| 345 | quit( status = 1 ) |
| 346 | } |
| 347 | ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 348 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 349 | print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", stackedBarOutputFile ) ) |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 350 | quit( status = 0 ) |