blob: f6da0d2534c566f018071894cfea90b4c9a37bda [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# **********************************************************
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070026print( "**********************************************************" )
27print( "STEP 1: Data management." )
28print( "**********************************************************" )
Devin Lim0e967162017-11-03 15:59:53 -070029database_host = 1
30database_port = 2
31database_u_id = 3
32database_pw = 4
33test_name = 5
34branch_name = 6
35save_directory = 7
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000036
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 SCPFgraphGenerator",
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 -070077outputFile <- 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 "_graph.jpg",
82 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000083
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070084chartTitle <- "Scale Topology Latency Test"
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000085
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070086# ------------------
87# SQL Initialization
88# ------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000089
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070090print( "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# Scale Topology SQL Command
101# --------------------------
102
103print( "Generating Scale Topology SQL Command" )
104
105command <- paste( "SELECT * FROM scale_topo_latency_details WHERE branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700106 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700107 "' AND date IN ( SELECT MAX( date ) FROM scale_topo_latency_details WHERE branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700108 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700109 "' ) ",
110 sep = "" )
111
112print( "Sending SQL command:" )
113print( command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000114fileData <- dbGetQuery( con, command )
115
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000116# **********************************************************
117# STEP 2: Organize data.
118# **********************************************************
119
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700120print( "**********************************************************" )
121print( "STEP 2: Organize Data." )
122print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000123
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700124# ------------
125# Data Sorting
126# ------------
127
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000128print( "Sorting data." )
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800129
130requiredColumns <- c( "last_role_request_to_last_topology", "last_connection_to_last_role_request", "first_connection_to_last_connection" )
131
132tryCatch( avgs <- c( fileData[ requiredColumns] ),
133 error = function( e ) {
134 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." )
135 print( "Required columns: " )
136 print( requiredColumns )
137 print( "Actual columns: " )
138 print( names( fileData ) )
139 print( "Error dump:" )
140 print( e )
141 quit( status = 1 )
142 }
143 )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700144
145# --------------------
146# Construct Data Frame
147# --------------------
148
149print( "Constructing Data Frame" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000150
151# Parse lists into data frames.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700152dataFrame <- melt( avgs )
153dataFrame$scale <- fileData$scale
154colnames( dataFrame ) <- c( "s",
155 "type",
156 "scale")
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000157
158# Format data frame so that the data is in the same order as it appeared in the file.
159dataFrame$type <- as.character( dataFrame$type )
160dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
161dataFrame$iterative <- seq( 1, nrow( fileData ), by = 1 )
162
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700163dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
164
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700165sum <- fileData[ 'last_role_request_to_last_topology' ] +
166 fileData[ 'last_connection_to_last_role_request' ] +
167 fileData[ 'first_connection_to_last_connection' ]
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700168
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700169print( "Data Frame Results:" )
170print( dataFrame )
171
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000172# **********************************************************
173# STEP 3: Generate graphs.
174# **********************************************************
175
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700176print( "**********************************************************" )
177print( "STEP 3: Generate Graph." )
178print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000179
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700180# ------------------
181# Generate Main Plot
182# ------------------
183
184print( "Creating main plot." )
185
186mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
187 y = s,
188 fill = type ) )
189
190# ------------------------------
191# Fundamental Variables Assigned
192# ------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000193
194print( "Generating fundamental graph data." )
195
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700196theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000197width <- 0.6 # Width of the bars.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700198xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative,
199 label = dataFrame$scale )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000200xLabel <- xlab( "Scale" )
Devin Lim3c2b9d62017-10-25 11:41:41 -0700201yLabel <- ylab( "Latency (s)" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000202fillLabel <- labs( fill="Type" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700203imageWidth <- 15
204imageHeight <- 10
205imageDPI <- 200
206
207theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
208 legend.position = "bottom",
209 legend.text = element_text( size=22 ),
210 legend.title = element_blank(),
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800211 legend.key.size = unit( 1.5, 'lines' ),
212 plot.subtitle = element_text( size=16, hjust=1.0 ) )
213
214subtitle <- paste( "Last Updated: ", format( Sys.time(), format = "%b %d, %Y at %I:%M %p %Z" ), sep="" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700215
216values <- geom_text( aes( x = dataFrame$iterative,
217 y = sum + 0.02 * max( sum ),
218 label = format( sum,
219 big.mark = ",",
220 scientific = FALSE ),
221 fontface = "bold" ),
222 size = 7.0 )
223
224wrapLegend <- guides( fill = guide_legend( nrow=2, byrow=TRUE ) )
225
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800226title <- labs( title = chartTitle, subtitle = subtitle )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700227
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000228# Store plot configurations as 1 variable
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700229fundamentalGraphData <- mainPlot +
230 xScaleConfig +
231 xLabel +
232 yLabel +
233 fillLabel +
234 theme +
235 values +
236 wrapLegend +
237 title
238
239# ---------------------------
240# Generating Bar Graph Format
241# ---------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000242
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700243print( "Generating bar graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000244
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700245barGraphFormat <- geom_bar( stat = "identity", width = width )
246
247result <- fundamentalGraphData +
248 barGraphFormat
249
250# -----------------------
251# Exporting Graph to File
252# -----------------------
253
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700254print( paste( "Saving bar chart to", outputFile ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700255
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800256tryCatch( ggsave( outputFile,
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 out to", outputFile ) )
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800268quit( status = 0 )