Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [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, |
| 21 | # please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu |
| 22 | # |
| 23 | # Example script: |
| 24 | # Single Bench Flow Latency Graph with Eventually Consistent Flow Rule Store (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFbatchFlowResp_master_OldFlow_PostGraph.jpg): |
| 25 | # Rscript SCPFbatchFlowResp.R <url> <port> <username> <pass> SCPFbatchFlowResp.R master y /path/to/save/directory/ |
| 26 | |
| 27 | # ********************************************************** |
| 28 | # STEP 1: Data management. |
| 29 | # ********************************************************** |
| 30 | |
| 31 | old_flow <- 7 |
| 32 | save_directory <- 8 |
| 33 | |
| 34 | print( "**********************************************************" ) |
| 35 | print( "STEP 1: Data management." ) |
| 36 | print( "**********************************************************" ) |
| 37 | |
| 38 | # Command line arguments are read. |
| 39 | print( "Reading commmand-line args." ) |
| 40 | args <- commandArgs( trailingOnly=TRUE ) |
| 41 | |
| 42 | # ---------------- |
| 43 | # Import Libraries |
| 44 | # ---------------- |
| 45 | |
| 46 | print( "Importing libraries." ) |
| 47 | library( ggplot2 ) |
| 48 | library( reshape2 ) |
| 49 | library( RPostgreSQL ) # For databases |
Devin Lim | 324806b | 2018-05-11 15:36:52 -0700 | [diff] [blame] | 50 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" ) |
| 51 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" ) |
| 52 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" ) |
| 53 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 54 | |
| 55 | # ------------------- |
| 56 | # Check CLI Arguments |
| 57 | # ------------------- |
| 58 | |
| 59 | print( "Verifying CLI args." ) |
| 60 | |
| 61 | if ( length( args ) != save_directory ){ |
| 62 | usage( "SCPFbatchFlowResp.R", c( "using-old-flow" ) ) |
| 63 | quit( status = 1 ) |
| 64 | } |
| 65 | |
| 66 | # ----------------- |
| 67 | # Create File Names |
| 68 | # ----------------- |
| 69 | |
| 70 | print( "Creating filenames and title of graph." ) |
| 71 | |
| 72 | postOutputFile <- paste( args[ save_directory ], |
| 73 | args[ graph_title ], |
| 74 | "_", |
| 75 | args[ branch_name ], |
| 76 | if( args[ old_flow ] == "y" ) "_OldFlow" else "", |
| 77 | "_PostGraph.jpg", |
| 78 | sep="" ) |
| 79 | |
| 80 | delOutputFile <- paste( args[ save_directory ], |
| 81 | args[ graph_title ], |
| 82 | "_", |
| 83 | args[ branch_name ], |
| 84 | if( args[ old_flow ] == "y" ) "_OldFlow" else "", |
| 85 | "_DelGraph.jpg", |
| 86 | sep="" ) |
| 87 | |
| 88 | postChartTitle <- paste( "Single Bench Flow Latency - Post\n", |
| 89 | "Last 3 Builds", |
| 90 | if( args[ old_flow ] == "y" ) "\nWith Eventually Consistent Flow Rule Store" else "", |
| 91 | sep = "" ) |
| 92 | delChartTitle <- paste( "Single Bench Flow Latency - Del\n", |
| 93 | "Last 3 Builds", |
| 94 | if( args[ old_flow ] == "y" ) "\nWith Eventually Consistent Flow Rule Store" else "", |
| 95 | sep = "" ) |
| 96 | |
| 97 | # ------------------ |
| 98 | # SQL Initialization |
| 99 | # ------------------ |
| 100 | |
| 101 | print( "Initializing SQL" ) |
| 102 | |
| 103 | con <- initSQL( args[ database_host ], |
| 104 | args[ database_port ], |
| 105 | args[ database_u_id ], |
| 106 | args[ database_pw ] ) |
| 107 | |
| 108 | # --------------------------- |
| 109 | # Batch Flow Resp SQL Command |
| 110 | # --------------------------- |
| 111 | |
| 112 | print( "Generating Batch Flow Resp SQL Command" ) |
| 113 | |
| 114 | command <- paste( "SELECT * FROM batch_flow_tests WHERE branch='", |
| 115 | args[ branch_name ], |
| 116 | "' AND " , |
| 117 | ( if( args[ old_flow ] == 'y' ) "" else "NOT " ) , |
| 118 | "is_old_flow", |
| 119 | " ORDER BY date DESC LIMIT 3", |
| 120 | sep="" ) |
| 121 | |
| 122 | fileData <- retrieveData( con, command ) |
| 123 | |
| 124 | # ********************************************************** |
| 125 | # STEP 2: Organize data. |
| 126 | # ********************************************************** |
| 127 | |
| 128 | print( "**********************************************************" ) |
| 129 | print( "STEP 2: Organize Data." ) |
| 130 | print( "**********************************************************" ) |
| 131 | |
| 132 | # ----------------- |
| 133 | # Post Data Sorting |
| 134 | # ----------------- |
| 135 | |
| 136 | print( "Sorting data for Post." ) |
| 137 | |
| 138 | requiredColumns <- c( "posttoconfrm", "elapsepost" ) |
| 139 | |
| 140 | tryCatch( postAvgs <- c( fileData[ requiredColumns] ), |
| 141 | error = function( e ) { |
| 142 | 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." ) |
| 143 | print( "Required columns: " ) |
| 144 | print( requiredColumns ) |
| 145 | print( "Actual columns: " ) |
| 146 | print( names( fileData ) ) |
| 147 | print( "Error dump:" ) |
| 148 | print( e ) |
| 149 | quit( status = 1 ) |
| 150 | } |
| 151 | ) |
| 152 | |
| 153 | # ------------------------- |
| 154 | # Post Construct Data Frame |
| 155 | # ------------------------- |
| 156 | |
| 157 | postDataFrame <- melt( postAvgs ) |
| 158 | postDataFrame$scale <- fileData$scale |
| 159 | postDataFrame$date <- fileData$date |
| 160 | postDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) ) |
| 161 | |
| 162 | colnames( postDataFrame ) <- c( "ms", |
| 163 | "type", |
| 164 | "scale", |
| 165 | "date", |
| 166 | "iterative" ) |
| 167 | |
| 168 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 169 | postDataFrame$type <- as.character( postDataFrame$type ) |
| 170 | postDataFrame$type <- factor( postDataFrame$type, |
| 171 | levels = unique( postDataFrame$type ) ) |
| 172 | |
| 173 | postDataFrame <- na.omit( postDataFrame ) # Omit any data that doesn't exist |
| 174 | |
| 175 | print( "Post Data Frame Results:" ) |
| 176 | print( postDataFrame ) |
| 177 | |
| 178 | # ---------------- |
| 179 | # Del Data Sorting |
| 180 | # ---------------- |
| 181 | |
| 182 | requiredColumns <- c( "deltoconfrm", "elapsedel" ) |
| 183 | |
| 184 | tryCatch( delAvgs <- c( fileData[ requiredColumns] ), |
| 185 | error = function( e ) { |
| 186 | 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." ) |
| 187 | print( "Required columns: " ) |
| 188 | print( requiredColumns ) |
| 189 | print( "Actual columns: " ) |
| 190 | print( names( fileData ) ) |
| 191 | print( "Error dump:" ) |
| 192 | print( e ) |
| 193 | quit( status = 1 ) |
| 194 | } |
| 195 | ) |
| 196 | |
| 197 | |
| 198 | # ------------------------ |
| 199 | # Del Construct Data Frame |
| 200 | # ------------------------ |
| 201 | |
| 202 | delDataFrame <- melt( delAvgs ) |
| 203 | delDataFrame$scale <- fileData$scale |
| 204 | delDataFrame$date <- fileData$date |
| 205 | delDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) ) |
| 206 | |
| 207 | colnames( delDataFrame ) <- c( "ms", |
| 208 | "type", |
| 209 | "scale", |
| 210 | "date", |
| 211 | "iterative" ) |
| 212 | |
| 213 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 214 | delDataFrame$type <- as.character( delDataFrame$type ) |
| 215 | delDataFrame$type <- factor( delDataFrame$type, |
| 216 | levels = unique( delDataFrame$type ) ) |
| 217 | |
| 218 | delDataFrame <- na.omit( delDataFrame ) # Omit any data that doesn't exist |
| 219 | |
| 220 | print( "Del Data Frame Results:" ) |
| 221 | print( delDataFrame ) |
| 222 | |
| 223 | # ********************************************************** |
| 224 | # STEP 3: Generate graphs. |
| 225 | # ********************************************************** |
| 226 | |
| 227 | print( "**********************************************************" ) |
| 228 | print( "STEP 3: Generate Graph." ) |
| 229 | print( "**********************************************************" ) |
| 230 | |
| 231 | # ------------------------------------------ |
| 232 | # Initializing variables used in both graphs |
| 233 | # ------------------------------------------ |
| 234 | |
| 235 | print( "Initializing variables used in both graphs." ) |
| 236 | |
| 237 | defaultTextSize() |
| 238 | xLabel <- xlab( "Build Date" ) |
| 239 | yLabel <- ylab( "Latency (ms)" ) |
| 240 | fillLabel <- labs( fill="Type" ) |
| 241 | |
| 242 | colors <- scale_fill_manual( values=c( webColor( "redv2" ), |
| 243 | webColor( "light_blue" ) ) ) |
| 244 | |
| 245 | wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) ) |
| 246 | |
| 247 | barWidth <- 0.3 |
| 248 | |
| 249 | theme <- graphTheme() |
| 250 | |
| 251 | barGraphFormat <- geom_bar( stat = "identity", |
| 252 | width = barWidth ) |
| 253 | |
| 254 | # ----------------------- |
| 255 | # Post Generate Main Plot |
| 256 | # ----------------------- |
| 257 | |
| 258 | print( "Creating main plot for Post graph." ) |
| 259 | |
| 260 | mainPlot <- ggplot( data = postDataFrame, aes( x = iterative, |
| 261 | y = ms, |
| 262 | fill = type ) ) |
| 263 | |
| 264 | # ----------------------------------- |
| 265 | # Post Fundamental Variables Assigned |
| 266 | # ----------------------------------- |
| 267 | |
| 268 | print( "Generating fundamental graph data for Post graph." ) |
| 269 | |
| 270 | xScaleConfig <- scale_x_continuous( breaks = postDataFrame$iterative, |
| 271 | label = postDataFrame$date ) |
| 272 | |
| 273 | title <- labs( title = postChartTitle, subtitle = lastUpdatedLabel() ) |
| 274 | |
| 275 | fundamentalGraphData <- mainPlot + |
| 276 | xScaleConfig + |
| 277 | xLabel + |
| 278 | yLabel + |
| 279 | fillLabel + |
| 280 | theme + |
| 281 | wrapLegend + |
| 282 | colors + |
| 283 | title |
| 284 | |
| 285 | # -------------------------------- |
| 286 | # Post Generating Bar Graph Format |
| 287 | # -------------------------------- |
| 288 | |
| 289 | print( "Generating bar graph for Post graph." ) |
| 290 | |
| 291 | sum <- fileData[ 'posttoconfrm' ] + |
| 292 | fileData[ 'elapsepost' ] |
| 293 | |
| 294 | values <- geom_text( aes( x = postDataFrame$iterative, |
| 295 | y = sum + 0.03 * max( sum ), |
| 296 | label = format( sum, |
| 297 | digits = 3, |
| 298 | big.mark = ",", |
| 299 | scientific = FALSE ) ), |
| 300 | size = 7.0, |
| 301 | fontface = "bold" ) |
| 302 | |
| 303 | result <- fundamentalGraphData + |
| 304 | barGraphFormat + |
| 305 | values |
| 306 | |
| 307 | # ---------------------------- |
| 308 | # Post Exporting Graph to File |
| 309 | # ---------------------------- |
| 310 | |
| 311 | saveGraph( postOutputFile ) |
| 312 | |
| 313 | # ---------------------- |
| 314 | # Del Generate Main Plot |
| 315 | # ---------------------- |
| 316 | |
| 317 | print( "Creating main plot for Del graph." ) |
| 318 | |
| 319 | mainPlot <- ggplot( data = delDataFrame, aes( x = iterative, |
| 320 | y = ms, |
| 321 | fill = type ) ) |
| 322 | |
| 323 | # ---------------------------------- |
| 324 | # Del Fundamental Variables Assigned |
| 325 | # ---------------------------------- |
| 326 | |
| 327 | print( "Generating fundamental graph data for Del graph." ) |
| 328 | |
| 329 | xScaleConfig <- scale_x_continuous( breaks = delDataFrame$iterative, |
| 330 | label = delDataFrame$date ) |
| 331 | |
| 332 | title <- labs( title = delChartTitle, subtitle = lastUpdatedLabel() ) |
| 333 | |
| 334 | fundamentalGraphData <- mainPlot + |
| 335 | xScaleConfig + |
| 336 | xLabel + |
| 337 | yLabel + |
| 338 | fillLabel + |
| 339 | theme + |
| 340 | wrapLegend + |
| 341 | colors + |
| 342 | title |
| 343 | |
| 344 | # ------------------------------- |
| 345 | # Del Generating Bar Graph Format |
| 346 | # ------------------------------- |
| 347 | |
| 348 | print( "Generating bar graph for Del graph." ) |
| 349 | |
| 350 | sum <- fileData[ 'deltoconfrm' ] + |
| 351 | fileData[ 'elapsedel' ] |
| 352 | |
| 353 | values <- geom_text( aes( x = delDataFrame$iterative, |
| 354 | y = sum + 0.03 * max( sum ), |
| 355 | label = format( sum, |
| 356 | digits = 3, |
| 357 | big.mark = ",", |
| 358 | scientific = FALSE ) ), |
| 359 | size = 7.0, |
| 360 | fontface = "bold" ) |
| 361 | |
| 362 | result <- fundamentalGraphData + |
| 363 | barGraphFormat + |
| 364 | title + |
| 365 | values |
| 366 | |
| 367 | # --------------------------- |
| 368 | # Del Exporting Graph to File |
| 369 | # --------------------------- |
| 370 | |
| 371 | saveGraph( delOutputFile ) |
| 372 | quit( status = 0 ) |