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 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 41 | # Check if sufficient args are provided. |
| 42 | if ( is.na( args[ 7 ] ) ){ |
| 43 | print( "Usage: Rscript SCPFmastershipFailoverLat <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, "_errGraph.jpg", sep="" ) |
| 51 | |
| 52 | stackedBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" ) |
| 53 | stackedBarOutputFile <- paste( stackedBarOutputFile, args[ 6 ], sep="_" ) |
| 54 | stackedBarOutputFile <- paste( stackedBarOutputFile, "_stackedGraph.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 mastership_failover_tests WHERE branch = '", args[ 6 ], sep = "" ) |
| 61 | command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM mastership_failover_tests WHERE branch = '", sep = "" ) |
| 62 | command <- paste( command, args[ 6 ], sep = "" ) |
| 63 | command <- paste( command, "' ) ", sep="" ) |
| 64 | |
| 65 | print( paste( "Sending SQL command:", command ) ) |
| 66 | |
| 67 | fileData <- dbGetQuery( con, command ) |
| 68 | |
| 69 | chartTitle <- "Mastership Failover Latency" |
| 70 | |
| 71 | |
| 72 | # ********************************************************** |
| 73 | # STEP 2: Organize data. |
| 74 | # ********************************************************** |
| 75 | |
| 76 | fileDataNames <- names( fileData ) |
| 77 | |
| 78 | avgs <- c() |
| 79 | stds <- c() |
| 80 | |
| 81 | |
| 82 | print( "Sorting data." ) |
| 83 | for ( name in fileDataNames ){ |
| 84 | nameLen <- nchar( name ) |
| 85 | if ( nameLen > 2 ){ |
| 86 | if ( substring( name, nameLen - 2, nameLen ) == "avg" ){ |
| 87 | avgs <- c( avgs, fileData[ name ] ) |
| 88 | } |
| 89 | if ( substring( name, nameLen - 2, nameLen ) == "std" ){ |
| 90 | stds <- c( stds, fileData[ name ] ) |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | avgData <- melt( avgs ) |
| 96 | avgData$scale <- fileData$scale |
| 97 | colnames( avgData ) <- c( "ms", "type", "scale" ) |
| 98 | |
| 99 | stdData <- melt( stds ) |
| 100 | colnames( stdData ) <- c( "ms", "type" ) |
| 101 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 102 | dataFrame <- na.omit( avgData ) # Omit any data that doesn't exist |
| 103 | |
| 104 | print( "Data Frame Results:" ) |
| 105 | print( avgData ) |
| 106 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 107 | |
| 108 | # ********************************************************** |
| 109 | # STEP 3: Generate graphs. |
| 110 | # ********************************************************** |
| 111 | |
| 112 | print( "Generating fundamental graph data." ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 113 | |
| 114 | theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 115 | |
| 116 | mainPlot <- ggplot( data = avgData, aes( x = scale, y = ms, ymin = ms - stdData$ms, ymax = ms + stdData$ms,fill = type ) ) |
| 117 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 118 | xLabel <- xlab( "Scale" ) |
| 119 | yLabel <- ylab( "Latency (ms)" ) |
| 120 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 121 | 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] | 122 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 123 | fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 124 | |
| 125 | |
| 126 | print( "Generating bar graph with error bars." ) |
| 127 | width <- 0.9 |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 128 | barGraphFormat <- geom_bar( stat="identity", position=position_dodge(), width = width ) |
| 129 | errorBarFormat <- geom_errorbar( width = width, position=position_dodge(), color=rgb( 140, 140, 140, maxColorValue=255 ) ) |
| 130 | values <- geom_text( aes( x=avgData$scale, y=avgData$ms + 0.04 * max( avgData$ms ), label = format( avgData$ms, digits=3, big.mark = ",", scientific = FALSE ) ), size = 5, fontface = "bold", position=position_dodge( 0.9 ) ) |
| 131 | title <- ggtitle( paste( chartTitle, "" ) ) |
| 132 | result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title + values |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 133 | |
| 134 | |
| 135 | print( paste( "Saving bar chart with error bars to", errBarOutputFile ) ) |
| 136 | ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 ) |
| 137 | |
| 138 | |
| 139 | print( paste( "Successfully wrote bar chart with error bars out to", errBarOutputFile ) ) |
| 140 | |
| 141 | |
| 142 | print( "Generating stacked bar chart." ) |
| 143 | stackedBarFormat <- geom_bar( stat="identity", width=width ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 144 | title <- ggtitle( paste( chartTitle, "" ) ) |
| 145 | sum <- fileData[ 'deact_role_avg' ] + fileData[ 'kill_deact_avg' ] |
| 146 | values <- geom_text( aes( x=avgData$scale, y=sum + 0.04 * max( sum ), label = format( sum, digits=3, big.mark = ",", scientific = FALSE ) ), size = 5, fontface = "bold" ) |
| 147 | result <- fundamentalGraphData + stackedBarFormat + title + values |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 148 | |
| 149 | |
| 150 | print( paste( "Saving stacked bar chart to", stackedBarOutputFile ) ) |
| 151 | ggsave( stackedBarOutputFile, width = 10, height = 6, dpi = 200 ) |
| 152 | |
| 153 | |
| 154 | print( paste( "Successfully wrote stacked bar chart out to", stackedBarOutputFile ) ) |