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 | # Scale Topology Latency Test Graph (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFscaleTopo_master_graph.jpg): |
| 22 | # Rscript SCPFspecificGraphRScripts/SCPFscaleTopo.R <url> <port> <username> <pass> SCPFscaleTopo 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( "SCPFscaleTopo.R" ) |
| 59 | quit( status = 1 ) |
| 60 | } |
| 61 | |
| 62 | # ----------------- |
| 63 | # Create File Names |
| 64 | # ----------------- |
| 65 | |
| 66 | print( "Creating filenames and title of graph." ) |
| 67 | |
| 68 | outputFile <- paste( args[ save_directory ], |
| 69 | args[ graph_title ], |
| 70 | "_", |
| 71 | args[ branch_name ], |
| 72 | "_graph.jpg", |
| 73 | sep="" ) |
| 74 | |
| 75 | chartTitle <- "Scale Topology Latency Test" |
| 76 | |
| 77 | # ------------------ |
| 78 | # SQL Initialization |
| 79 | # ------------------ |
| 80 | |
| 81 | print( "Initializing SQL" ) |
| 82 | |
| 83 | con <- initSQL( args[ database_host ], |
| 84 | args[ database_port ], |
| 85 | args[ database_u_id ], |
| 86 | args[ database_pw ] ) |
| 87 | |
| 88 | # -------------------------- |
| 89 | # Scale Topology SQL Command |
| 90 | # -------------------------- |
| 91 | |
| 92 | print( "Generating Scale Topology SQL Command" ) |
| 93 | |
| 94 | command <- paste( "SELECT * FROM scale_topo_latency_details WHERE branch = '", |
| 95 | args[ branch_name ], |
| 96 | "' AND date IN ( SELECT MAX( date ) FROM scale_topo_latency_details WHERE branch = '", |
| 97 | args[ branch_name ], |
| 98 | "' ) ", |
| 99 | sep = "" ) |
| 100 | |
| 101 | fileData <- retrieveData( con, command ) |
| 102 | |
| 103 | # ********************************************************** |
| 104 | # STEP 2: Organize data. |
| 105 | # ********************************************************** |
| 106 | |
| 107 | print( "**********************************************************" ) |
| 108 | print( "STEP 2: Organize Data." ) |
| 109 | print( "**********************************************************" ) |
| 110 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 111 | latestBuildDate <- fileData$date[1] |
| 112 | |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 113 | # ------------ |
| 114 | # Data Sorting |
| 115 | # ------------ |
| 116 | |
| 117 | print( "Sorting data." ) |
| 118 | |
| 119 | requiredColumns <- c( "last_role_request_to_last_topology", "last_connection_to_last_role_request", "first_connection_to_last_connection" ) |
| 120 | |
| 121 | tryCatch( avgs <- c( fileData[ requiredColumns] ), |
| 122 | error = function( e ) { |
| 123 | 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." ) |
| 124 | print( "Required columns: " ) |
| 125 | print( requiredColumns ) |
| 126 | print( "Actual columns: " ) |
| 127 | print( names( fileData ) ) |
| 128 | print( "Error dump:" ) |
| 129 | print( e ) |
| 130 | quit( status = 1 ) |
| 131 | } |
| 132 | ) |
| 133 | |
| 134 | # -------------------- |
| 135 | # Construct Data Frame |
| 136 | # -------------------- |
| 137 | |
| 138 | print( "Constructing Data Frame" ) |
| 139 | |
| 140 | # Parse lists into data frames. |
| 141 | dataFrame <- melt( avgs ) |
| 142 | dataFrame$scale <- fileData$scale |
| 143 | colnames( dataFrame ) <- c( "s", |
| 144 | "type", |
| 145 | "scale") |
| 146 | |
| 147 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 148 | dataFrame$type <- as.character( dataFrame$type ) |
| 149 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 150 | dataFrame$iterative <- seq( 1, nrow( fileData ), by = 1 ) |
| 151 | |
| 152 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 153 | |
| 154 | sum <- fileData[ 'last_role_request_to_last_topology' ] + |
| 155 | fileData[ 'last_connection_to_last_role_request' ] + |
| 156 | fileData[ 'first_connection_to_last_connection' ] |
| 157 | |
| 158 | print( "Data Frame Results:" ) |
| 159 | print( dataFrame ) |
| 160 | |
| 161 | # ********************************************************** |
| 162 | # STEP 3: Generate graphs. |
| 163 | # ********************************************************** |
| 164 | |
| 165 | print( "**********************************************************" ) |
| 166 | print( "STEP 3: Generate Graph." ) |
| 167 | print( "**********************************************************" ) |
| 168 | |
| 169 | # ------------------ |
| 170 | # Generate Main Plot |
| 171 | # ------------------ |
| 172 | |
| 173 | print( "Creating main plot." ) |
| 174 | |
| 175 | mainPlot <- ggplot( data = dataFrame, aes( x = iterative, |
| 176 | y = s, |
| 177 | fill = type ) ) |
| 178 | |
| 179 | # ------------------------------ |
| 180 | # Fundamental Variables Assigned |
| 181 | # ------------------------------ |
| 182 | |
| 183 | print( "Generating fundamental graph data." ) |
| 184 | |
| 185 | defaultTextSize() |
| 186 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, |
| 187 | label = dataFrame$scale ) |
| 188 | xLabel <- xlab( "Scale" ) |
| 189 | yLabel <- ylab( "Latency (s)" ) |
| 190 | fillLabel <- labs( fill="Type" ) |
| 191 | |
| 192 | width <- 0.6 # Width of the bars. |
| 193 | |
| 194 | theme <- graphTheme() |
| 195 | |
| 196 | colors <- scale_fill_manual( values=c( webColor( "redv2" ), |
| 197 | webColor( "green" ), |
| 198 | webColor( "light_blue" ) ) ) |
| 199 | |
| 200 | values <- geom_text( aes( x = dataFrame$iterative, |
| 201 | y = sum + 0.02 * max( sum ), |
| 202 | label = format( sum, |
| 203 | big.mark = ",", |
| 204 | scientific = FALSE ), |
| 205 | fontface = "bold" ), |
| 206 | size = 7.0 ) |
| 207 | |
| 208 | wrapLegend <- guides( fill = guide_legend( nrow=2, byrow=TRUE ) ) |
| 209 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 210 | title <- labs( title = chartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 211 | |
| 212 | # Store plot configurations as 1 variable |
| 213 | fundamentalGraphData <- mainPlot + |
| 214 | xScaleConfig + |
| 215 | xLabel + |
| 216 | yLabel + |
| 217 | fillLabel + |
| 218 | theme + |
| 219 | values + |
| 220 | wrapLegend + |
| 221 | title + |
| 222 | colors |
| 223 | |
| 224 | # --------------------------- |
| 225 | # Generating Bar Graph Format |
| 226 | # --------------------------- |
| 227 | |
| 228 | print( "Generating bar graph." ) |
| 229 | |
| 230 | barGraphFormat <- geom_bar( stat = "identity", width = width ) |
| 231 | |
| 232 | result <- fundamentalGraphData + |
| 233 | barGraphFormat |
| 234 | |
| 235 | # ----------------------- |
| 236 | # Exporting Graph to File |
| 237 | # ----------------------- |
| 238 | |
| 239 | saveGraph( outputFile ) |
| 240 | quit( status = 0 ) |