Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [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, |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 21 | # please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 22 | |
| 23 | # ********************************************************** |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 24 | # STEP 1: Data management. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 25 | # ********************************************************** |
| 26 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 27 | print( "**********************************************************" ) |
| 28 | print( "STEP 1: Data management." ) |
| 29 | print( "**********************************************************" ) |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 30 | has_flow_obj = 1 |
| 31 | database_host = 2 |
| 32 | database_port = 3 |
| 33 | database_u_id = 4 |
| 34 | database_pw = 5 |
| 35 | test_name = 6 |
| 36 | branch_name = 7 |
| 37 | has_neighbors = 8 |
| 38 | old_flow = 9 |
| 39 | save_directory = 10 |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 40 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 41 | # Command line arguments are read. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 42 | print( "Reading commmand-line args." ) |
| 43 | args <- commandArgs( trailingOnly=TRUE ) |
| 44 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 45 | # ---------------- |
| 46 | # Import Libraries |
| 47 | # ---------------- |
| 48 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 49 | print( "Importing libraries." ) |
| 50 | library( ggplot2 ) |
| 51 | library( reshape2 ) |
| 52 | library( RPostgreSQL ) # For databases |
| 53 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 54 | # ------------------- |
| 55 | # Check CLI Arguments |
| 56 | # ------------------- |
| 57 | |
| 58 | print( "Verifying CLI args." ) |
| 59 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 60 | if ( is.na( args[ save_directory ] ) ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 61 | |
| 62 | print( paste( "Usage: Rscript SCPFIntentEventTp.R", |
| 63 | "<has-flow-obj>", |
| 64 | "<database-host>", |
| 65 | "<database-port>", |
| 66 | "<database-user-id>", |
| 67 | "<database-password>", |
| 68 | "<test-name>", |
| 69 | "<branch-name>", |
| 70 | "<has-neighbors>", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 71 | "<using-old-flow>", |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 72 | "<directory-to-save-graphs>", |
| 73 | sep=" " ) ) |
| 74 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 75 | q() # basically exit(), but in R |
| 76 | } |
| 77 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 78 | # ----------------- |
| 79 | # Create File Names |
| 80 | # ----------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 81 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 82 | print( "Creating filenames and title of graph." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 83 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 84 | chartTitle <- "Intent Event Throughput" |
| 85 | fileNeighborsModifier <- "no" |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 86 | commandNeighborModifier <- "" |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 87 | fileFlowObjModifier <- "" |
| 88 | sqlFlowObjModifier <- "" |
| 89 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 90 | if ( args[ has_flow_obj ] == 'y' ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 91 | fileFlowObjModifier <- "_flowObj" |
| 92 | sqlFlowObjModifier <- "_fobj" |
| 93 | chartTitle <- paste( chartTitle, " with Flow Objectives", sep="" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 94 | } |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 95 | |
| 96 | chartTitle <- paste( chartTitle, "\nevents/second with Neighbors =", sep="" ) |
| 97 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 98 | fileOldFlowModifier <- "" |
| 99 | if ( args[ has_neighbors ] == 'y' ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 100 | fileNeighborsModifier <- "all" |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 101 | commandNeighborModifier <- "scale=1 OR NOT " |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 102 | chartTitle <- paste( chartTitle, "all" ) |
| 103 | } else { |
| 104 | chartTitle <- paste( chartTitle, "0" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 105 | } |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 106 | if ( args[ old_flow ] == 'y' ){ |
| 107 | fileOldFlowModifier <- "_OldFlow" |
| 108 | chartTitle <- paste( chartTitle, "With Old Flow", sep="\n" ) |
| 109 | } |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 110 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 111 | errBarOutputFile <- paste( args[ save_directory ], |
| 112 | args[ test_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 113 | "_", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 114 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 115 | "_", |
| 116 | fileNeighborsModifier, |
| 117 | "-neighbors", |
| 118 | fileFlowObjModifier, |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 119 | fileOldFlowModifier, |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 120 | "_graph.jpg", |
| 121 | sep="" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 122 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 123 | # ------------------ |
| 124 | # SQL Initialization |
| 125 | # ------------------ |
| 126 | |
| 127 | print( "Initializing SQL" ) |
| 128 | |
| 129 | con <- dbConnect( dbDriver( "PostgreSQL" ), |
| 130 | dbname = "onostest", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 131 | host = args[ database_host ], |
| 132 | port = strtoi( args[ database_port ] ), |
| 133 | user = args[ database_u_id ], |
| 134 | password = args[ database_pw ] ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 135 | |
| 136 | # ----------------------------------- |
| 137 | # Intent Event Throughput SQL Command |
| 138 | # ----------------------------------- |
| 139 | |
| 140 | print( "Generating Intent Event Throughput SQL command." ) |
| 141 | |
| 142 | command <- paste( "SELECT scale, SUM( avg ) as avg FROM intent_tp", |
| 143 | sqlFlowObjModifier, |
| 144 | "_tests WHERE (", |
| 145 | commandNeighborModifier, |
| 146 | "neighbors = 0 ) AND branch = '", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 147 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 148 | "' AND date IN ( SELECT max( date ) FROM intent_tp", |
| 149 | sqlFlowObjModifier, |
| 150 | "_tests WHERE branch='", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 151 | args[ branch_name ], |
| 152 | "' AND ", |
| 153 | ( if( args[ old_flow ] == 'y' ) "" else "NOT " ), |
| 154 | "is_old_flow", |
| 155 | " ) GROUP BY scale ORDER BY scale", |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 156 | sep="" ) |
| 157 | |
| 158 | print( "Sending SQL command:" ) |
| 159 | print( command ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 160 | |
| 161 | fileData <- dbGetQuery( con, command ) |
| 162 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 163 | # ********************************************************** |
| 164 | # STEP 2: Organize data. |
| 165 | # ********************************************************** |
| 166 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 167 | print( "**********************************************************" ) |
| 168 | print( "STEP 2: Organize Data." ) |
| 169 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 170 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 171 | # ------------ |
| 172 | # Data Sorting |
| 173 | # ------------ |
| 174 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 175 | print( "Sorting data." ) |
| 176 | avgs <- c( fileData[ 'avg' ] ) |
| 177 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 178 | # -------------------- |
| 179 | # Construct Data Frame |
| 180 | # -------------------- |
| 181 | |
| 182 | print( "Constructing data frame." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 183 | dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame |
| 184 | dataFrame$scale <- fileData$scale # Add node scaling to the data frame. |
| 185 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 186 | colnames( dataFrame ) <- c( "throughput", |
| 187 | "type", |
| 188 | "scale" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 189 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 190 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 191 | |
| 192 | print( "Data Frame Results:" ) |
| 193 | print( dataFrame ) |
| 194 | |
| 195 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 196 | # ********************************************************** |
| 197 | # STEP 3: Generate graphs. |
| 198 | # ********************************************************** |
| 199 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 200 | print( "**********************************************************" ) |
| 201 | print( "STEP 3: Generate Graph." ) |
| 202 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 203 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 204 | # ------------------ |
| 205 | # Generate Main Plot |
| 206 | # ------------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 207 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 208 | print( "Generating main plot." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 209 | # Create the primary plot here. |
| 210 | # ggplot contains the following arguments: |
| 211 | # - data: the data frame that the graph will be based off of |
| 212 | # - aes: the asthetics of the graph which require: |
| 213 | # - x: x-axis values (usually node scaling) |
| 214 | # - y: y-axis values (usually time in milliseconds) |
| 215 | # - fill: the category of the colored side-by-side bars (usually type) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 216 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 217 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, |
| 218 | y = throughput, |
| 219 | fill = type ) ) |
| 220 | # ------------------------------ |
| 221 | # Fundamental Variables Assigned |
| 222 | # ------------------------------ |
| 223 | |
| 224 | print( "Generating fundamental graph data." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 225 | |
| 226 | # Formatting the plot |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 227 | theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 228 | width <- 0.7 # Width of the bars. |
| 229 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$scale, label = dataFrame$scale ) |
| 230 | xLabel <- xlab( "Scale" ) |
| 231 | yLabel <- ylab( "Throughput (events/second)" ) |
| 232 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 233 | imageWidth <- 15 |
| 234 | imageHeight <- 10 |
| 235 | imageDPI <- 200 |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 236 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 237 | theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ), |
| 238 | legend.position = "bottom", |
| 239 | legend.text = element_text( size = 18, face = "bold" ), |
| 240 | legend.title = element_blank() ) |
| 241 | |
| 242 | values <- geom_text( aes( x = dataFrame$scale, |
| 243 | y = dataFrame$throughput + 0.03 * max( dataFrame$throughput ), |
| 244 | label = format( dataFrame$throughput, |
| 245 | digits=3, |
| 246 | big.mark = ",", |
| 247 | scientific = FALSE ) ), |
| 248 | size = 7, |
| 249 | fontface = "bold" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 250 | |
| 251 | # Store plot configurations as 1 variable |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 252 | fundamentalGraphData <- mainPlot + |
| 253 | xScaleConfig + |
| 254 | xLabel + |
| 255 | yLabel + |
| 256 | fillLabel + |
| 257 | theme + |
| 258 | values |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 259 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 260 | # --------------------------- |
| 261 | # Generating Bar Graph Format |
| 262 | # --------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 263 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 264 | print( "Generating bar graph." ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 265 | barGraphFormat <- geom_bar( stat = "identity", |
| 266 | width = width, |
| 267 | fill = "#169EFF" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 268 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 269 | title <- ggtitle( chartTitle ) |
| 270 | |
| 271 | result <- fundamentalGraphData + |
| 272 | barGraphFormat + |
| 273 | title |
| 274 | |
| 275 | # ----------------------- |
| 276 | # Exporting Graph to File |
| 277 | # ----------------------- |
| 278 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 279 | print( paste( "Saving bar chart to", errBarOutputFile ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 280 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 281 | ggsave( errBarOutputFile, |
| 282 | width = imageWidth, |
| 283 | height = imageHeight, |
| 284 | dpi = imageDPI ) |
| 285 | |
| 286 | print( paste( "[SUCCESS] Successfully wrote bar chart out to", errBarOutputFile ) ) |