blob: 8681f290ff5e4563c135028ab23a5d2da61970c9 [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( "**********************************************************" )
Devin Lim0e967162017-11-03 15:59:53 -070030database_host = 1
31database_port = 2
32database_u_id = 3
33database_pw = 4
34test_name = 5
35branch_name = 6
36save_directory = 7
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000037
Jeremy Ronquillob6268842017-10-03 13:02:58 -070038# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000039print( "Reading commmand-line args." )
40args <- commandArgs( trailingOnly=TRUE )
41
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070042# ----------------
43# Import Libraries
44# ----------------
45
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000046print( "Importing libraries." )
47library( ggplot2 )
48library( reshape2 )
49library( RPostgreSQL ) # For databases
50
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070051# -------------------
52# Check CLI Arguments
53# -------------------
54
55print( "Verifying CLI args." )
Devin Lim0e967162017-11-03 15:59:53 -070056if ( is.na( args[ save_directory ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070057 print( paste( "Usage: Rscript SCPFmastershipFailoverLat",
58 "<database-host>",
59 "<database-port>",
60 "<database-user-id>",
61 "<database-password>",
62 "<test-name>",
63 "<branch-name>",
64 "<directory-to-save-graphs>",
65 sep=" " ) )
66
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000067 q() # basically exit(), but in R
68}
69
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070070# -----------------
71# Create File Names
72# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000073
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070074print( "Creating filenames and title of graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000075
76chartTitle <- "Mastership Failover Latency"
77
Devin Lim0e967162017-11-03 15:59:53 -070078errBarOutputFile <- paste( args[ save_directory ],
79 args[ test_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070080 "_",
Devin Lim0e967162017-11-03 15:59:53 -070081 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070082 "_errGraph.jpg",
83 sep="" )
84
Devin Lim0e967162017-11-03 15:59:53 -070085stackedBarOutputFile <- paste( args[ save_directory ],
86 args[ test_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070087 "_",
Devin Lim0e967162017-11-03 15:59:53 -070088 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070089 "_stackedGraph.jpg",
90 sep="" )
91
92# ------------------
93# SQL Initialization
94# ------------------
95
96print( "Initializing SQL" )
97
98con <- dbConnect( dbDriver( "PostgreSQL" ),
99 dbname = "onostest",
Devin Lim0e967162017-11-03 15:59:53 -0700100 host = args[ database_host ],
101 port = strtoi( args[ database_port ] ),
102 user = args[ database_u_id ],
103 password = args[ database_pw ] )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700104
105# ---------------------------------------
106# Mastership Failover Latency SQL Command
107# ---------------------------------------
108
109print( "Generating Mastership Failover Latency SQL command" )
110
111command <- paste( "SELECT * FROM mastership_failover_tests WHERE branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700112 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700113 "' AND date IN ( SELECT MAX( date ) FROM mastership_failover_tests WHERE branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700114 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700115 "' ) ",
116 sep = "" )
117
118print( "Sending SQL command:" )
119print( command )
120
121fileData <- dbGetQuery( con, command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000122
123# **********************************************************
124# STEP 2: Organize data.
125# **********************************************************
126
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700127print( "**********************************************************" )
128print( "STEP 2: Organize Data." )
129print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000130
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700131# ------------
132# Data Sorting
133# ------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000134
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700135print( "Combining averages into a list." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000136
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700137avgs <- c( fileData[ 'kill_deact_avg' ],
138 fileData[ 'deact_role_avg' ] )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000139
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700140# --------------------
141# Construct Data Frame
142# --------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000143
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700144print( "Constructing Data Frame from list." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000145
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700146dataFrame <- melt( avgs )
147dataFrame$scale <- fileData$scale
148dataFrame$stds <- c( fileData$kill_deact_std,
149 fileData$deact_role_std )
150
151colnames( dataFrame ) <- c( "ms",
152 "type",
153 "scale",
154 "stds" )
155
156dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
157
158sum <- fileData[ 'deact_role_avg' ] +
159 fileData[ 'kill_deact_avg' ]
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700160
161print( "Data Frame Results:" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700162print( dataFrame )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700163
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000164
165# **********************************************************
166# STEP 3: Generate graphs.
167# **********************************************************
168
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700169print( "**********************************************************" )
170print( "STEP 3: Generate Graph." )
171print( "**********************************************************" )
172
173# ------------------------------------
174# Initialize Variables for Both Graphs
175# ------------------------------------
176
177print( "Initializing variables used in both graphs." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700178
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700179theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700180xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000181xLabel <- xlab( "Scale" )
182yLabel <- ylab( "Latency (ms)" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700183fillLabel <- labs( fill = "Type" )
184barWidth <- 0.9
185imageWidth <- 15
186imageHeight <- 10
187imageDPI <- 200
188
189theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face='bold' ),
190 legend.position = "bottom",
191 legend.text = element_text( size=22 ),
192 legend.title = element_blank(),
193 legend.key.size = unit( 1.5, 'lines' ) )
194
195barColors <- scale_fill_manual( values=c( "#F77670",
196 "#619DFA" ) )
197
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700198wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000199
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700200# ----------------------------------
201# Error Bar Graph Generate Main Plot
202# ----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000203
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700204print( "Creating main plot." )
205
206mainPlot <- ggplot( data = dataFrame, aes( x = scale,
207 y = ms,
208 ymin = ms,
209 ymax = ms + stds,
210 fill = type ) )
211
212# ----------------------------------------------
213# Error Bar Graph Fundamental Variables Assigned
214# ----------------------------------------------
215
216print( "Generating fundamental graph data for the error bar graph." )
217
218errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 )
219
220title <- ggtitle( chartTitle )
221
222fundamentalGraphData <- mainPlot +
223 xScaleConfig +
224 xLabel +
225 yLabel +
226 fillLabel +
227 theme +
228 title +
229 wrapLegend
230
231# -------------------------------------------
232# Error Bar Graph Generating Bar Graph Format
233# -------------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000234
235print( "Generating bar graph with error bars." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000236
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700237barGraphFormat <- geom_bar( stat = "identity",
238 position = position_dodge(),
239 width = barWidth )
240
241errorBarFormat <- geom_errorbar( width = barWidth,
242 position = position_dodge(),
243 color = errorBarColor )
244
245values <- geom_text( aes( x = dataFrame$scale,
246 y = dataFrame$ms + 0.02 * max( dataFrame$ms ),
247 label = format( dataFrame$ms,
248 digits = 3,
249 big.mark = ",",
250 scientific = FALSE ) ),
251 size = 7.0,
252 fontface = "bold",
253 position = position_dodge( 0.9 ) )
254
255result <- fundamentalGraphData +
256 barGraphFormat +
257 barColors +
258 errorBarFormat +
259 values
260
261# ---------------------------------------
262# Error Bar Graph Exporting Graph to File
263# ---------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000264
265print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000266
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700267ggsave( errBarOutputFile,
268 width = imageWidth,
269 height = imageHeight,
270 dpi = imageDPI )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000271
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700272print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000273
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700274# ------------------------------------------------
275# Stacked Bar Graph Fundamental Variables Assigned
276# ------------------------------------------------
277
278print( "Generating fundamental graph data for the stacked bar graph." )
279
280title <- ggtitle( chartTitle )
281
282fundamentalGraphData <- mainPlot +
283 xScaleConfig +
284 xLabel +
285 yLabel +
286 fillLabel +
287 theme +
288 title +
289 wrapLegend
290
291# ---------------------------------------------
292# Stacked Bar Graph Generating Bar Graph Format
293# ---------------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000294
295print( "Generating stacked bar chart." )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700296stackedBarFormat <- geom_bar( stat = "identity",
297 width = barWidth )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000298
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700299values <- geom_text( aes( x = dataFrame$scale,
300 y = sum + 0.02 * max( sum ),
301 label = format( sum,
302 digits = 3,
303 big.mark = ",",
304 scientific = FALSE ) ),
305 size = 7.0,
306 fontface = "bold" )
307
308result <- fundamentalGraphData +
309 stackedBarFormat +
310 barColors +
311 title +
312 values
313
314# -----------------------------------------
315# Stacked Bar Graph Exporting Graph to File
316# -----------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000317
318print( paste( "Saving stacked bar chart to", stackedBarOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000319
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700320ggsave( stackedBarOutputFile,
321 width = imageWidth,
322 height = imageHeight,
323 dpi = imageDPI )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000324
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700325print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", stackedBarOutputFile ) )