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 | # ********************************************************** |
| 24 | # STEP 1: File management. |
| 25 | # ********************************************************** |
| 26 | |
| 27 | print( "STEP 1: File management." ) |
| 28 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 29 | # Command line arguments are read. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 30 | print( "Reading commmand-line args." ) |
| 31 | args <- commandArgs( trailingOnly=TRUE ) |
| 32 | |
| 33 | # Import libraries to be used for graphing and organizing data, respectively. |
| 34 | # Find out more about ggplot2: https://github.com/tidyverse/ggplot2 |
| 35 | # reshape2: https://github.com/hadley/reshape |
| 36 | print( "Importing libraries." ) |
| 37 | library( ggplot2 ) |
| 38 | library( reshape2 ) |
| 39 | library( RPostgreSQL ) # For databases |
| 40 | |
| 41 | # Check if sufficient args are provided. |
| 42 | if ( is.na( args[ 9 ] ) ){ |
| 43 | print( "Usage: Rscript SCPFIntentInstallWithdrawRerouteLat.R <isFlowObj> <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <batch-size> <directory-to-save-graphs>" ) |
| 44 | q() # basically exit(), but in R |
| 45 | } |
| 46 | |
| 47 | flowObjFileModifier <- "" |
| 48 | if ( args[ 1 ] == "y" ){ |
| 49 | flowObjFileModifier <- "fobj_" |
| 50 | } |
| 51 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 52 | # paste() is used to concatenate strings |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 53 | errBarOutputFile <- paste( args[ 9 ], "SCPFIntentInstallWithdrawRerouteLat", sep="" ) |
| 54 | errBarOutputFile <- paste( errBarOutputFile, args[ 7 ], sep="_" ) |
| 55 | if ( args[ 1 ] == "y" ){ |
| 56 | errBarOutputFile <- paste( errBarOutputFile, "_fobj", sep="" ) |
| 57 | } |
| 58 | errBarOutputFile <- paste( errBarOutputFile, "_", sep="" ) |
| 59 | errBarOutputFile <- paste( errBarOutputFile, args[ 8 ], sep="" ) |
| 60 | errBarOutputFile <- paste( errBarOutputFile, "-batchSize", sep="" ) |
| 61 | errBarOutputFile <- paste( errBarOutputFile, "_graph.jpg", sep="" ) |
| 62 | |
| 63 | print( "Reading from databases." ) |
| 64 | |
| 65 | con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 2 ], port=strtoi( args[ 3 ] ), user=args[ 4 ],password=args[ 5 ] ) |
| 66 | |
| 67 | command1 <- paste( "SELECT * FROM intent_latency_", flowObjFileModifier, sep="" ) |
| 68 | command1 <- paste( command1, "tests WHERE batch_size=", sep="" ) |
| 69 | command1 <- paste( command1, args[ 8 ], sep="" ) |
| 70 | command1 <- paste( command1, " AND branch = '", sep="" ) |
| 71 | command1 <- paste( command1, args[ 7 ], sep="" ) |
| 72 | command1 <- paste( command1, "' AND date IN ( SELECT MAX( date ) FROM intent_latency_", sep="" ) |
| 73 | command1 <- paste( command1, flowObjFileModifier, sep="" ) |
| 74 | command1 <- paste( command1, "tests WHERE branch='", sep="" ) |
| 75 | command1 <- paste( command1, args[ 7 ], sep="" ) |
| 76 | command1 <- paste( command1, "')", sep="" ) |
| 77 | |
| 78 | print( paste( "Sending SQL command:", command1 ) ) |
| 79 | |
| 80 | fileData1 <- dbGetQuery( con, command1 ) |
| 81 | |
| 82 | command2 <- paste( "SELECT * FROM intent_reroute_latency_", flowObjFileModifier, sep="" ) |
| 83 | command2 <- paste( command2, "tests WHERE batch_size=", sep="" ) |
| 84 | command2 <- paste( command2, args[ 8 ], sep="" ) |
| 85 | command2 <- paste( command2, " AND branch = '", sep="" ) |
| 86 | command2 <- paste( command2, args[ 7 ], sep="" ) |
| 87 | command2 <- paste( command2, "' AND date IN ( SELECT MAX( date ) FROM intent_reroute_latency_", sep="" ) |
| 88 | command2 <- paste( command2, flowObjFileModifier, sep="" ) |
| 89 | command2 <- paste( command2, "tests WHERE branch='", sep="" ) |
| 90 | command2 <- paste( command2, args[ 7 ], sep="" ) |
| 91 | command2 <- paste( command2, "')", sep="" ) |
| 92 | |
| 93 | print( paste( "Sending SQL command:", command2 ) ) |
| 94 | |
| 95 | fileData2 <- dbGetQuery( con, command2 ) |
| 96 | |
| 97 | # ********************************************************** |
| 98 | # STEP 2: Organize data. |
| 99 | # ********************************************************** |
| 100 | |
| 101 | print( "STEP 2: Organize data." ) |
| 102 | |
| 103 | # Create lists c() and organize data into their corresponding list. |
| 104 | print( "Sorting data." ) |
| 105 | if ( ncol( fileData2 ) == 0 ){ |
| 106 | avgs <- c( fileData1[ 'install_avg' ], fileData1[ 'withdraw_avg' ] ) |
| 107 | } else{ |
| 108 | colnames( fileData2 ) <- c( "date", "name", "date", "branch", "commit", "scale", "batch_size", "reroute_avg", "reroute_std" ) |
| 109 | avgs <- c( fileData1[ 'install_avg' ], fileData1[ 'withdraw_avg' ], fileData2[ 'reroute_avg' ] ) |
| 110 | } |
| 111 | |
| 112 | # Parse lists into data frames. |
| 113 | dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame |
| 114 | |
| 115 | if ( ncol( fileData2 ) == 0 ){ |
| 116 | dataFrame$scale <- c( fileData1$scale, fileData1$scale ) # Add node scaling to the data frame. |
| 117 | dataFrame$stds <- c( fileData1$install_std, fileData1$withdraw_std ) |
| 118 | } else{ |
| 119 | dataFrame$scale <- c( fileData1$scale, fileData1$scale, fileData2$scale ) # Add node scaling to the data frame. |
| 120 | dataFrame$stds <- c( fileData1$install_std, fileData1$withdraw_std, fileData2$reroute_std ) |
| 121 | } |
| 122 | colnames( dataFrame ) <- c( "ms", "type", "scale", "stds" ) |
| 123 | |
| 124 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 125 | dataFrame$type <- as.character( dataFrame$type ) |
| 126 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 127 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 128 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 129 | |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 130 | |
| 131 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 132 | print( "Data Frame Results:" ) |
| 133 | print( dataFrame ) |
| 134 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 135 | # ********************************************************** |
| 136 | # STEP 3: Generate graphs. |
| 137 | # ********************************************************** |
| 138 | |
| 139 | print( "STEP 3: Generate graphs." ) |
| 140 | |
| 141 | # 1. Graph fundamental data is generated first. |
| 142 | # These are variables that apply to all of the graphs being generated, regardless of type. |
| 143 | # |
| 144 | # 2. Type specific graph data is generated. |
| 145 | # Data specific for the error bar and stacked bar graphs are generated. |
| 146 | # |
| 147 | # 3. Generate and save the graphs. |
| 148 | # Graphs are saved to the filename above, in the directory provided in command line args |
| 149 | |
| 150 | print( "Generating fundamental graph data." ) |
| 151 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 152 | theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph. |
| 153 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 154 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = ms, ymin = ms - stds, ymax = ms + stds,fill = type ) ) |
| 155 | |
| 156 | # Formatting the plot |
| 157 | width <- 1.3 # Width of the bars. |
| 158 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 159 | xLabel <- xlab( "Scale" ) |
| 160 | yLabel <- ylab( "Latency (ms)" ) |
| 161 | fillLabel <- labs( fill="Type" ) |
| 162 | chartTitle <- "Intent Install, Withdraw, & Reroute Latencies" |
| 163 | if ( args[ 1 ] == "y" ){ |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 164 | chartTitle <- paste( chartTitle, "w/ FlowObj" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 165 | } |
| 166 | chartTitle <- paste( chartTitle, "\nBatch Size =" ) |
| 167 | chartTitle <- paste( chartTitle, fileData1[ 1,'batch_size' ] ) |
| 168 | |
Jeremy Ronquillo | be37f09 | 2017-09-26 13:30:05 -0700 | [diff] [blame] | 169 | theme <- theme( plot.title=element_text( hjust = 0.5, size = 22, face='bold' ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 170 | |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 171 | |
| 172 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 173 | # Store plot configurations as 1 variable |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 174 | fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 175 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 176 | # Create the bar graph with error bars. |
| 177 | # geom_bar contains: |
| 178 | # - stat: data formatting (usually "identity") |
| 179 | # - width: the width of the bar types (declared above) |
| 180 | # geom_errorbar contains similar arguments as geom_bar. |
| 181 | print( "Generating bar graph with error bars." ) |
| 182 | barGraphFormat <- geom_bar( stat = "identity", width = width, position = "dodge" ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 183 | errorBarFormat <- geom_errorbar( width = width, position = "dodge", color=rgb( 140, 140, 140, maxColorValue=255 ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 184 | title <- ggtitle( chartTitle ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 185 | values <- geom_text( aes( x=dataFrame$scale, y=dataFrame$ms + 0.035 * max( dataFrame$ms ), label = format( dataFrame$ms, digits=3, big.mark = ",", scientific = FALSE ) ), position=position_dodge( width=1.3 ), size = 3.2, fontface = "bold" ) |
| 186 | |
| 187 | result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title + values |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 188 | |
| 189 | # Save graph to file |
| 190 | print( paste( "Saving bar chart with error bars to", errBarOutputFile ) ) |
| 191 | ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 ) |
| 192 | print( paste( "Successfully wrote bar chart with error bars out to", errBarOutputFile ) ) |