blob: 82638dc2bfaa742ffacbd883ce58464c36e686ac [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# **********************************************************
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070024# STEP 1: Data management.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000025# **********************************************************
26
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070027print( "**********************************************************" )
28print( "STEP 1: Data management." )
29print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000030
Jeremy Ronquillob6268842017-10-03 13:02:58 -070031# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000032print( "Reading commmand-line args." )
33args <- commandArgs( trailingOnly=TRUE )
34
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070035# ----------------
36# Import Libraries
37# ----------------
38
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000039print( "Importing libraries." )
40library( ggplot2 )
41library( reshape2 )
42library( RPostgreSQL ) # For databases
43
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070044# -------------------
45# Check CLI Arguments
46# -------------------
47
48print( "Verifying CLI args." )
49
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000050if ( is.na( args[ 7 ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070051
52 print( paste( "Usage: Rscript SCPFmastershipFailoverLat",
53 "<database-host>",
54 "<database-port>",
55 "<database-user-id>",
56 "<database-password>",
57 "<test-name>",
58 "<branch-name>",
59 "<directory-to-save-graphs>",
60 sep=" " ) )
61
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000062 q() # basically exit(), but in R
63}
64
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070065# -----------------
66# Create File Names
67# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000068
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070069print( "Creating filenames and title of graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000070
71chartTitle <- "Mastership Failover Latency"
72
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070073errBarOutputFile <- paste( args[ 7 ],
74 args[ 5 ],
75 "_",
76 args[ 6 ],
77 "_errGraph.jpg",
78 sep="" )
79
80stackedBarOutputFile <- paste( args[ 7 ],
81 args[ 5 ],
82 "_",
83 args[ 6 ],
84 "_stackedGraph.jpg",
85 sep="" )
86
87# ------------------
88# SQL Initialization
89# ------------------
90
91print( "Initializing SQL" )
92
93con <- dbConnect( dbDriver( "PostgreSQL" ),
94 dbname = "onostest",
95 host = args[ 1 ],
96 port = strtoi( args[ 2 ] ),
97 user = args[ 3 ],
98 password = args[ 4 ] )
99
100# ---------------------------------------
101# Mastership Failover Latency SQL Command
102# ---------------------------------------
103
104print( "Generating Mastership Failover Latency SQL command" )
105
106command <- paste( "SELECT * FROM mastership_failover_tests WHERE branch = '",
107 args[ 6 ],
108 "' AND date IN ( SELECT MAX( date ) FROM mastership_failover_tests WHERE branch = '",
109 args[ 6 ],
110 "' ) ",
111 sep = "" )
112
113print( "Sending SQL command:" )
114print( command )
115
116fileData <- dbGetQuery( con, command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000117
118# **********************************************************
119# STEP 2: Organize data.
120# **********************************************************
121
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700122print( "**********************************************************" )
123print( "STEP 2: Organize Data." )
124print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000125
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700126# ------------
127# Data Sorting
128# ------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000129
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700130print( "Combining averages into a list." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000131
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700132avgs <- c( fileData[ 'kill_deact_avg' ],
133 fileData[ 'deact_role_avg' ] )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000134
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700135# --------------------
136# Construct Data Frame
137# --------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000138
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700139print( "Constructing Data Frame from list." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000140
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700141dataFrame <- melt( avgs )
142dataFrame$scale <- fileData$scale
143dataFrame$stds <- c( fileData$kill_deact_std,
144 fileData$deact_role_std )
145
146colnames( dataFrame ) <- c( "ms",
147 "type",
148 "scale",
149 "stds" )
150
151dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
152
153sum <- fileData[ 'deact_role_avg' ] +
154 fileData[ 'kill_deact_avg' ]
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700155
156print( "Data Frame Results:" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700157print( dataFrame )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700158
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000159
160# **********************************************************
161# STEP 3: Generate graphs.
162# **********************************************************
163
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700164print( "**********************************************************" )
165print( "STEP 3: Generate Graph." )
166print( "**********************************************************" )
167
168# ------------------------------------
169# Initialize Variables for Both Graphs
170# ------------------------------------
171
172print( "Initializing variables used in both graphs." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700173
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700174theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700175xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000176xLabel <- xlab( "Scale" )
177yLabel <- ylab( "Latency (ms)" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700178fillLabel <- labs( fill = "Type" )
179barWidth <- 0.9
180imageWidth <- 15
181imageHeight <- 10
182imageDPI <- 200
183
184theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face='bold' ),
185 legend.position = "bottom",
186 legend.text = element_text( size=22 ),
187 legend.title = element_blank(),
188 legend.key.size = unit( 1.5, 'lines' ) )
189
190barColors <- scale_fill_manual( values=c( "#F77670",
191 "#619DFA" ) )
192
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700193wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000194
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700195# ----------------------------------
196# Error Bar Graph Generate Main Plot
197# ----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000198
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700199print( "Creating main plot." )
200
201mainPlot <- ggplot( data = dataFrame, aes( x = scale,
202 y = ms,
203 ymin = ms,
204 ymax = ms + stds,
205 fill = type ) )
206
207# ----------------------------------------------
208# Error Bar Graph Fundamental Variables Assigned
209# ----------------------------------------------
210
211print( "Generating fundamental graph data for the error bar graph." )
212
213errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 )
214
215title <- ggtitle( chartTitle )
216
217fundamentalGraphData <- mainPlot +
218 xScaleConfig +
219 xLabel +
220 yLabel +
221 fillLabel +
222 theme +
223 title +
224 wrapLegend
225
226# -------------------------------------------
227# Error Bar Graph Generating Bar Graph Format
228# -------------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000229
230print( "Generating bar graph with error bars." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000231
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700232barGraphFormat <- geom_bar( stat = "identity",
233 position = position_dodge(),
234 width = barWidth )
235
236errorBarFormat <- geom_errorbar( width = barWidth,
237 position = position_dodge(),
238 color = errorBarColor )
239
240values <- geom_text( aes( x = dataFrame$scale,
241 y = dataFrame$ms + 0.02 * max( dataFrame$ms ),
242 label = format( dataFrame$ms,
243 digits = 3,
244 big.mark = ",",
245 scientific = FALSE ) ),
246 size = 7.0,
247 fontface = "bold",
248 position = position_dodge( 0.9 ) )
249
250result <- fundamentalGraphData +
251 barGraphFormat +
252 barColors +
253 errorBarFormat +
254 values
255
256# ---------------------------------------
257# Error Bar Graph Exporting Graph to File
258# ---------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000259
260print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000261
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700262ggsave( errBarOutputFile,
263 width = imageWidth,
264 height = imageHeight,
265 dpi = imageDPI )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000266
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700267print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000268
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700269# ------------------------------------------------
270# Stacked Bar Graph Fundamental Variables Assigned
271# ------------------------------------------------
272
273print( "Generating fundamental graph data for the stacked bar graph." )
274
275title <- ggtitle( chartTitle )
276
277fundamentalGraphData <- mainPlot +
278 xScaleConfig +
279 xLabel +
280 yLabel +
281 fillLabel +
282 theme +
283 title +
284 wrapLegend
285
286# ---------------------------------------------
287# Stacked Bar Graph Generating Bar Graph Format
288# ---------------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000289
290print( "Generating stacked bar chart." )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700291stackedBarFormat <- geom_bar( stat = "identity",
292 width = barWidth )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000293
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700294values <- geom_text( aes( x = dataFrame$scale,
295 y = sum + 0.02 * max( sum ),
296 label = format( sum,
297 digits = 3,
298 big.mark = ",",
299 scientific = FALSE ) ),
300 size = 7.0,
301 fontface = "bold" )
302
303result <- fundamentalGraphData +
304 stackedBarFormat +
305 barColors +
306 title +
307 values
308
309# -----------------------------------------
310# Stacked Bar Graph Exporting Graph to File
311# -----------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000312
313print( paste( "Saving stacked bar chart to", stackedBarOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000314
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700315ggsave( stackedBarOutputFile,
316 width = imageWidth,
317 height = imageHeight,
318 dpi = imageDPI )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000319
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700320print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", stackedBarOutputFile ) )