blob: 9d1972a1b9c7765317257eda8454aa1f89cbf1f2 [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 Ronquillob6268842017-10-03 13:02:58 -070037# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000038print( "Reading commmand-line args." )
39args <- commandArgs( trailingOnly=TRUE )
40
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070041# ----------------
42# Import Libraries
43# ----------------
44
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000045print( "Importing libraries." )
46library( ggplot2 )
47library( reshape2 )
48library( RPostgreSQL ) # For databases
49
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070050# -------------------
51# Check CLI Arguments
52# -------------------
53
54print( "Verifying CLI args." )
55
Devin Lim0e967162017-11-03 15:59:53 -070056if ( is.na( args[ save_directory ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070057
58 print( paste( "Usage: Rscript SCPFcbench",
59 "<database-host>",
60 "<database-port>",
61 "<database-user-id>",
62 "<database-password>",
63 "<test-name>",
64 "<branch-name>",
65 "<directory-to-save-graphs>",
66 sep=" " ) )
67
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -080068 quit( status = 1 ) # basically exit(), but in R
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000069}
70
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070071# -----------------
72# Create File Names
73# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000074
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070075print( "Creating filenames and title of graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000076
Devin Lim0e967162017-11-03 15:59:53 -070077errBarOutputFile <- paste( args[ save_directory ],
78 args[ test_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070079 "_",
Devin Lim0e967162017-11-03 15:59:53 -070080 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070081 "_errGraph.jpg",
82 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000083
84chartTitle <- paste( "Single-Node CBench Throughput", "Last 3 Builds", sep = "\n" )
85
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070086# ------------------
87# SQL Initialization
88# ------------------
89
90print( "Initializing SQL" )
91
92con <- dbConnect( dbDriver( "PostgreSQL" ),
93 dbname = "onostest",
Devin Lim0e967162017-11-03 15:59:53 -070094 host = args[ database_host ],
95 port = strtoi( args[ database_port ] ),
96 user = args[ database_u_id ],
97 password = args[ database_pw ] )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070098
99# ------------------
100# Cbench SQL Command
101# ------------------
102
103print( "Generating Scale Topology SQL Command" )
104
105command <- paste( "SELECT * FROM cbench_bm_tests WHERE branch='",
Devin Lim0e967162017-11-03 15:59:53 -0700106 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700107 "' ORDER BY date DESC LIMIT 3",
108 sep="" )
109
110print( "Sending SQL command:" )
111print( command )
112
113fileData <- dbGetQuery( con, command )
114
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000115# **********************************************************
116# STEP 2: Organize data.
117# **********************************************************
118
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700119print( "**********************************************************" )
120print( "STEP 2: Organize Data." )
121print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000122
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700123# ------------
124# Data Sorting
125# ------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000126
127print( "Sorting data." )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700128
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800129requiredColumns <- c( "avg" )
130
131tryCatch( avgs <- c( fileData[ requiredColumns] ),
132 error = function( e ) {
133 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." )
134 print( "Required columns: " )
135 print( requiredColumns )
136 print( "Actual columns: " )
137 print( names( fileData ) )
138 print( "Error dump:" )
139 print( e )
140 quit( status = 1 )
141 }
142 )
143
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000144
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700145# --------------------
146# Construct Data Frame
147# --------------------
148
149print( "Constructing Data Frame" )
150
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000151dataFrame <- melt( avgs )
152dataFrame$std <- c( fileData$std )
153dataFrame$date <- c( fileData$date )
154dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
155
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700156colnames( dataFrame ) <- c( "ms",
157 "type",
158 "std",
159 "date",
160 "iterative" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000161
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700162dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
163
164print( "Data Frame Results:" )
165print( dataFrame )
166
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000167# **********************************************************
168# STEP 3: Generate graphs.
169# **********************************************************
170
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700171print( "**********************************************************" )
172print( "STEP 3: Generate Graph." )
173print( "**********************************************************" )
174
175# ------------------
176# Generate Main Plot
177# ------------------
178
179print( "Creating main plot." )
180
181mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
182 y = ms,
183 ymin = ms,
184 ymax = ms + std ) )
185
186# ------------------------------
187# Fundamental Variables Assigned
188# ------------------------------
189
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000190print( "Generating fundamental graph data." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700191
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700192theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700193barWidth <- 0.3
194xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative,
195 label = dataFrame$date )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700196xLabel <- xlab( "Build Date" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000197yLabel <- ylab( "Responses / sec" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700198fillLabel <- labs( fill = "Type" )
199imageWidth <- 15
200imageHeight <- 10
201imageDPI <- 200
202errorBarColor <- rgb( 140,140,140, maxColorValue=255 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000203
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700204theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
205 legend.position = "bottom",
206 legend.text = element_text( size = 18, face = "bold" ),
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800207 legend.title = element_blank(),
208 plot.subtitle = element_text( size=16, hjust=1.0 ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000209
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800210subtitle <- paste( "Last Updated: ", format( Sys.time(), format = "%b %d, %Y at %I:%M %p %Z" ), sep="" )
211
212title <- labs( title = chartTitle, subtitle = subtitle )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700213
214fundamentalGraphData <- mainPlot +
215 xScaleConfig +
216 xLabel +
217 yLabel +
218 fillLabel +
219 theme +
220 title
221
222# ---------------------------
223# Generating Bar Graph Format
224# ---------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000225
226print( "Generating bar graph with error bars." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000227
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700228barGraphFormat <- geom_bar( stat = "identity",
229 position = position_dodge(),
230 width = barWidth,
231 fill = "#00AA13" )
232
233errorBarFormat <- geom_errorbar( width = barWidth,
234 color = errorBarColor )
235
236values <- geom_text( aes( x=dataFrame$iterative,
237 y=fileData[ 'avg' ] + 0.025 * max( fileData[ 'avg' ] ),
238 label = format( fileData[ 'avg' ],
239 digits=3,
240 big.mark = ",",
241 scientific = FALSE ) ),
242 size = 7.0,
243 fontface = "bold" )
244
245result <- fundamentalGraphData +
246 barGraphFormat +
247 errorBarFormat +
248 values
249
250# -----------------------
251# Exporting Graph to File
252# -----------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000253
254print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700255
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800256tryCatch( ggsave( errBarOutputFile,
257 width = imageWidth,
258 height = imageHeight,
259 dpi = imageDPI ),
260 error = function( e ){
261 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
262 print( e )
263 quit( status = 1 )
264 }
265 )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700266
267print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) )