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