blob: 897460b4d81d814f754e3385687197e6534c1356 [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
132# **********************************************************
133# STEP 3: Generate graphs.
134# **********************************************************
135
136print( "STEP 3: Generate graphs." )
137
138# 1. Graph fundamental data is generated first.
139# These are variables that apply to all of the graphs being generated, regardless of type.
140#
141# 2. Type specific graph data is generated.
142# Data specific for the error bar and stacked bar graphs are generated.
143#
144# 3. Generate and save the graphs.
145# Graphs are saved to the filename above, in the directory provided in command line args
146
147print( "Generating fundamental graph data." )
148
149# Calculate window to display graph, based on the lowest and highest points of the data.
150if ( min( dataFrame$ms - dataFrame$stds ) < 0){
151 yWindowMin <- min( dataFrame$ms - dataFrame$stds ) * 1.05
152} else {
153 yWindowMin <- 0
154}
155yWindowMax <- max( dataFrame$ms + dataFrame$stds )
156
157mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = ms, ymin = ms - stds, ymax = ms + stds,fill = type ) )
158
159# Formatting the plot
160width <- 1.3 # Width of the bars.
161xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
162yLimit <- ylim( yWindowMin, yWindowMax )
163xLabel <- xlab( "Scale" )
164yLabel <- ylab( "Latency (ms)" )
165fillLabel <- labs( fill="Type" )
166chartTitle <- "Intent Install, Withdraw, & Reroute Latencies"
167if ( args[ 1 ] == "y" ){
168 chartTitle <- paste( chartTitle, "with Flow Objectives" )
169}
170chartTitle <- paste( chartTitle, "\nBatch Size =" )
171chartTitle <- paste( chartTitle, fileData1[ 1,'batch_size' ] )
172
173theme <- theme( plot.title=element_text( hjust = 0.5, size = 18, face='bold' ) )
174
175# Store plot configurations as 1 variable
176fundamentalGraphData <- mainPlot + xScaleConfig + yLimit + xLabel + yLabel + fillLabel + theme
177
178
179# Create the bar graph with error bars.
180# geom_bar contains:
181# - stat: data formatting (usually "identity")
182# - width: the width of the bar types (declared above)
183# geom_errorbar contains similar arguments as geom_bar.
184print( "Generating bar graph with error bars." )
185barGraphFormat <- geom_bar( stat = "identity", width = width, position = "dodge" )
186errorBarFormat <- geom_errorbar( width = width, position = "dodge" )
187title <- ggtitle( chartTitle )
188result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
189
190# Save graph to file
191print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
192ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
193print( paste( "Successfully wrote bar chart with error bars out to", errBarOutputFile ) )