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