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