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[ 7 ] ) ){ |
| 43 | print( "Usage: Rscript SCPFswitchLat <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <directory-to-save-graphs>" ) |
| 44 | q() # basically exit(), but in R |
| 45 | } |
| 46 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 47 | # paste() is used to concatenate strings. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 48 | errBarOutputFileUp <- paste( args[ 7 ], "SCPFswitchLat_", sep = "" ) |
| 49 | errBarOutputFileUp <- paste( errBarOutputFileUp, args[ 6 ], sep = "" ) |
| 50 | errBarOutputFileUp <- paste( errBarOutputFileUp, "_UpErrBarWithStack.jpg", sep = "" ) |
| 51 | |
| 52 | errBarOutputFileDown <- paste( args[ 7 ], "SCPFswitchLat_", sep = "" ) |
| 53 | errBarOutputFileDown <- paste( errBarOutputFileDown, args[ 6 ], sep = "" ) |
| 54 | errBarOutputFileDown <- paste( errBarOutputFileDown, "_DownErrBarWithStack.jpg", sep = "" ) |
| 55 | |
| 56 | print( "Reading from databases." ) |
| 57 | |
| 58 | con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] ) |
| 59 | |
| 60 | command <- paste( "SELECT * FROM switch_latency_details WHERE branch = '", args[ 6 ], sep="" ) |
| 61 | command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM switch_latency_details WHERE branch='", sep = "") |
| 62 | command <- paste( command, args[ 6 ], sep="" ) |
| 63 | command <- paste( command, "' )", sep="" ) |
| 64 | |
| 65 | print( paste( "Sending SQL command:", command ) ) |
| 66 | |
| 67 | fileData <- dbGetQuery( con, command ) |
| 68 | |
| 69 | # ********************************************************** |
| 70 | # STEP 2: Organize data. |
| 71 | # ********************************************************** |
| 72 | |
| 73 | print( "Sorting data." ) |
| 74 | |
| 75 | upAvgs <- c( fileData[ 'up_device_to_graph_avg' ], fileData[ 'role_reply_to_device_avg' ], fileData[ 'role_request_to_role_reply_avg' ], fileData[ 'feature_reply_to_role_request_avg' ], fileData[ 'tcp_to_feature_reply_avg' ] ) |
| 76 | upAvgsData <- melt( upAvgs ) |
| 77 | upAvgsData$scale <- fileData$scale |
| 78 | upAvgsData$up_std <- fileData$up_std |
| 79 | |
| 80 | colnames( upAvgsData ) <- c( "ms", "type", "scale", "stds" ) |
| 81 | upAvgsData$type <- as.character( upAvgsData$type ) |
| 82 | upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) ) |
| 83 | |
| 84 | downAvgs <- c( fileData[ 'down_device_to_graph_avg' ], fileData[ 'ack_to_device_avg' ], fileData[ 'fin_ack_to_ack_avg' ] ) |
| 85 | downAvgsData <- melt( downAvgs ) |
| 86 | downAvgsData$scale <- fileData$scale |
| 87 | downAvgsData$down_std <- fileData$down_std |
| 88 | |
| 89 | colnames( downAvgsData ) <- c( "ms", "type", "scale", "stds" ) |
| 90 | downAvgsData$type <- as.character( downAvgsData$type ) |
| 91 | downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) ) |
| 92 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 93 | upAvgsData <- na.omit( upAvgsData ) # Omit any data that doesn't exist |
| 94 | downAvgsData <- na.omit( downAvgsData ) |
| 95 | |
| 96 | print( "Up Averages Results:" ) |
| 97 | print( upAvgsData ) |
| 98 | |
| 99 | print( "Down Averages Results:" ) |
| 100 | print( downAvgsData ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 101 | |
| 102 | # ********************************************************** |
| 103 | # STEP 3: Generate graphs. |
| 104 | # ********************************************************** |
| 105 | |
| 106 | |
| 107 | print( "Generating fundamental graph data (Switch Up Latency)." ) |
| 108 | width <- 1 |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 109 | |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 110 | theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph. |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 111 | |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 112 | mainPlot <- ggplot( data = upAvgsData, aes( x = scale, y = ms, fill = type, ymin = fileData[ 'up_end_to_end_avg' ], ymax = fileData[ 'up_end_to_end_avg' ] + stds ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 113 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 114 | xLabel <- xlab( "Scale" ) |
| 115 | yLabel <- ylab( "Latency (ms)" ) |
| 116 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 117 | theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ), legend.position="bottom", legend.text=element_text( size=22 ), legend.title = element_blank(), legend.key.size = unit( 1.5, 'lines' ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 118 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 119 | fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 120 | |
| 121 | print( "Generating bar graph with error bars (Switch Up Latency)." ) |
| 122 | barGraphFormat <- geom_bar( stat="identity", width = width ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 123 | errorBarFormat <- geom_errorbar( width = width, color=rgb( 140, 140, 140, maxColorValue=255 ) ) |
| 124 | sum <- fileData[ 'up_device_to_graph_avg' ] + fileData[ 'role_reply_to_device_avg' ] + fileData[ 'role_request_to_role_reply_avg' ] + fileData[ 'feature_reply_to_role_request_avg' ] + fileData[ 'tcp_to_feature_reply_avg' ] |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 125 | values <- geom_text( aes( x=upAvgsData$scale, y=sum + 0.04 * max( sum ), label = format( sum, digits=3, big.mark = ",", scientific = FALSE ) ), size = 7.0, fontface = "bold" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 126 | title <- ggtitle( "Switch Up Latency" ) |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 127 | wrapLegend <- guides( fill=guide_legend( nrow=2, byrow=TRUE ) ) |
| 128 | result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title + values + wrapLegend |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 129 | |
| 130 | |
| 131 | print( paste( "Saving bar chart with error bars (Switch Up Latency) to", errBarOutputFileUp ) ) |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 132 | ggsave( errBarOutputFileUp, width = 15, height = 10, dpi = 200 ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 133 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 134 | print( paste( "Successfully wrote bar chart with error bars (Switch Up Latency) out to", errBarOutputFileUp ) ) |
| 135 | |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 136 | # Generate switch down latency graph |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 137 | |
| 138 | print( "Generating fundamental graph data (Switch Down Latency)." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 139 | |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 140 | mainPlot <- ggplot( data = downAvgsData, aes( x = scale, y = ms, fill = type, ymin = fileData[ 'down_end_to_end_avg' ], ymax = fileData[ 'down_end_to_end_avg' ] + stds ) ) |
| 141 | theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ), legend.position="bottom", legend.text=element_text( size=22 ), legend.title = element_blank(), legend.key.size = unit( 1.5, 'lines' ) ) |
| 142 | colors <- scale_fill_manual( values=c( "#F77670", "#619DFA", "#18BA48" ) ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 143 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 144 | fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 145 | |
| 146 | print( "Generating bar graph with error bars (Switch Down Latency)." ) |
| 147 | barGraphFormat <- geom_bar( stat="identity", width = width ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 148 | errorBarFormat <- geom_errorbar( width = width, color=rgb( 140, 140, 140, maxColorValue=255 ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 149 | |
| 150 | title <- ggtitle( "Switch Down Latency" ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 151 | sum <- fileData[ 'down_device_to_graph_avg' ] + fileData[ 'ack_to_device_avg' ] + fileData[ 'fin_ack_to_ack_avg' ] |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 152 | values <- geom_text( aes( x=downAvgsData$scale, y=sum + 0.04 * max( sum ), label = format( sum, digits=3, big.mark = ",", scientific = FALSE ) ), size = 7.0, fontface = "bold" ) |
| 153 | wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) ) |
| 154 | result <- fundamentalGraphData + barGraphFormat + colors + errorBarFormat + title + values + wrapLegend |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 155 | |
| 156 | print( paste( "Saving bar chart with error bars (Switch Down Latency) to", errBarOutputFileDown ) ) |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 157 | ggsave( errBarOutputFileDown, width = 15, height = 10, dpi = 200 ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 158 | |
| 159 | |
| 160 | print( paste( "Successfully wrote bar chart with error bars (Switch Down Latency) out to", errBarOutputFileDown ) ) |