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 SCPFbatchFlowResp <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 | errBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" ) |
| 49 | errBarOutputFile <- paste( errBarOutputFile, args[ 6 ], sep="_" ) |
| 50 | errBarOutputFile <- paste( errBarOutputFile, "_PostGraph.jpg", sep="" ) |
| 51 | |
| 52 | print( "Reading from databases." ) |
| 53 | |
| 54 | con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] ) |
| 55 | |
| 56 | command <- paste( "SELECT * FROM batch_flow_tests WHERE branch='", args[ 6 ], sep="" ) |
| 57 | command <- paste( command, "' ORDER BY date DESC LIMIT 3", sep="" ) |
| 58 | |
| 59 | print( paste( "Sending SQL command:", command ) ) |
| 60 | |
| 61 | fileData <- dbGetQuery( con, command ) |
| 62 | |
| 63 | chartTitle <- paste( "Single Bench Flow Latency - Post", "Last 3 Builds", sep = "\n" ) |
| 64 | |
| 65 | # ********************************************************** |
| 66 | # STEP 2: Organize data. |
| 67 | # ********************************************************** |
| 68 | |
| 69 | avgs <- c() |
| 70 | |
| 71 | print( "Sorting data." ) |
| 72 | avgs <- c( fileData[ 'posttoconfrm' ], fileData[ 'elapsepost' ] ) |
| 73 | |
| 74 | dataFrame <- melt( avgs ) |
| 75 | dataFrame$scale <- fileData$scale |
| 76 | dataFrame$date <- fileData$date |
| 77 | dataFrame$iterative <- dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) ) |
| 78 | |
| 79 | colnames( dataFrame ) <- c( "ms", "type", "scale", "date", "iterative" ) |
| 80 | |
| 81 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 82 | dataFrame$type <- as.character( dataFrame$type ) |
| 83 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 84 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 85 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 86 | |
| 87 | print( "Data Frame Results:" ) |
| 88 | print( dataFrame ) |
| 89 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 90 | # ********************************************************** |
| 91 | # STEP 3: Generate graphs. |
| 92 | # ********************************************************** |
| 93 | |
| 94 | print( "Generating fundamental graph data." ) |
| 95 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 96 | theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph. |
| 97 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 98 | mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = ms, fill = type ) ) |
| 99 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$date ) |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 100 | xLabel <- xlab( "Build Date" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 101 | yLabel <- ylab( "Latency (ms)" ) |
| 102 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 103 | 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] | 104 | |
| 105 | fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme |
| 106 | |
| 107 | |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 108 | print( "Generating bar graph." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 109 | width <- 0.3 |
| 110 | barGraphFormat <- geom_bar( stat="identity", width = width ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 111 | sum <- fileData[ 'posttoconfrm' ] + fileData[ 'elapsepost' ] |
| 112 | values <- geom_text( aes( x=dataFrame$iterative, y=sum + 0.04 * max( sum ), label = format( sum, digits=3, big.mark = ",", scientific = FALSE ) ), size = 5, fontface = "bold" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 113 | title <- ggtitle( chartTitle ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 114 | result <- fundamentalGraphData + barGraphFormat + title + values |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 115 | |
| 116 | |
| 117 | print( paste( "Saving bar chart to", errBarOutputFile ) ) |
| 118 | ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 ) |
| 119 | |
| 120 | print( paste( "Successfully wrote stacked bar chart out to", errBarOutputFile ) ) |
| 121 | |
| 122 | |
| 123 | # ********************************************************** |
| 124 | # STEP 2: Organize data. |
| 125 | # ********************************************************** |
| 126 | |
| 127 | avgs <- c() |
| 128 | |
| 129 | print( "Sorting data." ) |
| 130 | avgs <- c( fileData[ 'deltoconfrm' ], fileData[ 'elapsedel' ] ) |
| 131 | |
| 132 | dataFrame <- melt( avgs ) |
| 133 | dataFrame$scale <- fileData$scale |
| 134 | dataFrame$date <- fileData$date |
| 135 | dataFrame$iterative <- dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) ) |
| 136 | |
| 137 | colnames( dataFrame ) <- c( "ms", "type", "scale", "date", "iterative" ) |
| 138 | |
| 139 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 140 | dataFrame$type <- as.character( dataFrame$type ) |
| 141 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 142 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 143 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 144 | |
| 145 | print( "Data Frame Results:" ) |
| 146 | print( dataFrame ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 147 | |
| 148 | # ********************************************************** |
| 149 | # STEP 3: Generate graphs. |
| 150 | # ********************************************************** |
| 151 | |
| 152 | print( "Generating fundamental graph data." ) |
| 153 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 154 | theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph. |
| 155 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 156 | mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = ms, fill = type ) ) |
| 157 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$date ) |
| 158 | xLabel <- xlab( "Build Date" ) |
| 159 | yLabel <- ylab( "Latency (ms)" ) |
| 160 | fillLabel <- labs( fill="Type" ) |
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 + xScaleConfig + xLabel + yLabel + fillLabel + theme |
| 164 | |
| 165 | |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 166 | print( "Generating bar graph." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 167 | width <- 0.3 |
| 168 | barGraphFormat <- geom_bar( stat="identity", width = width ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 169 | sum <- fileData[ 'deltoconfrm' ] + fileData[ 'elapsedel' ] |
| 170 | values <- geom_text( aes( x=dataFrame$iterative, y=sum + 0.04 * max( sum ), label = format( sum, digits=3, big.mark = ",", scientific = FALSE ) ), size = 5, fontface = "bold" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 171 | chartTitle <- paste( "Single Bench Flow Latency - Del", "Last 3 Builds", sep = "\n" ) |
| 172 | title <- ggtitle( chartTitle ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 173 | result <- fundamentalGraphData + barGraphFormat + title + values |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 174 | |
| 175 | errBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" ) |
| 176 | errBarOutputFile <- paste( errBarOutputFile, args[ 6 ], sep="_" ) |
| 177 | errBarOutputFile <- paste( errBarOutputFile, "_DelGraph.jpg", sep="" ) |
| 178 | |
| 179 | print( paste( "Saving bar chart to", errBarOutputFile ) ) |
| 180 | ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 ) |
| 181 | |
| 182 | print( paste( "Successfully wrote stacked bar chart out to", errBarOutputFile ) ) |