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, |
| 21 | # please contact Jeremy Ronquillo: jeremyr@opennetworking.org |
| 22 | |
| 23 | # ********************************************************** |
| 24 | # STEP 1: File management. |
| 25 | # ********************************************************** |
| 26 | |
| 27 | print( "STEP 1: File management." ) |
| 28 | |
| 29 | # Command line arguments are read. Args usually include the database filename and the output |
| 30 | # directory for the graphs to save to. |
| 31 | # ie: Rscript SCPFgraphGenerator SCPFsampleDataDB.csv ~/tmp/ |
| 32 | print( "Reading commmand-line args." ) |
| 33 | args <- commandArgs( trailingOnly=TRUE ) |
| 34 | |
| 35 | # Import libraries to be used for graphing and organizing data, respectively. |
| 36 | # Find out more about ggplot2: https://github.com/tidyverse/ggplot2 |
| 37 | # reshape2: https://github.com/hadley/reshape |
| 38 | print( "Importing libraries." ) |
| 39 | library( ggplot2 ) |
| 40 | library( reshape2 ) |
| 41 | library( RPostgreSQL ) # For databases |
| 42 | |
| 43 | # Check if sufficient args are provided. |
| 44 | if ( is.na( args[ 7 ] ) ){ |
| 45 | print( "Usage: Rscript SCPFportLat <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <directory-to-save-graphs>" ) |
| 46 | q() # basically exit(), but in R |
| 47 | } |
| 48 | |
| 49 | # Filenames for output graphs include the testname and the graph type. |
| 50 | # See the examples below. paste() is used to concatenate strings. |
| 51 | errBarOutputFileUp <- paste( args[ 7 ], "SCPFportLat_", sep = "" ) |
| 52 | errBarOutputFileUp <- paste( errBarOutputFileUp, args[ 6 ], sep = "" ) |
| 53 | errBarOutputFileUp <- paste( errBarOutputFileUp, "_UpErrBarWithStack.jpg", sep = "" ) |
| 54 | |
| 55 | errBarOutputFileDown <- paste( args[ 7 ], "SCPFportLat_", sep = "" ) |
| 56 | errBarOutputFileDown <- paste( errBarOutputFileDown, args[ 6 ], sep = "" ) |
| 57 | errBarOutputFileDown <- paste( errBarOutputFileDown, "_DownErrBarWithStack.jpg", sep = "" ) |
| 58 | |
| 59 | print( "Reading from databases." ) |
| 60 | |
| 61 | con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] ) |
| 62 | |
| 63 | command <- paste( "SELECT * FROM port_latency_details WHERE branch = '", args[ 6 ], sep = "" ) |
| 64 | command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM port_latency_details WHERE branch = '", sep = "" ) |
| 65 | command <- paste( command, args[ 6 ], sep = "" ) |
| 66 | command <- paste( command, "' ) ", sep="" ) |
| 67 | |
| 68 | print( paste( "Sending SQL command:", command ) ) |
| 69 | |
| 70 | fileData <- dbGetQuery( con, command ) |
| 71 | |
| 72 | chartTitle <- paste( "Port Latency", args[ 6 ], sep = " - " ) |
| 73 | chartTitle <- paste( chartTitle, "\n" ) |
| 74 | |
| 75 | |
| 76 | # ********************************************************** |
| 77 | # STEP 2: Organize data. |
| 78 | # ********************************************************** |
| 79 | |
| 80 | print( "Sorting data." ) |
| 81 | |
| 82 | upAvgs <- c( fileData[ 'up_ofp_to_dev_avg' ], fileData[ 'up_dev_to_link_avg' ], fileData[ 'up_link_to_graph_avg' ] ) |
| 83 | upAvgsData <- melt( upAvgs ) |
| 84 | upAvgsData$scale <- fileData$scale |
| 85 | upAvgsData$up_std <- fileData$up_std |
| 86 | |
| 87 | |
| 88 | colnames( upAvgsData ) <- c( "ms", "type", "scale", "stds" ) |
| 89 | upAvgsData$type <- as.character( upAvgsData$type ) |
| 90 | upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) ) |
| 91 | |
| 92 | downAvgs <- c( fileData[ 'down_ofp_to_dev_avg' ], fileData[ 'down_dev_to_link_avg' ], fileData[ 'down_link_to_graph_avg' ] ) |
| 93 | downAvgsData <- melt( downAvgs ) |
| 94 | downAvgsData$scale <- fileData$scale |
| 95 | downAvgsData$down_std <- fileData$down_std |
| 96 | |
| 97 | colnames( downAvgsData ) <- c( "ms", "type", "scale", "stds" ) |
| 98 | downAvgsData$type <- as.character( downAvgsData$type ) |
| 99 | downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) ) |
| 100 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 101 | upAvgsData <- na.omit( upAvgsData ) # Omit any data that doesn't exist |
| 102 | downAvgsData <- na.omit( downAvgsData ) # Omit any data that doesn't exist |
| 103 | |
| 104 | print( "Up Averages Results:" ) |
| 105 | print( upAvgsData ) |
| 106 | |
| 107 | print( "Down Averages Results:" ) |
| 108 | print( downAvgsData ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 109 | |
| 110 | # ********************************************************** |
| 111 | # STEP 3: Generate graphs. |
| 112 | # ********************************************************** |
| 113 | |
| 114 | |
| 115 | print( "Generating fundamental graph data (Port Up Latency)." ) |
| 116 | width <- 1 |
| 117 | if ( min( fileData[ 'up_end_to_end_avg' ] - upAvgsData$stds ) < 0 ) { |
| 118 | yMin <- min( fileData[ 'up_end_to_end_avg' ] - upAvgsData$stds ) * 1.05 |
| 119 | } else { |
| 120 | yMin <- 0 |
| 121 | } |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 122 | theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph. |
| 123 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 124 | yMax <- max( fileData[ 'up_end_to_end_avg' ] + upAvgsData$stds ) |
| 125 | |
| 126 | mainPlot <- ggplot( data = upAvgsData, aes( x = scale, y = ms, fill = type, ymin = fileData[ 'up_end_to_end_avg' ] - stds, ymax = fileData[ 'up_end_to_end_avg' ] + stds ) ) |
| 127 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) ) |
| 128 | yLimit <- ylim( yMin, yMax ) |
| 129 | xLabel <- xlab( "Scale" ) |
| 130 | yLabel <- ylab( "Latency (ms)" ) |
| 131 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 132 | theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 133 | |
| 134 | fundamentalGraphData <- mainPlot + yLimit + xScaleConfig + xLabel + yLabel + fillLabel + theme |
| 135 | |
| 136 | print( "Generating bar graph with error bars (Port Up Latency)." ) |
| 137 | barGraphFormat <- geom_bar( stat="identity", width = width ) |
| 138 | errorBarFormat <- geom_errorbar( width = width ) |
| 139 | |
| 140 | title <- ggtitle( "Port Up Latency" ) |
| 141 | result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title |
| 142 | |
| 143 | |
| 144 | print( paste( "Saving bar chart with error bars (Port Up Latency) to", errBarOutputFileUp ) ) |
| 145 | ggsave( errBarOutputFileUp, width = 10, height = 6, dpi = 200 ) |
| 146 | |
| 147 | |
| 148 | print( paste( "Successfully wrote bar chart with error bars (Port Up Latency) out to", errBarOutputFileUp ) ) |
| 149 | |
| 150 | |
| 151 | print( "Generating fundamental graph data (Port Down Latency)." ) |
| 152 | if ( min( fileData[ 'down_end_to_end_avg' ] - downAvgsData$stds ) < 0 ) { |
| 153 | yMin <- min( fileData[ 'down_end_to_end_avg' ] - downAvgsData$stds ) |
| 154 | } else { |
| 155 | yMin <- 0 |
| 156 | } |
| 157 | yMax <- max( fileData[ 'down_end_to_end_avg' ] + downAvgsData$stds ) |
| 158 | |
| 159 | mainPlot <- ggplot( data = downAvgsData, aes( x = scale, y = ms, fill = type, ymin = fileData[ 'down_end_to_end_avg' ] - stds, ymax = fileData[ 'down_end_to_end_avg' ] + stds ) ) |
| 160 | yLimit <- ylim( yMin, yMax ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 161 | theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 162 | |
| 163 | fundamentalGraphData <- mainPlot + yLimit + xScaleConfig + xLabel + yLabel + fillLabel + theme |
| 164 | |
| 165 | print( "Generating bar graph with error bars (Port Down Latency)." ) |
| 166 | barGraphFormat <- geom_bar( stat="identity", width = width ) |
| 167 | errorBarFormat <- geom_errorbar( width = width ) |
| 168 | |
| 169 | title <- ggtitle( "Port Down Latency" ) |
| 170 | result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title |
| 171 | |
| 172 | |
| 173 | print( paste( "Saving bar chart with error bars (Port Down Latency) to", errBarOutputFileDown ) ) |
| 174 | ggsave( errBarOutputFileDown, width = 10, height = 6, dpi = 200 ) |
| 175 | |
| 176 | |
| 177 | print( paste( "Successfully wrote bar chart with error bars (Port Down Latency) out to", errBarOutputFileDown ) ) |