blob: 0ae64cfb1740ea36da22f844f8da822267464061 [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# -------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000047
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070048print( "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 SCPFhostLat",
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 -070071errBarOutputFile <- paste( args[ 7 ],
72 args[ 5 ],
73 "_",
74 args[ 6 ],
75 "_errGraph.jpg",
76 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000077
78chartTitle <- "Host Latency"
79
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070080# ------------------
81# SQL Initialization
82# ------------------
83
84print( "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# Host Latency SQL Command
95# ------------------------
96
97print( "Generating Host Latency SQL Command" )
98
99command <- paste( "SELECT * FROM host_latency_tests WHERE branch = '",
100 args[ 6 ],
101 "' AND date IN ( SELECT MAX( date ) FROM host_latency_tests WHERE branch = '",
102 args[ 6 ],
103 "' ) ",
104 sep = "" )
105
106print( "Sending SQL command:" )
107print( command )
108
109fileData <- dbGetQuery( con, command )
110
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000111
112# **********************************************************
113# STEP 2: Organize data.
114# **********************************************************
115
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700116print( "**********************************************************" )
117print( "STEP 2: Organize Data." )
118print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000119
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700120# ------------
121# Data Sorting
122# ------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000123
124print( "Sorting data." )
125avgs <- c( fileData[ 'avg' ] )
126
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700127# --------------------
128# Construct Data Frame
129# --------------------
130
131print( "Constructing Data Frame" )
132
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000133dataFrame <- melt( avgs )
134dataFrame$scale <- fileData$scale
135dataFrame$std <- fileData$std
136
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700137colnames( dataFrame ) <- c( "ms",
138 "type",
139 "scale",
140 "std" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000141
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700142dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
143
144print( "Data Frame Results:" )
145print( dataFrame )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000146
147# **********************************************************
148# STEP 3: Generate graphs.
149# **********************************************************
150
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700151print( "**********************************************************" )
152print( "STEP 3: Generate Graph." )
153print( "**********************************************************" )
154
155# ------------------
156# Generate Main Plot
157# ------------------
158
159print( "Creating main plot." )
160
161mainPlot <- ggplot( data = dataFrame, aes( x = scale,
162 y = ms,
163 ymin = ms,
164 ymax = ms + std ) )
165
166# ------------------------------
167# Fundamental Variables Assigned
168# ------------------------------
169
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000170print( "Generating fundamental graph data." )
171
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700172theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700173xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000174xLabel <- xlab( "Scale" )
175yLabel <- ylab( "Latency (ms)" )
176fillLabel <- labs( fill="Type" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700177theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face ='bold' ) )
178title <- ggtitle( chartTitle )
179errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 )
180imageWidth <- 15
181imageHeight <- 10
182imageDPI <- 200
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000183
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700184fundamentalGraphData <- mainPlot +
185 xScaleConfig +
186 xLabel +
187 yLabel +
188 fillLabel +
189 theme +
190 title
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000191
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700192# ---------------------------
193# Generating Bar Graph Format
194# ---------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000195
196print( "Generating bar graph with error bars." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000197
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700198barWidth <- 0.9
199barGraphFormat <- geom_bar( stat = "identity",
200 position = position_dodge(),
201 width = barWidth,
202 fill = "#A700EF" )
203
204errorBarFormat <- geom_errorbar( position = position_dodge(),
205 width = barWidth,
206 color = errorBarColor )
207
208values <- geom_text( aes( x=dataFrame$scale,
209 y=dataFrame$ms + 0.06 * max( dataFrame$ms ),
210 label = format( dataFrame$ms,
211 digits=3,
212 big.mark = ",",
213 scientific = FALSE ) ),
214 size = 7.0,
215 fontface = "bold" )
216
217result <- fundamentalGraphData +
218 barGraphFormat +
219 errorBarFormat +
220 values
221
222# -----------------------
223# Exporting Graph to File
224# -----------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000225
226print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000227
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700228ggsave( errBarOutputFile,
229 width = imageWidth,
230 height = imageHeight,
231 dpi = imageDPI )
232
233print( paste( "[SUCCESS] Successfully wrote bar chart out to", errBarOutputFile ) )