blob: fdb39e4829c8bda6c0f0278af238e0d0cceb6d26 [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 Ronquillo6df87812017-08-28 16:17:36 +000068 q() # basically exit(), but in R
69}
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 Ronquillo7673f802017-10-30 09:42:44 -0700129avgs <- c( fileData[ 'last_role_request_to_last_topology' ],
130 fileData[ 'last_connection_to_last_role_request' ],
131 fileData[ 'first_connection_to_last_connection' ] )
132
133# --------------------
134# Construct Data Frame
135# --------------------
136
137print( "Constructing Data Frame" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000138
139# Parse lists into data frames.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700140dataFrame <- melt( avgs )
141dataFrame$scale <- fileData$scale
142colnames( dataFrame ) <- c( "s",
143 "type",
144 "scale")
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000145
146# Format data frame so that the data is in the same order as it appeared in the file.
147dataFrame$type <- as.character( dataFrame$type )
148dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
149dataFrame$iterative <- seq( 1, nrow( fileData ), by = 1 )
150
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700151dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
152
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700153sum <- fileData[ 'last_role_request_to_last_topology' ] +
154 fileData[ 'last_connection_to_last_role_request' ] +
155 fileData[ 'first_connection_to_last_connection' ]
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700156
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700157print( "Data Frame Results:" )
158print( dataFrame )
159
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000160# **********************************************************
161# STEP 3: Generate graphs.
162# **********************************************************
163
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700164print( "**********************************************************" )
165print( "STEP 3: Generate Graph." )
166print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000167
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700168# ------------------
169# Generate Main Plot
170# ------------------
171
172print( "Creating main plot." )
173
174mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
175 y = s,
176 fill = type ) )
177
178# ------------------------------
179# Fundamental Variables Assigned
180# ------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000181
182print( "Generating fundamental graph data." )
183
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700184theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000185width <- 0.6 # Width of the bars.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700186xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative,
187 label = dataFrame$scale )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000188xLabel <- xlab( "Scale" )
Devin Lim3c2b9d62017-10-25 11:41:41 -0700189yLabel <- ylab( "Latency (s)" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000190fillLabel <- labs( fill="Type" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700191imageWidth <- 15
192imageHeight <- 10
193imageDPI <- 200
194
195theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
196 legend.position = "bottom",
197 legend.text = element_text( size=22 ),
198 legend.title = element_blank(),
199 legend.key.size = unit( 1.5, 'lines' ) )
200
201values <- geom_text( aes( x = dataFrame$iterative,
202 y = sum + 0.02 * max( sum ),
203 label = format( sum,
204 big.mark = ",",
205 scientific = FALSE ),
206 fontface = "bold" ),
207 size = 7.0 )
208
209wrapLegend <- guides( fill = guide_legend( nrow=2, byrow=TRUE ) )
210
211title <- ggtitle( chartTitle, "" )
212
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000213# Store plot configurations as 1 variable
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700214fundamentalGraphData <- mainPlot +
215 xScaleConfig +
216 xLabel +
217 yLabel +
218 fillLabel +
219 theme +
220 values +
221 wrapLegend +
222 title
223
224# ---------------------------
225# Generating Bar Graph Format
226# ---------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000227
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700228print( "Generating bar graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000229
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700230barGraphFormat <- geom_bar( stat = "identity", width = width )
231
232result <- fundamentalGraphData +
233 barGraphFormat
234
235# -----------------------
236# Exporting Graph to File
237# -----------------------
238
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700239print( paste( "Saving bar chart to", outputFile ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700240
241ggsave( outputFile,
242 width = imageWidth,
243 height = imageHeight,
244 dpi = imageDPI )
245
246print( paste( "[SUCCESS] Successfully wrote bar chart out to", outputFile ) )