blob: 56d0f11cad889859ae6ff32fe88d3e1b0e157462 [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.
Devin Lim0e967162017-11-03 15:59:53 -070025# **********************************************************\
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# -------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000053
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070054print( "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 SCPFhostLat",
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 -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 <- "Host Latency"
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070085# ------------------
86# SQL Initialization
87# ------------------
88
89print( "Initializing SQL" )
90
91con <- dbConnect( dbDriver( "PostgreSQL" ),
92 dbname = "onostest",
Devin Lim0e967162017-11-03 15:59:53 -070093 host = args[ database_host ],
94 port = strtoi( args[ database_port ] ),
95 user = args[ database_u_id ],
96 password = args[ database_pw ] )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070097
98# ------------------------
99# Host Latency SQL Command
100# ------------------------
101
102print( "Generating Host Latency SQL Command" )
103
104command <- paste( "SELECT * FROM host_latency_tests WHERE branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700105 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700106 "' AND date IN ( SELECT MAX( date ) FROM host_latency_tests WHERE branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700107 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700108 "' ) ",
109 sep = "" )
110
111print( "Sending SQL command:" )
112print( command )
113
114fileData <- dbGetQuery( con, command )
115
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000116
117# **********************************************************
118# STEP 2: Organize data.
119# **********************************************************
120
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700121print( "**********************************************************" )
122print( "STEP 2: Organize Data." )
123print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000124
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700125# ------------
126# Data Sorting
127# ------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000128
129print( "Sorting data." )
130avgs <- c( fileData[ 'avg' ] )
131
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700132# --------------------
133# Construct Data Frame
134# --------------------
135
136print( "Constructing Data Frame" )
137
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000138dataFrame <- melt( avgs )
139dataFrame$scale <- fileData$scale
140dataFrame$std <- fileData$std
141
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700142colnames( dataFrame ) <- c( "ms",
143 "type",
144 "scale",
145 "std" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000146
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700147dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
148
149print( "Data Frame Results:" )
150print( dataFrame )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000151
152# **********************************************************
153# STEP 3: Generate graphs.
154# **********************************************************
155
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700156print( "**********************************************************" )
157print( "STEP 3: Generate Graph." )
158print( "**********************************************************" )
159
160# ------------------
161# Generate Main Plot
162# ------------------
163
164print( "Creating main plot." )
165
166mainPlot <- ggplot( data = dataFrame, aes( x = scale,
167 y = ms,
168 ymin = ms,
169 ymax = ms + std ) )
170
171# ------------------------------
172# Fundamental Variables Assigned
173# ------------------------------
174
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000175print( "Generating fundamental graph data." )
176
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700177theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700178xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000179xLabel <- xlab( "Scale" )
180yLabel <- ylab( "Latency (ms)" )
181fillLabel <- labs( fill="Type" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700182theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face ='bold' ) )
183title <- ggtitle( chartTitle )
184errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 )
185imageWidth <- 15
186imageHeight <- 10
187imageDPI <- 200
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000188
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700189fundamentalGraphData <- mainPlot +
190 xScaleConfig +
191 xLabel +
192 yLabel +
193 fillLabel +
194 theme +
195 title
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000196
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700197# ---------------------------
198# Generating Bar Graph Format
199# ---------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000200
201print( "Generating bar graph with error bars." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000202
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700203barWidth <- 0.9
204barGraphFormat <- geom_bar( stat = "identity",
205 position = position_dodge(),
206 width = barWidth,
207 fill = "#A700EF" )
208
209errorBarFormat <- geom_errorbar( position = position_dodge(),
210 width = barWidth,
211 color = errorBarColor )
212
213values <- geom_text( aes( x=dataFrame$scale,
214 y=dataFrame$ms + 0.06 * max( dataFrame$ms ),
215 label = format( dataFrame$ms,
216 digits=3,
217 big.mark = ",",
218 scientific = FALSE ) ),
219 size = 7.0,
220 fontface = "bold" )
221
222result <- fundamentalGraphData +
223 barGraphFormat +
224 errorBarFormat +
225 values
226
227# -----------------------
228# Exporting Graph to File
229# -----------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000230
231print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000232
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700233ggsave( errBarOutputFile,
234 width = imageWidth,
235 height = imageHeight,
236 dpi = imageDPI )
237
Devin Lim0e967162017-11-03 15:59:53 -0700238print( paste( "[SUCCESS] Successfully wrote bar chart out to", errBarOutputFile ) )