blob: 66dc50505563284743bc4a85bc92b3c2db17770a [file] [log] [blame]
Jeremy Ronquillodae11042018-02-21 09:21:44 -08001# 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: j_ronquillo@u.pacific.edu
22#
23# Example script:
24# Single Bench Flow Latency Graph with Eventually Consistent Flow Rule Store (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFbatchFlowResp_master_OldFlow_PostGraph.jpg):
25# Rscript SCPFbatchFlowResp.R <url> <port> <username> <pass> SCPFbatchFlowResp.R master y /path/to/save/directory/
26
27# **********************************************************
28# STEP 1: Data management.
29# **********************************************************
30
31old_flow <- 7
32save_directory <- 8
33
34print( "**********************************************************" )
35print( "STEP 1: Data management." )
36print( "**********************************************************" )
37
38# Command line arguments are read.
39print( "Reading commmand-line args." )
40args <- commandArgs( trailingOnly=TRUE )
41
42# ----------------
43# Import Libraries
44# ----------------
45
46print( "Importing libraries." )
47library( ggplot2 )
48library( reshape2 )
49library( RPostgreSQL ) # For databases
Devin Lim324806b2018-05-11 15:36:52 -070050source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" )
51source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" )
52source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" )
53source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" )
Jeremy Ronquillodae11042018-02-21 09:21:44 -080054
55# -------------------
56# Check CLI Arguments
57# -------------------
58
59print( "Verifying CLI args." )
60
61if ( length( args ) != save_directory ){
62 usage( "SCPFbatchFlowResp.R", c( "using-old-flow" ) )
63 quit( status = 1 )
64}
65
66# -----------------
67# Create File Names
68# -----------------
69
70print( "Creating filenames and title of graph." )
71
72postOutputFile <- paste( args[ save_directory ],
73 args[ graph_title ],
74 "_",
75 args[ branch_name ],
76 if( args[ old_flow ] == "y" ) "_OldFlow" else "",
77 "_PostGraph.jpg",
78 sep="" )
79
80delOutputFile <- paste( args[ save_directory ],
81 args[ graph_title ],
82 "_",
83 args[ branch_name ],
84 if( args[ old_flow ] == "y" ) "_OldFlow" else "",
85 "_DelGraph.jpg",
86 sep="" )
87
88postChartTitle <- paste( "Single Bench Flow Latency - Post\n",
89 "Last 3 Builds",
90 if( args[ old_flow ] == "y" ) "\nWith Eventually Consistent Flow Rule Store" else "",
91 sep = "" )
92delChartTitle <- paste( "Single Bench Flow Latency - Del\n",
93 "Last 3 Builds",
94 if( args[ old_flow ] == "y" ) "\nWith Eventually Consistent Flow Rule Store" else "",
95 sep = "" )
96
97# ------------------
98# SQL Initialization
99# ------------------
100
101print( "Initializing SQL" )
102
103con <- initSQL( args[ database_host ],
104 args[ database_port ],
105 args[ database_u_id ],
106 args[ database_pw ] )
107
108# ---------------------------
109# Batch Flow Resp SQL Command
110# ---------------------------
111
112print( "Generating Batch Flow Resp SQL Command" )
113
114command <- paste( "SELECT * FROM batch_flow_tests WHERE branch='",
115 args[ branch_name ],
116 "' AND " ,
117 ( if( args[ old_flow ] == 'y' ) "" else "NOT " ) ,
118 "is_old_flow",
119 " ORDER BY date DESC LIMIT 3",
120 sep="" )
121
122fileData <- retrieveData( con, command )
123
124# **********************************************************
125# STEP 2: Organize data.
126# **********************************************************
127
128print( "**********************************************************" )
129print( "STEP 2: Organize Data." )
130print( "**********************************************************" )
131
132# -----------------
133# Post Data Sorting
134# -----------------
135
136print( "Sorting data for Post." )
137
138requiredColumns <- c( "posttoconfrm", "elapsepost" )
139
140tryCatch( postAvgs <- c( fileData[ requiredColumns] ),
141 error = function( e ) {
142 print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." )
143 print( "Required columns: " )
144 print( requiredColumns )
145 print( "Actual columns: " )
146 print( names( fileData ) )
147 print( "Error dump:" )
148 print( e )
149 quit( status = 1 )
150 }
151 )
152
153# -------------------------
154# Post Construct Data Frame
155# -------------------------
156
157postDataFrame <- melt( postAvgs )
158postDataFrame$scale <- fileData$scale
159postDataFrame$date <- fileData$date
160postDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
161
162colnames( postDataFrame ) <- c( "ms",
163 "type",
164 "scale",
165 "date",
166 "iterative" )
167
168# Format data frame so that the data is in the same order as it appeared in the file.
169postDataFrame$type <- as.character( postDataFrame$type )
170postDataFrame$type <- factor( postDataFrame$type,
171 levels = unique( postDataFrame$type ) )
172
173postDataFrame <- na.omit( postDataFrame ) # Omit any data that doesn't exist
174
175print( "Post Data Frame Results:" )
176print( postDataFrame )
177
178# ----------------
179# Del Data Sorting
180# ----------------
181
182requiredColumns <- c( "deltoconfrm", "elapsedel" )
183
184tryCatch( delAvgs <- c( fileData[ requiredColumns] ),
185 error = function( e ) {
186 print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." )
187 print( "Required columns: " )
188 print( requiredColumns )
189 print( "Actual columns: " )
190 print( names( fileData ) )
191 print( "Error dump:" )
192 print( e )
193 quit( status = 1 )
194 }
195 )
196
197
198# ------------------------
199# Del Construct Data Frame
200# ------------------------
201
202delDataFrame <- melt( delAvgs )
203delDataFrame$scale <- fileData$scale
204delDataFrame$date <- fileData$date
205delDataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
206
207colnames( delDataFrame ) <- c( "ms",
208 "type",
209 "scale",
210 "date",
211 "iterative" )
212
213# Format data frame so that the data is in the same order as it appeared in the file.
214delDataFrame$type <- as.character( delDataFrame$type )
215delDataFrame$type <- factor( delDataFrame$type,
216 levels = unique( delDataFrame$type ) )
217
218delDataFrame <- na.omit( delDataFrame ) # Omit any data that doesn't exist
219
220print( "Del Data Frame Results:" )
221print( delDataFrame )
222
223# **********************************************************
224# STEP 3: Generate graphs.
225# **********************************************************
226
227print( "**********************************************************" )
228print( "STEP 3: Generate Graph." )
229print( "**********************************************************" )
230
231# ------------------------------------------
232# Initializing variables used in both graphs
233# ------------------------------------------
234
235print( "Initializing variables used in both graphs." )
236
237defaultTextSize()
238xLabel <- xlab( "Build Date" )
239yLabel <- ylab( "Latency (ms)" )
240fillLabel <- labs( fill="Type" )
241
242colors <- scale_fill_manual( values=c( webColor( "redv2" ),
243 webColor( "light_blue" ) ) )
244
245wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
246
247barWidth <- 0.3
248
249theme <- graphTheme()
250
251barGraphFormat <- geom_bar( stat = "identity",
252 width = barWidth )
253
254# -----------------------
255# Post Generate Main Plot
256# -----------------------
257
258print( "Creating main plot for Post graph." )
259
260mainPlot <- ggplot( data = postDataFrame, aes( x = iterative,
261 y = ms,
262 fill = type ) )
263
264# -----------------------------------
265# Post Fundamental Variables Assigned
266# -----------------------------------
267
268print( "Generating fundamental graph data for Post graph." )
269
270xScaleConfig <- scale_x_continuous( breaks = postDataFrame$iterative,
271 label = postDataFrame$date )
272
273title <- labs( title = postChartTitle, subtitle = lastUpdatedLabel() )
274
275fundamentalGraphData <- mainPlot +
276 xScaleConfig +
277 xLabel +
278 yLabel +
279 fillLabel +
280 theme +
281 wrapLegend +
282 colors +
283 title
284
285# --------------------------------
286# Post Generating Bar Graph Format
287# --------------------------------
288
289print( "Generating bar graph for Post graph." )
290
291sum <- fileData[ 'posttoconfrm' ] +
292 fileData[ 'elapsepost' ]
293
294values <- geom_text( aes( x = postDataFrame$iterative,
295 y = sum + 0.03 * 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 barGraphFormat +
305 values
306
307# ----------------------------
308# Post Exporting Graph to File
309# ----------------------------
310
311saveGraph( postOutputFile )
312
313# ----------------------
314# Del Generate Main Plot
315# ----------------------
316
317print( "Creating main plot for Del graph." )
318
319mainPlot <- ggplot( data = delDataFrame, aes( x = iterative,
320 y = ms,
321 fill = type ) )
322
323# ----------------------------------
324# Del Fundamental Variables Assigned
325# ----------------------------------
326
327print( "Generating fundamental graph data for Del graph." )
328
329xScaleConfig <- scale_x_continuous( breaks = delDataFrame$iterative,
330 label = delDataFrame$date )
331
332title <- labs( title = delChartTitle, subtitle = lastUpdatedLabel() )
333
334fundamentalGraphData <- mainPlot +
335 xScaleConfig +
336 xLabel +
337 yLabel +
338 fillLabel +
339 theme +
340 wrapLegend +
341 colors +
342 title
343
344# -------------------------------
345# Del Generating Bar Graph Format
346# -------------------------------
347
348print( "Generating bar graph for Del graph." )
349
350sum <- fileData[ 'deltoconfrm' ] +
351 fileData[ 'elapsedel' ]
352
353values <- geom_text( aes( x = delDataFrame$iterative,
354 y = sum + 0.03 * max( sum ),
355 label = format( sum,
356 digits = 3,
357 big.mark = ",",
358 scientific = FALSE ) ),
359 size = 7.0,
360 fontface = "bold" )
361
362result <- fundamentalGraphData +
363 barGraphFormat +
364 title +
365 values
366
367# ---------------------------
368# Del Exporting Graph to File
369# ---------------------------
370
371saveGraph( delOutputFile )
372quit( status = 0 )