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 SCPFgraphGenerator <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 | outputFile <- paste( args[ 7 ], args[ 5 ], sep="" ) |
| 49 | outputFile <- paste( outputFile, args[ 6 ], sep="_" ) |
| 50 | outputFile <- paste( outputFile, "_graph.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 scale_topo_latency_details WHERE branch = '", args[ 6 ], sep = "" ) |
| 57 | command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM scale_topo_latency_details WHERE branch = '", sep = "" ) |
| 58 | command <- paste( command, args[ 6 ], sep = "" ) |
| 59 | command <- paste( command, "' ) ", sep="" ) |
| 60 | |
| 61 | print( paste( "Sending SQL command:", command ) ) |
| 62 | |
| 63 | fileData <- dbGetQuery( con, command ) |
| 64 | |
| 65 | title <- paste( args[ 5 ], args[ 6 ], sep="_" ) |
| 66 | |
| 67 | # ********************************************************** |
| 68 | # STEP 2: Organize data. |
| 69 | # ********************************************************** |
| 70 | |
| 71 | print( "STEP 2: Organize data." ) |
| 72 | |
| 73 | # Create lists c() and organize data into their corresponding list. |
| 74 | print( "Sorting data." ) |
| 75 | avgs <- c( fileData[ 'last_role_request_to_last_topology' ], fileData[ 'last_connection_to_last_role_request' ], fileData[ 'first_connection_to_last_connection' ] ) |
| 76 | |
| 77 | # Parse lists into data frames. |
| 78 | dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 79 | dataFrame$scale <- fileData$scale # Add node scaling to the data frame. |
Devin Lim | 3c2b9d6 | 2017-10-25 11:41:41 -0700 | [diff] [blame^] | 80 | colnames( dataFrame ) <- c( "s", "type", "scale") |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 81 | |
| 82 | |
| 83 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 84 | dataFrame$type <- as.character( dataFrame$type ) |
| 85 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 86 | dataFrame$iterative <- seq( 1, nrow( fileData ), by = 1 ) |
| 87 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 88 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 89 | |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 90 | sum <- fileData[ 'last_role_request_to_last_topology' ] + fileData[ 'last_connection_to_last_role_request' ] + fileData[ 'first_connection_to_last_connection' ] |
| 91 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 92 | print( "Data Frame Results:" ) |
| 93 | print( dataFrame ) |
| 94 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 95 | # ********************************************************** |
| 96 | # STEP 3: Generate graphs. |
| 97 | # ********************************************************** |
| 98 | |
| 99 | print( "STEP 3: Generate graphs." ) |
| 100 | |
| 101 | # 1. Graph fundamental data is generated first. |
| 102 | # These are variables that apply to all of the graphs being generated, regardless of type. |
| 103 | # |
| 104 | # 2. Type specific graph data is generated. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 105 | # |
| 106 | # 3. Generate and save the graphs. |
| 107 | # Graphs are saved to the filename above, in the directory provided in command line args |
| 108 | |
| 109 | print( "Generating fundamental graph data." ) |
| 110 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 111 | theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph. |
| 112 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 113 | # Create the primary plot here. |
| 114 | # ggplot contains the following arguments: |
| 115 | # - data: the data frame that the graph will be based off of |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 116 | # - aes: the asthetics of the graph which require: |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 117 | # - x: x-axis values (usually node scaling) |
| 118 | # - y: y-axis values (usually time in milliseconds) |
| 119 | # - fill: the category of the colored side-by-side bars (usually type) |
Devin Lim | 3c2b9d6 | 2017-10-25 11:41:41 -0700 | [diff] [blame^] | 120 | mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = s, fill = type ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 121 | |
| 122 | # Formatting the plot |
| 123 | width <- 0.6 # Width of the bars. |
| 124 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$scale ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 125 | xLabel <- xlab( "Scale" ) |
Devin Lim | 3c2b9d6 | 2017-10-25 11:41:41 -0700 | [diff] [blame^] | 126 | yLabel <- ylab( "Latency (s)" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 127 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 128 | chartTitle <- paste( "Scale Topology Latency Test" ) |
| 129 | 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] | 130 | values <- geom_text( aes( x=dataFrame$iterative, y=sum + 0.02 * max( sum ), label = format( sum, big.mark = ",", scientific = FALSE ), fontface = "bold" ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 131 | |
| 132 | # Store plot configurations as 1 variable |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 133 | fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme + values |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 134 | |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 135 | print( "Generating bar graph." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 136 | barGraphFormat <- geom_bar( stat = "identity", width = width ) |
| 137 | title <- ggtitle( paste( chartTitle, "" ) ) |
| 138 | result <- fundamentalGraphData + barGraphFormat + title |
| 139 | |
| 140 | # Save graph to file |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 141 | print( paste( "Saving bar chart to", outputFile ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 142 | ggsave( outputFile, width = 10, height = 6, dpi = 200 ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 143 | print( paste( "Successfully wrote bar chart out to", outputFile ) ) |