blob: 90bcb8d6f7aa42c261d73baece195f1c7676862f [file] [log] [blame]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +00001# 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 Ronquillob6268842017-10-03 13:02:58 -070021# please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000022
23# **********************************************************
24# STEP 1: File management.
25# **********************************************************
26
27print( "STEP 1: File management." )
28
Jeremy Ronquillob6268842017-10-03 13:02:58 -070029# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000030print( "Reading commmand-line args." )
31args <- 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
36print( "Importing libraries." )
37library( ggplot2 )
38library( reshape2 )
39library( RPostgreSQL ) # For databases
40
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000041# Check if sufficient args are provided.
42if ( 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 Ronquillob6268842017-10-03 13:02:58 -070047# paste() is used to concatenate strings.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000048errBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
49errBarOutputFile <- paste( errBarOutputFile, args[ 6 ], sep="_" )
50errBarOutputFile <- paste( errBarOutputFile, "_errGraph.jpg", sep="" )
51
52stackedBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
53stackedBarOutputFile <- paste( stackedBarOutputFile, args[ 6 ], sep="_" )
54stackedBarOutputFile <- paste( stackedBarOutputFile, "_stackedGraph.jpg", sep="" )
55
56print( "Reading from databases." )
57
58con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] )
59
60command <- paste( "SELECT * FROM mastership_failover_tests WHERE branch = '", args[ 6 ], sep = "" )
61command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM mastership_failover_tests WHERE branch = '", sep = "" )
62command <- paste( command, args[ 6 ], sep = "" )
63command <- paste( command, "' ) ", sep="" )
64
65print( paste( "Sending SQL command:", command ) )
66
67fileData <- dbGetQuery( con, command )
68
69chartTitle <- "Mastership Failover Latency"
70
71
72# **********************************************************
73# STEP 2: Organize data.
74# **********************************************************
75
76fileDataNames <- names( fileData )
77
78avgs <- c()
79stds <- c()
80
81
82print( "Sorting data." )
83for ( 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
95avgData <- melt( avgs )
96avgData$scale <- fileData$scale
97colnames( avgData ) <- c( "ms", "type", "scale" )
98
99stdData <- melt( stds )
100colnames( stdData ) <- c( "ms", "type" )
101
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700102dataFrame <- na.omit( avgData ) # Omit any data that doesn't exist
103
104print( "Data Frame Results:" )
105print( avgData )
106
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000107
108# **********************************************************
109# STEP 3: Generate graphs.
110# **********************************************************
111
112print( "Generating fundamental graph data." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700113
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700114theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000115
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700116mainPlot <- ggplot( data = avgData, aes( x = scale, y = ms, ymin = ms, ymax = ms + stdData$ms,fill = type ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000117xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000118xLabel <- xlab( "Scale" )
119yLabel <- ylab( "Latency (ms)" )
120fillLabel <- labs( fill="Type" )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700121theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ), legend.position="bottom", legend.text=element_text( size=22 ), legend.title = element_blank(), legend.key.size = unit( 1.5, 'lines' ) )
122wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000123
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700124fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme + wrapLegend
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000125
126
127print( "Generating bar graph with error bars." )
128width <- 0.9
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700129barGraphFormat <- geom_bar( stat="identity", position=position_dodge(), width = width )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700130colors <- scale_fill_manual( values=c( "#F77670", "#619DFA" ) )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700131errorBarFormat <- geom_errorbar( width = width, position=position_dodge(), color=rgb( 140, 140, 140, maxColorValue=255 ) )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700132values <- geom_text( aes( x=avgData$scale, y=avgData$ms + 0.02 * max( avgData$ms ), label = format( avgData$ms, digits=3, big.mark = ",", scientific = FALSE ) ), size = 7.0, fontface = "bold", position=position_dodge( 0.9 ) )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700133title <- ggtitle( paste( chartTitle, "" ) )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700134result <- fundamentalGraphData + barGraphFormat + colors + errorBarFormat + title + values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000135
136
137print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700138ggsave( errBarOutputFile, width = 15, height = 10, dpi = 200 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000139
140
141print( paste( "Successfully wrote bar chart with error bars out to", errBarOutputFile ) )
142
143
144print( "Generating stacked bar chart." )
145stackedBarFormat <- geom_bar( stat="identity", width=width )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700146title <- ggtitle( paste( chartTitle, "" ) )
147sum <- fileData[ 'deact_role_avg' ] + fileData[ 'kill_deact_avg' ]
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700148values <- geom_text( aes( x=avgData$scale, y=sum + 0.02 * max( sum ), label = format( sum, digits=3, big.mark = ",", scientific = FALSE ) ), size = 7.0, fontface = "bold" )
149result <- fundamentalGraphData + stackedBarFormat + colors + title + values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000150
151
152print( paste( "Saving stacked bar chart to", stackedBarOutputFile ) )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700153ggsave( stackedBarOutputFile, width = 15, height = 10, dpi = 200 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000154
155
156print( paste( "Successfully wrote stacked bar chart out to", stackedBarOutputFile ) )