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 | # Port Latency Graph (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFportLat_master_UpErrBarWithStack.jpg): |
| 22 | # Rscript SCPFportLat.R <url> <port> <username> <pass> SCPFmastershipFailoverLat 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( "SCPFmastershipFailoverLat.R" ) |
| 59 | quit( status = 1 ) |
| 60 | } |
| 61 | |
| 62 | # ----------------- |
| 63 | # Create File Names |
| 64 | # ----------------- |
| 65 | |
| 66 | print( "Creating filenames and title of graph." ) |
| 67 | errBarOutputFileUp <- paste( args[ save_directory ], |
| 68 | "SCPFportLat_", |
| 69 | args[ branch_name ], |
| 70 | "_UpErrBarWithStack.jpg", |
| 71 | sep = "" ) |
| 72 | |
| 73 | errBarOutputFileDown <- paste( args[ save_directory ], |
| 74 | "SCPFportLat_", |
| 75 | args[ branch_name ], |
| 76 | "_DownErrBarWithStack.jpg", |
| 77 | sep = "" ) |
| 78 | |
| 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 | # Port Latency SQL Command |
| 92 | # ------------------------ |
| 93 | |
| 94 | print( "Generating Port Latency SQL Command" ) |
| 95 | |
| 96 | command <- paste( "SELECT * FROM port_latency_details WHERE branch = '", |
| 97 | args[ branch_name ], |
| 98 | "' AND date IN ( SELECT MAX( date ) FROM port_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 | # Port Up Averages Data Sorting |
| 117 | # ----------------------------- |
| 118 | |
| 119 | print( "Sorting data for Port Up Averages." ) |
| 120 | |
| 121 | requiredColumns <- c( "up_ofp_to_dev_avg", "up_dev_to_link_avg", "up_link_to_graph_avg" ) |
| 122 | |
| 123 | tryCatch( upAvgs <- c( fileData[ requiredColumns] ), |
| 124 | error = function( e ) { |
| 125 | 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." ) |
| 126 | print( "Required columns: " ) |
| 127 | print( requiredColumns ) |
| 128 | print( "Actual columns: " ) |
| 129 | print( names( fileData ) ) |
| 130 | print( "Error dump:" ) |
| 131 | print( e ) |
| 132 | quit( status = 1 ) |
| 133 | } |
| 134 | ) |
| 135 | |
| 136 | # ---------------------------- |
| 137 | # Port Up Construct Data Frame |
| 138 | # ---------------------------- |
| 139 | |
| 140 | print( "Constructing Port Up data frame." ) |
| 141 | |
| 142 | upAvgsDataFrame <- melt( upAvgs ) |
| 143 | upAvgsDataFrame$scale <- fileData$scale |
| 144 | upAvgsDataFrame$up_std <- fileData$up_std |
| 145 | |
| 146 | colnames( upAvgsDataFrame ) <- c( "ms", |
| 147 | "type", |
| 148 | "scale", |
| 149 | "stds" ) |
| 150 | |
| 151 | upAvgsDataFrame <- na.omit( upAvgsDataFrame ) |
| 152 | |
| 153 | upAvgsDataFrame$type <- as.character( upAvgsDataFrame$type ) |
| 154 | upAvgsDataFrame$type <- factor( upAvgsDataFrame$type, levels=unique( upAvgsDataFrame$type ) ) |
| 155 | |
| 156 | sumOfUpAvgs <- fileData[ 'up_ofp_to_dev_avg' ] + |
| 157 | fileData[ 'up_dev_to_link_avg' ] + |
| 158 | fileData[ 'up_link_to_graph_avg' ] |
| 159 | |
| 160 | print( "Up Averages Results:" ) |
| 161 | print( upAvgsDataFrame ) |
| 162 | |
| 163 | # ------------------------------- |
| 164 | # Port Down Averages Data Sorting |
| 165 | # ------------------------------- |
| 166 | |
| 167 | print( "Sorting data for Port Down Averages." ) |
| 168 | |
| 169 | requiredColumns <- c( "down_ofp_to_dev_avg", "down_dev_to_link_avg", "down_link_to_graph_avg" ) |
| 170 | |
| 171 | tryCatch( downAvgs <- c( fileData[ requiredColumns] ), |
| 172 | error = function( e ) { |
| 173 | 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." ) |
| 174 | print( "Required columns: " ) |
| 175 | print( requiredColumns ) |
| 176 | print( "Actual columns: " ) |
| 177 | print( names( fileData ) ) |
| 178 | print( "Error dump:" ) |
| 179 | print( e ) |
| 180 | quit( status = 1 ) |
| 181 | } |
| 182 | ) |
| 183 | |
| 184 | # ------------------------------ |
| 185 | # Port Down Construct Data Frame |
| 186 | # ------------------------------ |
| 187 | |
| 188 | print( "Constructing Port Down data frame." ) |
| 189 | |
| 190 | downAvgsDataFrame <- melt( downAvgs ) |
| 191 | downAvgsDataFrame$scale <- fileData$scale |
| 192 | downAvgsDataFrame$down_std <- fileData$down_std |
| 193 | |
| 194 | colnames( downAvgsDataFrame ) <- c( "ms", |
| 195 | "type", |
| 196 | "scale", |
| 197 | "stds" ) |
| 198 | |
| 199 | downAvgsDataFrame <- na.omit( downAvgsDataFrame ) |
| 200 | |
| 201 | downAvgsDataFrame$type <- as.character( downAvgsDataFrame$type ) |
| 202 | downAvgsDataFrame$type <- factor( downAvgsDataFrame$type, levels=unique( downAvgsDataFrame$type ) ) |
| 203 | |
| 204 | sumOfDownAvgs <- fileData[ 'down_ofp_to_dev_avg' ] + |
| 205 | fileData[ 'down_dev_to_link_avg' ] + |
| 206 | fileData[ 'down_link_to_graph_avg' ] |
| 207 | |
| 208 | print( "Down Averages Results:" ) |
| 209 | print( downAvgsDataFrame ) |
| 210 | |
| 211 | # ********************************************************** |
| 212 | # STEP 3: Generate graphs. |
| 213 | # ********************************************************** |
| 214 | |
| 215 | print( "**********************************************************" ) |
| 216 | print( "STEP 3: Generate Graph." ) |
| 217 | print( "**********************************************************" ) |
| 218 | |
| 219 | # ------------------------------------ |
| 220 | # Initialize Variables For Both Graphs |
| 221 | # ------------------------------------ |
| 222 | |
| 223 | print( "Initializing variables used in both graphs." ) |
| 224 | |
| 225 | defaultTextSize() |
| 226 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) ) |
| 227 | |
| 228 | xLabel <- xlab( "Scale" ) |
| 229 | yLabel <- ylab( "Latency (ms)" ) |
| 230 | fillLabel <- labs( fill="Type" ) |
| 231 | |
| 232 | barWidth <- 1 |
| 233 | |
| 234 | wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) ) |
| 235 | |
| 236 | theme <- graphTheme() |
| 237 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 238 | subtitle <- lastUpdatedLabel( latestBuildDate ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 239 | |
| 240 | colors <- scale_fill_manual( values=c( webColor( "redv2" ), |
| 241 | webColor( "light_blue" ), |
| 242 | webColor( "green" ) ) ) |
| 243 | |
| 244 | errorBarColor <- webColor( "darkerGray" ) |
| 245 | |
| 246 | # -------------------------- |
| 247 | # Port Up Generate Main Plot |
| 248 | # -------------------------- |
| 249 | |
| 250 | print( "Generating main plot (Port Up Latency)." ) |
| 251 | |
| 252 | mainPlot <- ggplot( data = upAvgsDataFrame, aes( x = scale, |
| 253 | y = ms, |
| 254 | fill = type, |
| 255 | ymin = fileData[ 'up_end_to_end_avg' ], |
| 256 | ymax = fileData[ 'up_end_to_end_avg' ] + stds ) ) |
| 257 | |
| 258 | # -------------------------------------- |
| 259 | # Port Up Fundamental Variables Assigned |
| 260 | # -------------------------------------- |
| 261 | |
| 262 | print( "Generating fundamental graph data (Port Up Latency)." ) |
| 263 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 264 | title <- labs( title = "Port Up Latency", subtitle = lastUpdatedLabel( latestBuildDate ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 265 | |
| 266 | fundamentalGraphData <- mainPlot + |
| 267 | xScaleConfig + |
| 268 | xLabel + |
| 269 | yLabel + |
| 270 | fillLabel + |
| 271 | theme + |
| 272 | wrapLegend + |
| 273 | title + |
| 274 | colors |
| 275 | |
| 276 | # ----------------------------------- |
| 277 | # Port Up Generating Bar Graph Format |
| 278 | # ----------------------------------- |
| 279 | |
| 280 | print( "Generating bar graph with error bars (Port Up Latency)." ) |
| 281 | |
| 282 | barGraphFormat <- geom_bar( stat = "identity", |
| 283 | width = barWidth ) |
| 284 | |
| 285 | errorBarFormat <- geom_errorbar( width = barWidth, |
| 286 | color = errorBarColor ) |
| 287 | |
| 288 | values <- geom_text( aes( x = upAvgsDataFrame$scale, |
| 289 | y = sumOfUpAvgs + 0.03 * max( sumOfUpAvgs ), |
| 290 | label = format( sumOfUpAvgs, |
| 291 | digits=3, |
| 292 | big.mark = ",", |
| 293 | scientific = FALSE ) ), |
| 294 | size = 7.0, |
| 295 | fontface = "bold" ) |
| 296 | |
| 297 | result <- fundamentalGraphData + |
| 298 | barGraphFormat + |
| 299 | errorBarFormat + |
| 300 | values |
| 301 | |
| 302 | # ------------------------------- |
| 303 | # Port Up Exporting Graph to File |
| 304 | # ------------------------------- |
| 305 | |
| 306 | saveGraph( errBarOutputFileUp ) |
| 307 | |
| 308 | # ---------------------------- |
| 309 | # Port Down Generate Main Plot |
| 310 | # ---------------------------- |
| 311 | |
| 312 | print( "Generating main plot (Port Down Latency)." ) |
| 313 | |
| 314 | mainPlot <- ggplot( data = downAvgsDataFrame, aes( x = scale, |
| 315 | y = ms, |
| 316 | fill = type, |
| 317 | ymin = fileData[ 'down_end_to_end_avg' ], |
| 318 | ymax = fileData[ 'down_end_to_end_avg' ] + stds ) ) |
| 319 | |
| 320 | # ---------------------------------------- |
| 321 | # Port Down Fundamental Variables Assigned |
| 322 | # ---------------------------------------- |
| 323 | |
| 324 | print( "Generating fundamental graph data (Port Down Latency)." ) |
| 325 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 326 | title <- labs( title = "Port Down Latency", subtitle = lastUpdatedLabel( latestBuildDate ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 327 | |
| 328 | fundamentalGraphData <- mainPlot + |
| 329 | xScaleConfig + |
| 330 | xLabel + |
| 331 | yLabel + |
| 332 | fillLabel + |
| 333 | theme + |
| 334 | wrapLegend + |
| 335 | title + |
| 336 | colors |
| 337 | |
| 338 | # ------------------------------------- |
| 339 | # Port Down Generating Bar Graph Format |
| 340 | # ------------------------------------- |
| 341 | |
| 342 | print( "Generating bar graph with error bars (Port Down Latency)." ) |
| 343 | |
| 344 | barGraphFormat <- geom_bar( stat = "identity", |
| 345 | width = barWidth ) |
| 346 | |
| 347 | errorBarFormat <- geom_errorbar( width = barWidth, |
| 348 | color = errorBarColor ) |
| 349 | |
| 350 | values <- geom_text( aes( x = downAvgsDataFrame$scale, |
| 351 | y = sumOfDownAvgs + 0.03 * max( sumOfDownAvgs ), |
| 352 | label = format( sumOfDownAvgs, |
| 353 | digits=3, |
| 354 | big.mark = ",", |
| 355 | scientific = FALSE ) ), |
| 356 | size = 7.0, |
| 357 | fontface = "bold" ) |
| 358 | |
| 359 | result <- fundamentalGraphData + |
| 360 | barGraphFormat + |
| 361 | errorBarFormat + |
| 362 | values |
| 363 | |
| 364 | # --------------------------------- |
| 365 | # Port Down Exporting Graph to File |
| 366 | # --------------------------------- |
| 367 | |
| 368 | saveGraph( errBarOutputFileDown ) |
| 369 | quit( status = 0 ) |