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( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 30 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 31 | # Command line arguments are read. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 32 | print( "Reading commmand-line args." ) |
| 33 | args <- commandArgs( trailingOnly=TRUE ) |
| 34 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 35 | # ---------------- |
| 36 | # Import Libraries |
| 37 | # ---------------- |
| 38 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 39 | print( "Importing libraries." ) |
| 40 | library( ggplot2 ) |
| 41 | library( reshape2 ) |
| 42 | library( RPostgreSQL ) # For databases |
| 43 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 44 | # ------------------- |
| 45 | # Check CLI Arguments |
| 46 | # ------------------- |
| 47 | |
| 48 | print( "Verifying CLI args." ) |
| 49 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 50 | if ( is.na( args[ 7 ] ) ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 51 | |
| 52 | print( paste( "Usage: Rscript SCPFgraphGenerator", |
| 53 | "<database-host>", |
| 54 | "<database-port>", |
| 55 | "<database-user-id>", |
| 56 | "<database-password>", |
| 57 | "<test-name>", |
| 58 | "<branch-name>", |
| 59 | "<directory-to-save-graphs>", |
| 60 | sep=" ") ) |
| 61 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 62 | q() # basically exit(), but in R |
| 63 | } |
| 64 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 65 | # ----------------- |
| 66 | # Create File Names |
| 67 | # ----------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 68 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 69 | print( "Creating filenames and title of graph." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 70 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 71 | outputFile <- paste( args[ 7 ], |
| 72 | args[ 5 ], |
| 73 | "_", |
| 74 | args[ 6 ], |
| 75 | "_graph.jpg", |
| 76 | sep="" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 77 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 78 | chartTitle <- "Scale Topology Latency Test" |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 79 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 80 | # ------------------ |
| 81 | # SQL Initialization |
| 82 | # ------------------ |
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 | print( "Initializing SQL" ) |
| 85 | |
| 86 | con <- dbConnect( dbDriver( "PostgreSQL" ), |
| 87 | dbname = "onostest", |
| 88 | host = args[ 1 ], |
| 89 | port = strtoi( args[ 2 ] ), |
| 90 | user = args[ 3 ], |
| 91 | password = args[ 4 ] ) |
| 92 | |
| 93 | # -------------------------- |
| 94 | # Scale Topology SQL Command |
| 95 | # -------------------------- |
| 96 | |
| 97 | print( "Generating Scale Topology SQL Command" ) |
| 98 | |
| 99 | command <- paste( "SELECT * FROM scale_topo_latency_details WHERE branch = '", |
| 100 | args[ 6 ], |
| 101 | "' AND date IN ( SELECT MAX( date ) FROM scale_topo_latency_details WHERE branch = '", |
| 102 | args[ 6 ], |
| 103 | "' ) ", |
| 104 | sep = "" ) |
| 105 | |
| 106 | print( "Sending SQL command:" ) |
| 107 | print( command ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 108 | fileData <- dbGetQuery( con, command ) |
| 109 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 110 | # ********************************************************** |
| 111 | # STEP 2: Organize data. |
| 112 | # ********************************************************** |
| 113 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 114 | print( "**********************************************************" ) |
| 115 | print( "STEP 2: Organize Data." ) |
| 116 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 117 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 118 | # ------------ |
| 119 | # Data Sorting |
| 120 | # ------------ |
| 121 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 122 | print( "Sorting data." ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 123 | avgs <- c( fileData[ 'last_role_request_to_last_topology' ], |
| 124 | fileData[ 'last_connection_to_last_role_request' ], |
| 125 | fileData[ 'first_connection_to_last_connection' ] ) |
| 126 | |
| 127 | # -------------------- |
| 128 | # Construct Data Frame |
| 129 | # -------------------- |
| 130 | |
| 131 | print( "Constructing Data Frame" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 132 | |
| 133 | # Parse lists into data frames. |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 134 | dataFrame <- melt( avgs ) |
| 135 | dataFrame$scale <- fileData$scale |
| 136 | colnames( dataFrame ) <- c( "s", |
| 137 | "type", |
| 138 | "scale") |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 139 | |
| 140 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 141 | dataFrame$type <- as.character( dataFrame$type ) |
| 142 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 143 | dataFrame$iterative <- seq( 1, nrow( fileData ), by = 1 ) |
| 144 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 145 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 146 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 147 | sum <- fileData[ 'last_role_request_to_last_topology' ] + |
| 148 | fileData[ 'last_connection_to_last_role_request' ] + |
| 149 | fileData[ 'first_connection_to_last_connection' ] |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 150 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 151 | print( "Data Frame Results:" ) |
| 152 | print( dataFrame ) |
| 153 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 154 | # ********************************************************** |
| 155 | # STEP 3: Generate graphs. |
| 156 | # ********************************************************** |
| 157 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 158 | print( "**********************************************************" ) |
| 159 | print( "STEP 3: Generate Graph." ) |
| 160 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 161 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 162 | # ------------------ |
| 163 | # Generate Main Plot |
| 164 | # ------------------ |
| 165 | |
| 166 | print( "Creating main plot." ) |
| 167 | |
| 168 | mainPlot <- ggplot( data = dataFrame, aes( x = iterative, |
| 169 | y = s, |
| 170 | fill = type ) ) |
| 171 | |
| 172 | # ------------------------------ |
| 173 | # Fundamental Variables Assigned |
| 174 | # ------------------------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 175 | |
| 176 | print( "Generating fundamental graph data." ) |
| 177 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 178 | theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 179 | width <- 0.6 # Width of the bars. |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 180 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, |
| 181 | label = dataFrame$scale ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 182 | xLabel <- xlab( "Scale" ) |
Devin Lim | 3c2b9d6 | 2017-10-25 11:41:41 -0700 | [diff] [blame] | 183 | yLabel <- ylab( "Latency (s)" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 184 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 185 | imageWidth <- 15 |
| 186 | imageHeight <- 10 |
| 187 | imageDPI <- 200 |
| 188 | |
| 189 | theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ), |
| 190 | legend.position = "bottom", |
| 191 | legend.text = element_text( size=22 ), |
| 192 | legend.title = element_blank(), |
| 193 | legend.key.size = unit( 1.5, 'lines' ) ) |
| 194 | |
| 195 | values <- geom_text( aes( x = dataFrame$iterative, |
| 196 | y = sum + 0.02 * max( sum ), |
| 197 | label = format( sum, |
| 198 | big.mark = ",", |
| 199 | scientific = FALSE ), |
| 200 | fontface = "bold" ), |
| 201 | size = 7.0 ) |
| 202 | |
| 203 | wrapLegend <- guides( fill = guide_legend( nrow=2, byrow=TRUE ) ) |
| 204 | |
| 205 | title <- ggtitle( chartTitle, "" ) |
| 206 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 207 | # Store plot configurations as 1 variable |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 208 | fundamentalGraphData <- mainPlot + |
| 209 | xScaleConfig + |
| 210 | xLabel + |
| 211 | yLabel + |
| 212 | fillLabel + |
| 213 | theme + |
| 214 | values + |
| 215 | wrapLegend + |
| 216 | title |
| 217 | |
| 218 | # --------------------------- |
| 219 | # Generating Bar Graph Format |
| 220 | # --------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 221 | |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 222 | print( "Generating bar graph." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 223 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 224 | barGraphFormat <- geom_bar( stat = "identity", width = width ) |
| 225 | |
| 226 | result <- fundamentalGraphData + |
| 227 | barGraphFormat |
| 228 | |
| 229 | # ----------------------- |
| 230 | # Exporting Graph to File |
| 231 | # ----------------------- |
| 232 | |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 233 | print( paste( "Saving bar chart to", outputFile ) ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 234 | |
| 235 | ggsave( outputFile, |
| 236 | width = imageWidth, |
| 237 | height = imageHeight, |
| 238 | dpi = imageDPI ) |
| 239 | |
| 240 | print( paste( "[SUCCESS] Successfully wrote bar chart out to", outputFile ) ) |