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 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 132 | latestBuildDate <- fileData$date[1] |
| 133 | |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 134 | # ----------------- |
| 135 | # Post Data Sorting |
| 136 | # ----------------- |
| 137 | |
| 138 | print( "Sorting data for Post." ) |
| 139 | |
| 140 | requiredColumns <- c( "posttoconfrm", "elapsepost" ) |
| 141 | |
| 142 | tryCatch( postAvgs <- c( fileData[ requiredColumns] ), |
| 143 | error = function( e ) { |
| 144 | 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." ) |
| 145 | print( "Required columns: " ) |
| 146 | print( requiredColumns ) |
| 147 | print( "Actual columns: " ) |
| 148 | print( names( fileData ) ) |
| 149 | print( "Error dump:" ) |
| 150 | print( e ) |
| 151 | quit( status = 1 ) |
| 152 | } |
| 153 | ) |
| 154 | |
| 155 | # ------------------------- |
| 156 | # Post Construct Data Frame |
| 157 | # ------------------------- |
| 158 | |
| 159 | postDataFrame <- melt( postAvgs ) |
| 160 | postDataFrame$scale <- fileData$scale |
| 161 | postDataFrame$date <- fileData$date |
| 162 | postDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) ) |
| 163 | |
| 164 | colnames( postDataFrame ) <- c( "ms", |
| 165 | "type", |
| 166 | "scale", |
| 167 | "date", |
| 168 | "iterative" ) |
| 169 | |
| 170 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 171 | postDataFrame$type <- as.character( postDataFrame$type ) |
| 172 | postDataFrame$type <- factor( postDataFrame$type, |
| 173 | levels = unique( postDataFrame$type ) ) |
| 174 | |
| 175 | postDataFrame <- na.omit( postDataFrame ) # Omit any data that doesn't exist |
| 176 | |
| 177 | print( "Post Data Frame Results:" ) |
| 178 | print( postDataFrame ) |
| 179 | |
| 180 | # ---------------- |
| 181 | # Del Data Sorting |
| 182 | # ---------------- |
| 183 | |
| 184 | requiredColumns <- c( "deltoconfrm", "elapsedel" ) |
| 185 | |
| 186 | tryCatch( delAvgs <- c( fileData[ requiredColumns] ), |
| 187 | error = function( e ) { |
| 188 | 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." ) |
| 189 | print( "Required columns: " ) |
| 190 | print( requiredColumns ) |
| 191 | print( "Actual columns: " ) |
| 192 | print( names( fileData ) ) |
| 193 | print( "Error dump:" ) |
| 194 | print( e ) |
| 195 | quit( status = 1 ) |
| 196 | } |
| 197 | ) |
| 198 | |
| 199 | |
| 200 | # ------------------------ |
| 201 | # Del Construct Data Frame |
| 202 | # ------------------------ |
| 203 | |
| 204 | delDataFrame <- melt( delAvgs ) |
| 205 | delDataFrame$scale <- fileData$scale |
| 206 | delDataFrame$date <- fileData$date |
| 207 | delDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) ) |
| 208 | |
| 209 | colnames( delDataFrame ) <- c( "ms", |
| 210 | "type", |
| 211 | "scale", |
| 212 | "date", |
| 213 | "iterative" ) |
| 214 | |
| 215 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 216 | delDataFrame$type <- as.character( delDataFrame$type ) |
| 217 | delDataFrame$type <- factor( delDataFrame$type, |
| 218 | levels = unique( delDataFrame$type ) ) |
| 219 | |
| 220 | delDataFrame <- na.omit( delDataFrame ) # Omit any data that doesn't exist |
| 221 | |
| 222 | print( "Del Data Frame Results:" ) |
| 223 | print( delDataFrame ) |
| 224 | |
| 225 | # ********************************************************** |
| 226 | # STEP 3: Generate graphs. |
| 227 | # ********************************************************** |
| 228 | |
| 229 | print( "**********************************************************" ) |
| 230 | print( "STEP 3: Generate Graph." ) |
| 231 | print( "**********************************************************" ) |
| 232 | |
| 233 | # ------------------------------------------ |
| 234 | # Initializing variables used in both graphs |
| 235 | # ------------------------------------------ |
| 236 | |
| 237 | print( "Initializing variables used in both graphs." ) |
| 238 | |
| 239 | defaultTextSize() |
| 240 | xLabel <- xlab( "Build Date" ) |
| 241 | yLabel <- ylab( "Latency (ms)" ) |
| 242 | fillLabel <- labs( fill="Type" ) |
| 243 | |
| 244 | colors <- scale_fill_manual( values=c( webColor( "redv2" ), |
| 245 | webColor( "light_blue" ) ) ) |
| 246 | |
| 247 | wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) ) |
| 248 | |
| 249 | barWidth <- 0.3 |
| 250 | |
| 251 | theme <- graphTheme() |
| 252 | |
| 253 | barGraphFormat <- geom_bar( stat = "identity", |
| 254 | width = barWidth ) |
| 255 | |
| 256 | # ----------------------- |
| 257 | # Post Generate Main Plot |
| 258 | # ----------------------- |
| 259 | |
| 260 | print( "Creating main plot for Post graph." ) |
| 261 | |
| 262 | mainPlot <- ggplot( data = postDataFrame, aes( x = iterative, |
| 263 | y = ms, |
| 264 | fill = type ) ) |
| 265 | |
| 266 | # ----------------------------------- |
| 267 | # Post Fundamental Variables Assigned |
| 268 | # ----------------------------------- |
| 269 | |
| 270 | print( "Generating fundamental graph data for Post graph." ) |
| 271 | |
| 272 | xScaleConfig <- scale_x_continuous( breaks = postDataFrame$iterative, |
| 273 | label = postDataFrame$date ) |
| 274 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 275 | title <- labs( title = postChartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 276 | |
| 277 | fundamentalGraphData <- mainPlot + |
| 278 | xScaleConfig + |
| 279 | xLabel + |
| 280 | yLabel + |
| 281 | fillLabel + |
| 282 | theme + |
| 283 | wrapLegend + |
| 284 | colors + |
| 285 | title |
| 286 | |
| 287 | # -------------------------------- |
| 288 | # Post Generating Bar Graph Format |
| 289 | # -------------------------------- |
| 290 | |
| 291 | print( "Generating bar graph for Post graph." ) |
| 292 | |
| 293 | sum <- fileData[ 'posttoconfrm' ] + |
| 294 | fileData[ 'elapsepost' ] |
| 295 | |
| 296 | values <- geom_text( aes( x = postDataFrame$iterative, |
| 297 | y = sum + 0.03 * max( sum ), |
| 298 | label = format( sum, |
| 299 | digits = 3, |
| 300 | big.mark = ",", |
| 301 | scientific = FALSE ) ), |
| 302 | size = 7.0, |
| 303 | fontface = "bold" ) |
| 304 | |
| 305 | result <- fundamentalGraphData + |
| 306 | barGraphFormat + |
| 307 | values |
| 308 | |
| 309 | # ---------------------------- |
| 310 | # Post Exporting Graph to File |
| 311 | # ---------------------------- |
| 312 | |
| 313 | saveGraph( postOutputFile ) |
| 314 | |
| 315 | # ---------------------- |
| 316 | # Del Generate Main Plot |
| 317 | # ---------------------- |
| 318 | |
| 319 | print( "Creating main plot for Del graph." ) |
| 320 | |
| 321 | mainPlot <- ggplot( data = delDataFrame, aes( x = iterative, |
| 322 | y = ms, |
| 323 | fill = type ) ) |
| 324 | |
| 325 | # ---------------------------------- |
| 326 | # Del Fundamental Variables Assigned |
| 327 | # ---------------------------------- |
| 328 | |
| 329 | print( "Generating fundamental graph data for Del graph." ) |
| 330 | |
| 331 | xScaleConfig <- scale_x_continuous( breaks = delDataFrame$iterative, |
| 332 | label = delDataFrame$date ) |
| 333 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 334 | title <- labs( title = delChartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 335 | |
| 336 | fundamentalGraphData <- mainPlot + |
| 337 | xScaleConfig + |
| 338 | xLabel + |
| 339 | yLabel + |
| 340 | fillLabel + |
| 341 | theme + |
| 342 | wrapLegend + |
| 343 | colors + |
| 344 | title |
| 345 | |
| 346 | # ------------------------------- |
| 347 | # Del Generating Bar Graph Format |
| 348 | # ------------------------------- |
| 349 | |
| 350 | print( "Generating bar graph for Del graph." ) |
| 351 | |
| 352 | sum <- fileData[ 'deltoconfrm' ] + |
| 353 | fileData[ 'elapsedel' ] |
| 354 | |
| 355 | values <- geom_text( aes( x = delDataFrame$iterative, |
| 356 | y = sum + 0.03 * max( sum ), |
| 357 | label = format( sum, |
| 358 | digits = 3, |
| 359 | big.mark = ",", |
| 360 | scientific = FALSE ) ), |
| 361 | size = 7.0, |
| 362 | fontface = "bold" ) |
| 363 | |
| 364 | result <- fundamentalGraphData + |
| 365 | barGraphFormat + |
| 366 | title + |
| 367 | values |
| 368 | |
| 369 | # --------------------------- |
| 370 | # Del Exporting Graph to File |
| 371 | # --------------------------- |
| 372 | |
| 373 | saveGraph( delOutputFile ) |
| 374 | quit( status = 0 ) |