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