blob: 98447ca04311c62bc1ce998dbf0d2c3463dc96c1 [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
41# Check if sufficient args are provided.
42if ( is.na( args[ 9 ] ) ){
43 print( "Usage: Rscript SCPFIntentInstallWithdrawRerouteLat.R <isFlowObj> <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <batch-size> <directory-to-save-graphs>" )
44 q() # basically exit(), but in R
45}
46
47flowObjFileModifier <- ""
48if ( args[ 1 ] == "y" ){
49 flowObjFileModifier <- "fobj_"
50}
51
Jeremy Ronquillob6268842017-10-03 13:02:58 -070052# paste() is used to concatenate strings
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000053errBarOutputFile <- paste( args[ 9 ], "SCPFIntentInstallWithdrawRerouteLat", sep="" )
54errBarOutputFile <- paste( errBarOutputFile, args[ 7 ], sep="_" )
55if ( args[ 1 ] == "y" ){
56 errBarOutputFile <- paste( errBarOutputFile, "_fobj", sep="" )
57}
58errBarOutputFile <- paste( errBarOutputFile, "_", sep="" )
59errBarOutputFile <- paste( errBarOutputFile, args[ 8 ], sep="" )
60errBarOutputFile <- paste( errBarOutputFile, "-batchSize", sep="" )
61errBarOutputFile <- paste( errBarOutputFile, "_graph.jpg", sep="" )
62
63print( "Reading from databases." )
64
65con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 2 ], port=strtoi( args[ 3 ] ), user=args[ 4 ],password=args[ 5 ] )
66
67command1 <- paste( "SELECT * FROM intent_latency_", flowObjFileModifier, sep="" )
68command1 <- paste( command1, "tests WHERE batch_size=", sep="" )
69command1 <- paste( command1, args[ 8 ], sep="" )
70command1 <- paste( command1, " AND branch = '", sep="" )
71command1 <- paste( command1, args[ 7 ], sep="" )
72command1 <- paste( command1, "' AND date IN ( SELECT MAX( date ) FROM intent_latency_", sep="" )
73command1 <- paste( command1, flowObjFileModifier, sep="" )
74command1 <- paste( command1, "tests WHERE branch='", sep="" )
75command1 <- paste( command1, args[ 7 ], sep="" )
76command1 <- paste( command1, "')", sep="" )
77
78print( paste( "Sending SQL command:", command1 ) )
79
80fileData1 <- dbGetQuery( con, command1 )
81
82command2 <- paste( "SELECT * FROM intent_reroute_latency_", flowObjFileModifier, sep="" )
83command2 <- paste( command2, "tests WHERE batch_size=", sep="" )
84command2 <- paste( command2, args[ 8 ], sep="" )
85command2 <- paste( command2, " AND branch = '", sep="" )
86command2 <- paste( command2, args[ 7 ], sep="" )
87command2 <- paste( command2, "' AND date IN ( SELECT MAX( date ) FROM intent_reroute_latency_", sep="" )
88command2 <- paste( command2, flowObjFileModifier, sep="" )
89command2 <- paste( command2, "tests WHERE branch='", sep="" )
90command2 <- paste( command2, args[ 7 ], sep="" )
91command2 <- paste( command2, "')", sep="" )
92
93print( paste( "Sending SQL command:", command2 ) )
94
95fileData2 <- dbGetQuery( con, command2 )
96
97# **********************************************************
98# STEP 2: Organize data.
99# **********************************************************
100
101print( "STEP 2: Organize data." )
102
103# Create lists c() and organize data into their corresponding list.
104print( "Sorting data." )
105if ( ncol( fileData2 ) == 0 ){
106 avgs <- c( fileData1[ 'install_avg' ], fileData1[ 'withdraw_avg' ] )
107} else{
108 colnames( fileData2 ) <- c( "date", "name", "date", "branch", "commit", "scale", "batch_size", "reroute_avg", "reroute_std" )
109 avgs <- c( fileData1[ 'install_avg' ], fileData1[ 'withdraw_avg' ], fileData2[ 'reroute_avg' ] )
110}
111
112# Parse lists into data frames.
113dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame
114
115if ( ncol( fileData2 ) == 0 ){
116 dataFrame$scale <- c( fileData1$scale, fileData1$scale ) # Add node scaling to the data frame.
117 dataFrame$stds <- c( fileData1$install_std, fileData1$withdraw_std )
118} else{
119 dataFrame$scale <- c( fileData1$scale, fileData1$scale, fileData2$scale ) # Add node scaling to the data frame.
120 dataFrame$stds <- c( fileData1$install_std, fileData1$withdraw_std, fileData2$reroute_std )
121}
122colnames( dataFrame ) <- c( "ms", "type", "scale", "stds" )
123
124# Format data frame so that the data is in the same order as it appeared in the file.
125dataFrame$type <- as.character( dataFrame$type )
126dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
127
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700128dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
129
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700130
131
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700132print( "Data Frame Results:" )
133print( dataFrame )
134
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000135# **********************************************************
136# STEP 3: Generate graphs.
137# **********************************************************
138
139print( "STEP 3: Generate graphs." )
140
141# 1. Graph fundamental data is generated first.
142# These are variables that apply to all of the graphs being generated, regardless of type.
143#
144# 2. Type specific graph data is generated.
145# Data specific for the error bar and stacked bar graphs are generated.
146#
147# 3. Generate and save the graphs.
148# Graphs are saved to the filename above, in the directory provided in command line args
149
150print( "Generating fundamental graph data." )
151
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700152theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
153
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000154mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = ms, ymin = ms - stds, ymax = ms + stds,fill = type ) )
155
156# Formatting the plot
157width <- 1.3 # Width of the bars.
158xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000159xLabel <- xlab( "Scale" )
160yLabel <- ylab( "Latency (ms)" )
161fillLabel <- labs( fill="Type" )
162chartTitle <- "Intent Install, Withdraw, & Reroute Latencies"
163if ( args[ 1 ] == "y" ){
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700164 chartTitle <- paste( chartTitle, "w/ FlowObj" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000165}
166chartTitle <- paste( chartTitle, "\nBatch Size =" )
167chartTitle <- paste( chartTitle, fileData1[ 1,'batch_size' ] )
168
Jeremy Ronquillobe37f092017-09-26 13:30:05 -0700169theme <- theme( plot.title=element_text( hjust = 0.5, size = 22, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000170
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700171
172
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000173# Store plot configurations as 1 variable
Jeremy Ronquillob6268842017-10-03 13:02:58 -0700174fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000175
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000176# Create the bar graph with error bars.
177# geom_bar contains:
178# - stat: data formatting (usually "identity")
179# - width: the width of the bar types (declared above)
180# geom_errorbar contains similar arguments as geom_bar.
181print( "Generating bar graph with error bars." )
182barGraphFormat <- geom_bar( stat = "identity", width = width, position = "dodge" )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700183errorBarFormat <- geom_errorbar( width = width, position = "dodge", color=rgb( 140, 140, 140, maxColorValue=255 ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000184title <- ggtitle( chartTitle )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700185values <- geom_text( aes( x=dataFrame$scale, y=dataFrame$ms + 0.035 * max( dataFrame$ms ), label = format( dataFrame$ms, digits=3, big.mark = ",", scientific = FALSE ) ), position=position_dodge( width=1.3 ), size = 3.2, fontface = "bold" )
186
187result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title + values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000188
189# Save graph to file
190print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
191ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
192print( paste( "Successfully wrote bar chart with error bars out to", errBarOutputFile ) )