blob: 8344efbf0304e7a5726cd04567b1ba1178427e18 [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 SCPFgraphGenerator",
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 -070071outputFile <- paste( args[ 7 ],
72 args[ 5 ],
73 "_",
74 args[ 6 ],
75 "_graph.jpg",
76 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000077
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070078chartTitle <- "Scale Topology Latency Test"
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000079
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070080# ------------------
81# SQL Initialization
82# ------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000083
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070084print( "Initializing SQL" )
85
86con <- dbConnect( dbDriver( "PostgreSQL" ),
87 dbname = "onostest",
88 host = args[ 1 ],
89 port = strtoi( args[ 2 ] ),
90 user = args[ 3 ],
91 password = args[ 4 ] )
92
93# --------------------------
94# Scale Topology SQL Command
95# --------------------------
96
97print( "Generating Scale Topology SQL Command" )
98
99command <- paste( "SELECT * FROM scale_topo_latency_details WHERE branch = '",
100 args[ 6 ],
101 "' AND date IN ( SELECT MAX( date ) FROM scale_topo_latency_details WHERE branch = '",
102 args[ 6 ],
103 "' ) ",
104 sep = "" )
105
106print( "Sending SQL command:" )
107print( command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000108fileData <- dbGetQuery( con, command )
109
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000110# **********************************************************
111# STEP 2: Organize data.
112# **********************************************************
113
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700114print( "**********************************************************" )
115print( "STEP 2: Organize Data." )
116print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000117
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700118# ------------
119# Data Sorting
120# ------------
121
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000122print( "Sorting data." )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700123avgs <- c( fileData[ 'last_role_request_to_last_topology' ],
124 fileData[ 'last_connection_to_last_role_request' ],
125 fileData[ 'first_connection_to_last_connection' ] )
126
127# --------------------
128# Construct Data Frame
129# --------------------
130
131print( "Constructing Data Frame" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000132
133# Parse lists into data frames.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700134dataFrame <- melt( avgs )
135dataFrame$scale <- fileData$scale
136colnames( dataFrame ) <- c( "s",
137 "type",
138 "scale")
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000139
140# Format data frame so that the data is in the same order as it appeared in the file.
141dataFrame$type <- as.character( dataFrame$type )
142dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
143dataFrame$iterative <- seq( 1, nrow( fileData ), by = 1 )
144
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700145dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
146
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700147sum <- fileData[ 'last_role_request_to_last_topology' ] +
148 fileData[ 'last_connection_to_last_role_request' ] +
149 fileData[ 'first_connection_to_last_connection' ]
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700150
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700151print( "Data Frame Results:" )
152print( dataFrame )
153
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000154# **********************************************************
155# STEP 3: Generate graphs.
156# **********************************************************
157
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700158print( "**********************************************************" )
159print( "STEP 3: Generate Graph." )
160print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000161
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700162# ------------------
163# Generate Main Plot
164# ------------------
165
166print( "Creating main plot." )
167
168mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
169 y = s,
170 fill = type ) )
171
172# ------------------------------
173# Fundamental Variables Assigned
174# ------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000175
176print( "Generating fundamental graph data." )
177
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700178theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000179width <- 0.6 # Width of the bars.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700180xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative,
181 label = dataFrame$scale )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000182xLabel <- xlab( "Scale" )
Devin Lim3c2b9d62017-10-25 11:41:41 -0700183yLabel <- ylab( "Latency (s)" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000184fillLabel <- labs( fill="Type" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700185imageWidth <- 15
186imageHeight <- 10
187imageDPI <- 200
188
189theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
190 legend.position = "bottom",
191 legend.text = element_text( size=22 ),
192 legend.title = element_blank(),
193 legend.key.size = unit( 1.5, 'lines' ) )
194
195values <- geom_text( aes( x = dataFrame$iterative,
196 y = sum + 0.02 * max( sum ),
197 label = format( sum,
198 big.mark = ",",
199 scientific = FALSE ),
200 fontface = "bold" ),
201 size = 7.0 )
202
203wrapLegend <- guides( fill = guide_legend( nrow=2, byrow=TRUE ) )
204
205title <- ggtitle( chartTitle, "" )
206
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000207# Store plot configurations as 1 variable
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700208fundamentalGraphData <- mainPlot +
209 xScaleConfig +
210 xLabel +
211 yLabel +
212 fillLabel +
213 theme +
214 values +
215 wrapLegend +
216 title
217
218# ---------------------------
219# Generating Bar Graph Format
220# ---------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000221
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700222print( "Generating bar graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000223
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700224barGraphFormat <- geom_bar( stat = "identity", width = width )
225
226result <- fundamentalGraphData +
227 barGraphFormat
228
229# -----------------------
230# Exporting Graph to File
231# -----------------------
232
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700233print( paste( "Saving bar chart to", outputFile ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700234
235ggsave( outputFile,
236 width = imageWidth,
237 height = imageHeight,
238 dpi = imageDPI )
239
240print( paste( "[SUCCESS] Successfully wrote bar chart out to", outputFile ) )