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 | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 67 | q() # basically exit(), but in R |
| 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 | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 137 | avgs <- c( fileData[ 'kill_deact_avg' ], |
| 138 | fileData[ 'deact_role_avg' ] ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 139 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 140 | # -------------------- |
| 141 | # Construct Data Frame |
| 142 | # -------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 143 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 144 | print( "Constructing Data Frame from list." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 145 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 146 | dataFrame <- melt( avgs ) |
| 147 | dataFrame$scale <- fileData$scale |
| 148 | dataFrame$stds <- c( fileData$kill_deact_std, |
| 149 | fileData$deact_role_std ) |
| 150 | |
| 151 | colnames( dataFrame ) <- c( "ms", |
| 152 | "type", |
| 153 | "scale", |
| 154 | "stds" ) |
| 155 | |
| 156 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 157 | |
| 158 | sum <- fileData[ 'deact_role_avg' ] + |
| 159 | fileData[ 'kill_deact_avg' ] |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 160 | |
| 161 | print( "Data Frame Results:" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 162 | print( dataFrame ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 163 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 164 | |
| 165 | # ********************************************************** |
| 166 | # STEP 3: Generate graphs. |
| 167 | # ********************************************************** |
| 168 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 169 | print( "**********************************************************" ) |
| 170 | print( "STEP 3: Generate Graph." ) |
| 171 | print( "**********************************************************" ) |
| 172 | |
| 173 | # ------------------------------------ |
| 174 | # Initialize Variables for Both Graphs |
| 175 | # ------------------------------------ |
| 176 | |
| 177 | print( "Initializing variables used in both graphs." ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 178 | |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 179 | 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] | 180 | xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 181 | xLabel <- xlab( "Scale" ) |
| 182 | yLabel <- ylab( "Latency (ms)" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 183 | fillLabel <- labs( fill = "Type" ) |
| 184 | barWidth <- 0.9 |
| 185 | imageWidth <- 15 |
| 186 | imageHeight <- 10 |
| 187 | imageDPI <- 200 |
| 188 | |
| 189 | theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face='bold' ), |
| 190 | legend.position = "bottom", |
| 191 | legend.text = element_text( size=22 ), |
| 192 | legend.title = element_blank(), |
| 193 | legend.key.size = unit( 1.5, 'lines' ) ) |
| 194 | |
| 195 | barColors <- scale_fill_manual( values=c( "#F77670", |
| 196 | "#619DFA" ) ) |
| 197 | |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 198 | wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 199 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 200 | # ---------------------------------- |
| 201 | # Error Bar Graph Generate Main Plot |
| 202 | # ---------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 203 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 204 | print( "Creating main plot." ) |
| 205 | |
| 206 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, |
| 207 | y = ms, |
| 208 | ymin = ms, |
| 209 | ymax = ms + stds, |
| 210 | fill = type ) ) |
| 211 | |
| 212 | # ---------------------------------------------- |
| 213 | # Error Bar Graph Fundamental Variables Assigned |
| 214 | # ---------------------------------------------- |
| 215 | |
| 216 | print( "Generating fundamental graph data for the error bar graph." ) |
| 217 | |
| 218 | errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 ) |
| 219 | |
| 220 | title <- ggtitle( chartTitle ) |
| 221 | |
| 222 | fundamentalGraphData <- mainPlot + |
| 223 | xScaleConfig + |
| 224 | xLabel + |
| 225 | yLabel + |
| 226 | fillLabel + |
| 227 | theme + |
| 228 | title + |
| 229 | wrapLegend |
| 230 | |
| 231 | # ------------------------------------------- |
| 232 | # Error Bar Graph Generating Bar Graph Format |
| 233 | # ------------------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 234 | |
| 235 | print( "Generating bar graph with error bars." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 236 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 237 | barGraphFormat <- geom_bar( stat = "identity", |
| 238 | position = position_dodge(), |
| 239 | width = barWidth ) |
| 240 | |
| 241 | errorBarFormat <- geom_errorbar( width = barWidth, |
| 242 | position = position_dodge(), |
| 243 | color = errorBarColor ) |
| 244 | |
| 245 | values <- geom_text( aes( x = dataFrame$scale, |
| 246 | y = dataFrame$ms + 0.02 * max( dataFrame$ms ), |
| 247 | label = format( dataFrame$ms, |
| 248 | digits = 3, |
| 249 | big.mark = ",", |
| 250 | scientific = FALSE ) ), |
| 251 | size = 7.0, |
| 252 | fontface = "bold", |
| 253 | position = position_dodge( 0.9 ) ) |
| 254 | |
| 255 | result <- fundamentalGraphData + |
| 256 | barGraphFormat + |
| 257 | barColors + |
| 258 | errorBarFormat + |
| 259 | values |
| 260 | |
| 261 | # --------------------------------------- |
| 262 | # Error Bar Graph Exporting Graph to File |
| 263 | # --------------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 264 | |
| 265 | print( paste( "Saving bar chart with error bars to", errBarOutputFile ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 266 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 267 | ggsave( errBarOutputFile, |
| 268 | width = imageWidth, |
| 269 | height = imageHeight, |
| 270 | dpi = imageDPI ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 271 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 272 | 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] | 273 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 274 | # ------------------------------------------------ |
| 275 | # Stacked Bar Graph Fundamental Variables Assigned |
| 276 | # ------------------------------------------------ |
| 277 | |
| 278 | print( "Generating fundamental graph data for the stacked bar graph." ) |
| 279 | |
| 280 | title <- ggtitle( chartTitle ) |
| 281 | |
| 282 | fundamentalGraphData <- mainPlot + |
| 283 | xScaleConfig + |
| 284 | xLabel + |
| 285 | yLabel + |
| 286 | fillLabel + |
| 287 | theme + |
| 288 | title + |
| 289 | wrapLegend |
| 290 | |
| 291 | # --------------------------------------------- |
| 292 | # Stacked Bar Graph Generating Bar Graph Format |
| 293 | # --------------------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 294 | |
| 295 | print( "Generating stacked bar chart." ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 296 | stackedBarFormat <- geom_bar( stat = "identity", |
| 297 | width = barWidth ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 298 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 299 | values <- geom_text( aes( x = dataFrame$scale, |
| 300 | y = sum + 0.02 * max( sum ), |
| 301 | label = format( sum, |
| 302 | digits = 3, |
| 303 | big.mark = ",", |
| 304 | scientific = FALSE ) ), |
| 305 | size = 7.0, |
| 306 | fontface = "bold" ) |
| 307 | |
| 308 | result <- fundamentalGraphData + |
| 309 | stackedBarFormat + |
| 310 | barColors + |
| 311 | title + |
| 312 | values |
| 313 | |
| 314 | # ----------------------------------------- |
| 315 | # Stacked Bar Graph Exporting Graph to File |
| 316 | # ----------------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 317 | |
| 318 | print( paste( "Saving stacked bar chart to", stackedBarOutputFile ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 319 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 320 | ggsave( stackedBarOutputFile, |
| 321 | width = imageWidth, |
| 322 | height = imageHeight, |
| 323 | dpi = imageDPI ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 324 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 325 | print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", stackedBarOutputFile ) ) |