blob: d63bce338563498b63f88603229eefc680f7c841 [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 SCPFbatchFlowResp",
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
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070071postOutputFile <- paste( args[ 7 ],
72 args[ 5 ],
73 "_",
74 args[ 6 ],
75 "_PostGraph.jpg",
76 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000077
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070078delOutputFile <- paste( args[ 7 ],
79 args[ 5 ],
80 "_",
81 args[ 6 ],
82 "_DelGraph.jpg",
83 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000084
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070085postChartTitle <- paste( "Single Bench Flow Latency - Post", "Last 3 Builds", sep = "\n" )
86delChartTitle <- paste( "Single Bench Flow Latency - Del", "Last 3 Builds", sep = "\n" )
87
88# ------------------
89# SQL Initialization
90# ------------------
91
92print( "Initializing SQL" )
93
94con <- dbConnect( dbDriver( "PostgreSQL" ),
95 dbname = "onostest",
96 host = args[ 1 ],
97 port = strtoi( args[ 2 ] ),
98 user = args[ 3 ],
99 password = args[ 4 ] )
100
101# ---------------------------
102# Batch Flow Resp SQL Command
103# ---------------------------
104
105print( "Generating Batch Flow Resp SQL Command" )
106
107command <- paste( "SELECT * FROM batch_flow_tests WHERE branch='",
108 args[ 6 ],
109 "' ORDER BY date DESC LIMIT 3",
110 sep="" )
111
112print( "Sending SQL command:" )
113print( command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000114
115fileData <- dbGetQuery( con, command )
116
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# Post Data Sorting
128# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000129
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700130print( "Sorting data for Post." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000131
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700132postAvgs <- c( fileData[ 'posttoconfrm' ],
133 fileData[ 'elapsepost' ] )
134
135# -------------------------
136# Post Construct Data Frame
137# -------------------------
138
139postDataFrame <- melt( postAvgs )
140postDataFrame$scale <- fileData$scale
141postDataFrame$date <- fileData$date
142postDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
143
144colnames( postDataFrame ) <- c( "ms",
145 "type",
146 "scale",
147 "date",
148 "iterative" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000149
150# Format data frame so that the data is in the same order as it appeared in the file.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700151postDataFrame$type <- as.character( postDataFrame$type )
152postDataFrame$type <- factor( postDataFrame$type,
153 levels = unique( postDataFrame$type ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000154
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700155postDataFrame <- na.omit( postDataFrame ) # Omit any data that doesn't exist
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700156
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700157print( "Post Data Frame Results:" )
158print( postDataFrame )
159
160# ----------------
161# Del Data Sorting
162# ----------------
163
164print( "Sorting data for Del." )
165avgs <- c( fileData[ 'deltoconfrm' ],
166 fileData[ 'elapsedel' ] )
167
168# ------------------------
169# Del Construct Data Frame
170# ------------------------
171
172delDataFrame <- melt( avgs )
173delDataFrame$scale <- fileData$scale
174delDataFrame$date <- fileData$date
175delDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
176
177colnames( delDataFrame ) <- c( "ms",
178 "type",
179 "scale",
180 "date",
181 "iterative" )
182
183# Format data frame so that the data is in the same order as it appeared in the file.
184delDataFrame$type <- as.character( delDataFrame$type )
185delDataFrame$type <- factor( delDataFrame$type,
186 levels = unique( delDataFrame$type ) )
187
188delDataFrame <- na.omit( delDataFrame ) # Omit any data that doesn't exist
189
190print( "Del Data Frame Results:" )
191print( delDataFrame )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700192
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000193# **********************************************************
194# STEP 3: Generate graphs.
195# **********************************************************
196
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700197print( "**********************************************************" )
198print( "STEP 3: Generate Graph." )
199print( "**********************************************************" )
200
201# ------------------------------------------
202# Initializing variables used in both graphs
203# ------------------------------------------
204
205print( "Initializing variables used in both graphs." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000206
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700207theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillob6268842017-10-03 13:02:58 -0700208xLabel <- xlab( "Build Date" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000209yLabel <- ylab( "Latency (ms)" )
210fillLabel <- labs( fill="Type" )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700211colors <- scale_fill_manual( values=c( "#F77670", "#619DFA" ) )
212wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700213barWidth <- 0.3
214imageWidth <- 15
215imageHeight <- 10
216imageDPI <- 200
217
218theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
219 legend.position = "bottom",
220 legend.text = element_text( size = 22 ),
221 legend.title = element_blank(),
222 legend.key.size = unit( 1.5, 'lines' ) )
223
224barGraphFormat <- geom_bar( stat = "identity",
225 width = barWidth )
226
227# -----------------------
228# Post Generate Main Plot
229# -----------------------
230
231print( "Creating main plot for Post graph." )
232
233mainPlot <- ggplot( data = postDataFrame, aes( x = iterative,
234 y = ms,
235 fill = type ) )
236
237# -----------------------------------
238# Post Fundamental Variables Assigned
239# -----------------------------------
240
241print( "Generating fundamental graph data for Post graph." )
242
243xScaleConfig <- scale_x_continuous( breaks = postDataFrame$iterative,
244 label = postDataFrame$date )
245title <- ggtitle( postChartTitle )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000246
247
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700248fundamentalGraphData <- mainPlot +
249 xScaleConfig +
250 xLabel +
251 yLabel +
252 fillLabel +
253 theme +
254 wrapLegend +
255 colors +
256 title
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000257
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700258# --------------------------------
259# Post Generating Bar Graph Format
260# --------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000261
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700262print( "Generating bar graph for Post graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000263
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700264sum <- fileData[ 'posttoconfrm' ] +
265 fileData[ 'elapsepost' ]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000266
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700267values <- geom_text( aes( x = postDataFrame$iterative,
268 y = sum + 0.03 * max( sum ),
269 label = format( sum,
270 digits = 3,
271 big.mark = ",",
272 scientific = FALSE ) ),
273 size = 7.0,
274 fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000275
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700276result <- fundamentalGraphData +
277 barGraphFormat +
278 values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000279
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700280# ----------------------------
281# Post Exporting Graph to File
282# ----------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000283
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700284print( paste( "Saving Post bar chart to", postOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000285
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700286ggsave( postOutputFile,
287 width = imageWidth,
288 height = imageHeight,
289 dpi = imageDPI )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000290
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700291print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", postOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000292
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700293# ----------------------
294# Del Generate Main Plot
295# ----------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000296
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700297print( "Creating main plot for Del graph." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700298
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700299mainPlot <- ggplot( data = delDataFrame, aes( x = iterative,
300 y = ms,
301 fill = type ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000302
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700303# ----------------------------------
304# Del Fundamental Variables Assigned
305# ----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000306
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700307print( "Generating fundamental graph data for Del graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000308
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700309xScaleConfig <- scale_x_continuous( breaks = delDataFrame$iterative,
310 label = delDataFrame$date )
311title <- ggtitle( delChartTitle )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700312
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700313fundamentalGraphData <- mainPlot +
314 xScaleConfig +
315 xLabel +
316 yLabel +
317 fillLabel +
318 theme +
319 wrapLegend +
320 colors +
321 title
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000322
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700323# -------------------------------
324# Del Generating Bar Graph Format
325# -------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000326
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700327print( "Generating bar graph for Del graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000328
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700329sum <- fileData[ 'deltoconfrm' ] +
330 fileData[ 'elapsedel' ]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000331
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700332values <- geom_text( aes( x = delDataFrame$iterative,
333 y = sum + 0.03 * max( sum ),
334 label = format( sum,
335 digits = 3,
336 big.mark = ",",
337 scientific = FALSE ) ),
338 size = 7.0,
339 fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000340
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700341result <- fundamentalGraphData +
342 barGraphFormat +
343 title +
344 values
345
346# ---------------------------
347# Del Exporting Graph to File
348# ---------------------------
349
350print( paste( "Saving Del bar chart to", delOutputFile ) )
351
352ggsave( delOutputFile,
353 width = imageWidth,
354 height = imageHeight,
355 dpi = imageDPI )
356
357print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", delOutputFile ) )