blob: f2697dbcff440441f074cd4b4220c13f4a5a6a3d [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,
21# please contact Jeremy Ronquillo: jeremyr@opennetworking.org
22
23# **********************************************************
24# STEP 1: File management.
25# **********************************************************
26
27print( "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.
31# ie: Rscript SCPFgraphGenerator SCPFsampleDataDB.csv ~/tmp/
32print( "Reading commmand-line args." )
33args <- commandArgs( trailingOnly=TRUE )
34
35# Import libraries to be used for graphing and organizing data, respectively.
36# Find out more about ggplot2: https://github.com/tidyverse/ggplot2
37# reshape2: https://github.com/hadley/reshape
38print( "Importing libraries." )
39library( ggplot2 )
40library( reshape2 )
41library( RPostgreSQL ) # For databases
42
43# Check if sufficient args are provided.
44if ( is.na( args[ 9 ] ) ){
45 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>" )
46 q() # basically exit(), but in R
47}
48
49flowObjFileModifier <- ""
50if ( args[ 1 ] == "y" ){
51 flowObjFileModifier <- "fobj_"
52}
53
54# Filenames for output graphs include the testname and the graph type.
55# See the examples below. paste() is used to concatenate strings.
56
57errBarOutputFile <- paste( args[ 9 ], "SCPFIntentInstallWithdrawRerouteLat", sep="" )
58errBarOutputFile <- paste( errBarOutputFile, args[ 7 ], sep="_" )
59if ( args[ 1 ] == "y" ){
60 errBarOutputFile <- paste( errBarOutputFile, "_fobj", sep="" )
61}
62errBarOutputFile <- paste( errBarOutputFile, "_", sep="" )
63errBarOutputFile <- paste( errBarOutputFile, args[ 8 ], sep="" )
64errBarOutputFile <- paste( errBarOutputFile, "-batchSize", sep="" )
65errBarOutputFile <- paste( errBarOutputFile, "_graph.jpg", sep="" )
66
67print( "Reading from databases." )
68
69con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 2 ], port=strtoi( args[ 3 ] ), user=args[ 4 ],password=args[ 5 ] )
70
71command1 <- paste( "SELECT * FROM intent_latency_", flowObjFileModifier, sep="" )
72command1 <- paste( command1, "tests WHERE batch_size=", sep="" )
73command1 <- paste( command1, args[ 8 ], sep="" )
74command1 <- paste( command1, " AND branch = '", sep="" )
75command1 <- paste( command1, args[ 7 ], sep="" )
76command1 <- paste( command1, "' AND date IN ( SELECT MAX( date ) FROM intent_latency_", sep="" )
77command1 <- paste( command1, flowObjFileModifier, sep="" )
78command1 <- paste( command1, "tests WHERE branch='", sep="" )
79command1 <- paste( command1, args[ 7 ], sep="" )
80command1 <- paste( command1, "')", sep="" )
81
82print( paste( "Sending SQL command:", command1 ) )
83
84fileData1 <- dbGetQuery( con, command1 )
85
86command2 <- paste( "SELECT * FROM intent_reroute_latency_", flowObjFileModifier, sep="" )
87command2 <- paste( command2, "tests WHERE batch_size=", sep="" )
88command2 <- paste( command2, args[ 8 ], sep="" )
89command2 <- paste( command2, " AND branch = '", sep="" )
90command2 <- paste( command2, args[ 7 ], sep="" )
91command2 <- paste( command2, "' AND date IN ( SELECT MAX( date ) FROM intent_reroute_latency_", sep="" )
92command2 <- paste( command2, flowObjFileModifier, sep="" )
93command2 <- paste( command2, "tests WHERE branch='", sep="" )
94command2 <- paste( command2, args[ 7 ], sep="" )
95command2 <- paste( command2, "')", sep="" )
96
97print( paste( "Sending SQL command:", command2 ) )
98
99fileData2 <- dbGetQuery( con, command2 )
100
101# **********************************************************
102# STEP 2: Organize data.
103# **********************************************************
104
105print( "STEP 2: Organize data." )
106
107# Create lists c() and organize data into their corresponding list.
108print( "Sorting data." )
109if ( ncol( fileData2 ) == 0 ){
110 avgs <- c( fileData1[ 'install_avg' ], fileData1[ 'withdraw_avg' ] )
111} else{
112 colnames( fileData2 ) <- c( "date", "name", "date", "branch", "commit", "scale", "batch_size", "reroute_avg", "reroute_std" )
113 avgs <- c( fileData1[ 'install_avg' ], fileData1[ 'withdraw_avg' ], fileData2[ 'reroute_avg' ] )
114}
115
116# Parse lists into data frames.
117dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame
118
119if ( ncol( fileData2 ) == 0 ){
120 dataFrame$scale <- c( fileData1$scale, fileData1$scale ) # Add node scaling to the data frame.
121 dataFrame$stds <- c( fileData1$install_std, fileData1$withdraw_std )
122} else{
123 dataFrame$scale <- c( fileData1$scale, fileData1$scale, fileData2$scale ) # Add node scaling to the data frame.
124 dataFrame$stds <- c( fileData1$install_std, fileData1$withdraw_std, fileData2$reroute_std )
125}
126colnames( dataFrame ) <- c( "ms", "type", "scale", "stds" )
127
128# Format data frame so that the data is in the same order as it appeared in the file.
129dataFrame$type <- as.character( dataFrame$type )
130dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
131
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700132dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
133
134print( "Data Frame Results:" )
135print( dataFrame )
136
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000137# **********************************************************
138# STEP 3: Generate graphs.
139# **********************************************************
140
141print( "STEP 3: Generate graphs." )
142
143# 1. Graph fundamental data is generated first.
144# These are variables that apply to all of the graphs being generated, regardless of type.
145#
146# 2. Type specific graph data is generated.
147# Data specific for the error bar and stacked bar graphs are generated.
148#
149# 3. Generate and save the graphs.
150# Graphs are saved to the filename above, in the directory provided in command line args
151
152print( "Generating fundamental graph data." )
153
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700154theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
155
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000156# Calculate window to display graph, based on the lowest and highest points of the data.
157if ( min( dataFrame$ms - dataFrame$stds ) < 0){
158 yWindowMin <- min( dataFrame$ms - dataFrame$stds ) * 1.05
159} else {
160 yWindowMin <- 0
161}
162yWindowMax <- max( dataFrame$ms + dataFrame$stds )
163
164mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = ms, ymin = ms - stds, ymax = ms + stds,fill = type ) )
165
166# Formatting the plot
167width <- 1.3 # Width of the bars.
168xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
169yLimit <- ylim( yWindowMin, yWindowMax )
170xLabel <- xlab( "Scale" )
171yLabel <- ylab( "Latency (ms)" )
172fillLabel <- labs( fill="Type" )
173chartTitle <- "Intent Install, Withdraw, & Reroute Latencies"
174if ( args[ 1 ] == "y" ){
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700175 chartTitle <- paste( chartTitle, "w/ FlowObj" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000176}
177chartTitle <- paste( chartTitle, "\nBatch Size =" )
178chartTitle <- paste( chartTitle, fileData1[ 1,'batch_size' ] )
179
Jeremy Ronquillobe37f092017-09-26 13:30:05 -0700180theme <- theme( plot.title=element_text( hjust = 0.5, size = 22, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000181
182# Store plot configurations as 1 variable
183fundamentalGraphData <- mainPlot + xScaleConfig + yLimit + xLabel + yLabel + fillLabel + theme
184
185
186# Create the bar graph with error bars.
187# geom_bar contains:
188# - stat: data formatting (usually "identity")
189# - width: the width of the bar types (declared above)
190# geom_errorbar contains similar arguments as geom_bar.
191print( "Generating bar graph with error bars." )
192barGraphFormat <- geom_bar( stat = "identity", width = width, position = "dodge" )
193errorBarFormat <- geom_errorbar( width = width, position = "dodge" )
194title <- ggtitle( chartTitle )
195result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
196
197# Save graph to file
198print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
199ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
200print( paste( "Successfully wrote bar chart with error bars out to", errBarOutputFile ) )