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 | # Normal usage |
| 44 | # Check if sufficient args are provided. |
| 45 | if ( is.na( args[ 9 ] ) ){ |
| 46 | print( "Usage: Rscript SCPFIntentEventTp.R <has-flow-obj> <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <has-neighbors> <directory-to-save-graphs>" ) |
| 47 | q() # basically exit(), but in R |
| 48 | } |
| 49 | |
| 50 | # Filenames for output graphs include the testname and the graph type. |
| 51 | # See the examples below. paste() is used to concatenate strings. |
| 52 | |
| 53 | errBarOutputFile <- paste( args[ 9 ], args[ 6 ], sep="" ) |
| 54 | errBarOutputFile <- paste( errBarOutputFile, args[ 7 ], sep="_" ) |
| 55 | if ( args[ 8 ] == 'y' ){ |
| 56 | errBarOutputFile <- paste( errBarOutputFile, "all-neighbors", sep="_" ) |
| 57 | } else { |
| 58 | errBarOutputFile <- paste( errBarOutputFile, "no-neighbors", sep="_" ) |
| 59 | } |
| 60 | if ( args[ 1 ] == 'y' ){ |
| 61 | errBarOutputFile <- paste( errBarOutputFile, "flowObj", sep="_") |
| 62 | } |
| 63 | errBarOutputFile <- paste( errBarOutputFile, "_graph.jpg", sep="" ) |
| 64 | |
| 65 | print( "Reading from databases." ) |
| 66 | con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 2 ], port=strtoi( args[ 3 ] ), user=args[ 4 ],password=args[ 5 ] ) |
| 67 | |
| 68 | commandNeighborModifier <- "" |
| 69 | flowObjModifier <- "" |
| 70 | if ( args[ 1 ] == 'y' ){ |
| 71 | flowObjModifier <- "_fobj" |
| 72 | } |
| 73 | if ( args[ 8 ] == 'y' ){ |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 74 | commandNeighborModifier <- "scale=1 OR NOT " |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 77 | command <- paste( "SELECT scale, SUM( avg ) as avg FROM intent_tp", flowObjModifier, sep="" ) |
| 78 | command <- paste( command, "_tests WHERE (", sep="" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 79 | command <- paste( command, commandNeighborModifier, sep="" ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 80 | command <- paste( command, "neighbors = 0 ) AND branch = '", sep="") |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 81 | command <- paste( command, args[ 7 ], sep="" ) |
| 82 | command <- paste( command, "' AND date IN ( SELECT max( date ) FROM intent_tp", sep="" ) |
| 83 | command <- paste( command, flowObjModifier, sep="" ) |
| 84 | command <- paste( command, "_tests WHERE branch='", sep="" ) |
| 85 | command <- paste( command, args[ 7 ], sep="" ) |
| 86 | command <- paste( command, "' ) GROUP BY scale ORDER BY scale", sep="" ) |
| 87 | |
| 88 | print( paste( "Sending SQL command:", command ) ) |
| 89 | |
| 90 | fileData <- dbGetQuery( con, command ) |
| 91 | |
| 92 | title <- paste( args[ 6 ], args[ 7 ], sep="_" ) |
| 93 | |
| 94 | # ********************************************************** |
| 95 | # STEP 2: Organize data. |
| 96 | # ********************************************************** |
| 97 | |
| 98 | print( "STEP 2: Organize data." ) |
| 99 | |
| 100 | # Create lists c() and organize data into their corresponding list. |
| 101 | print( "Sorting data." ) |
| 102 | avgs <- c( fileData[ 'avg' ] ) |
| 103 | |
| 104 | # Parse lists into data frames. |
| 105 | dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame |
| 106 | dataFrame$scale <- fileData$scale # Add node scaling to the data frame. |
| 107 | |
| 108 | colnames( dataFrame ) <- c( "throughput", "type", "scale" ) |
| 109 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 110 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 111 | |
| 112 | print( "Data Frame Results:" ) |
| 113 | print( dataFrame ) |
| 114 | |
| 115 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 116 | # ********************************************************** |
| 117 | # STEP 3: Generate graphs. |
| 118 | # ********************************************************** |
| 119 | |
| 120 | print( "STEP 3: Generate graphs." ) |
| 121 | |
| 122 | # 1. Graph fundamental data is generated first. |
| 123 | # These are variables that apply to all of the graphs being generated, regardless of type. |
| 124 | # |
| 125 | # 2. Type specific graph data is generated. |
| 126 | # Data specific for the error bar and stacked bar graphs are generated. |
| 127 | # |
| 128 | # 3. Generate and save the graphs. |
| 129 | # Graphs are saved to the filename above, in the directory provided in command line args |
| 130 | |
| 131 | print( "Generating fundamental graph data." ) |
| 132 | |
| 133 | # Create the primary plot here. |
| 134 | # ggplot contains the following arguments: |
| 135 | # - data: the data frame that the graph will be based off of |
| 136 | # - aes: the asthetics of the graph which require: |
| 137 | # - x: x-axis values (usually node scaling) |
| 138 | # - y: y-axis values (usually time in milliseconds) |
| 139 | # - fill: the category of the colored side-by-side bars (usually type) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 140 | theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph. |
| 141 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 142 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = throughput, fill = type ) ) |
| 143 | |
| 144 | # Formatting the plot |
| 145 | width <- 0.7 # Width of the bars. |
| 146 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$scale, label = dataFrame$scale ) |
| 147 | xLabel <- xlab( "Scale" ) |
| 148 | yLabel <- ylab( "Throughput (events/second)" ) |
| 149 | fillLabel <- labs( fill="Type" ) |
| 150 | chartTitle <- "Intent Event Throughput" |
| 151 | if ( args[ 1 ] == 'y' ){ |
| 152 | chartTitle <- paste( chartTitle, " With Flow Objectives", sep="" ) |
| 153 | } |
| 154 | chartTitle <- paste( chartTitle, "\nevents/second with Neighbors =", sep="" ) |
| 155 | if ( args[ 8 ] == 'y' ){ |
| 156 | chartTitle <- paste( chartTitle, "all" ) |
| 157 | } else { |
| 158 | chartTitle <- paste( chartTitle, "0" ) |
| 159 | } |
| 160 | |
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 | # Store plot configurations as 1 variable |
| 164 | fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme |
| 165 | |
| 166 | |
| 167 | # Create the stacked bar graph with error bars. |
| 168 | # geom_bar contains: |
| 169 | # - stat: data formatting (usually "identity") |
| 170 | # - width: the width of the bar types (declared above) |
| 171 | # geom_errorbar contains similar arguments as geom_bar. |
| 172 | print( "Generating bar graph." ) |
| 173 | barGraphFormat <- geom_bar( stat = "identity", width = width, fill="#169EFF" ) |
| 174 | title <- ggtitle( paste( chartTitle, "" ) ) |
| 175 | result <- fundamentalGraphData + barGraphFormat + title |
| 176 | |
| 177 | # Save graph to file |
| 178 | print( paste( "Saving bar chart to", errBarOutputFile ) ) |
| 179 | ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 ) |
| 180 | |
| 181 | print( paste( "Successfully wrote bar chart out to", errBarOutputFile ) ) |