blob: fa59c55ea18488103deab6f691580fe4517a76e0 [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 SCPFcbench",
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 <- paste( "Single-Node CBench Throughput", "Last 3 Builds", sep = "\n" )
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# Cbench SQL Command
95# ------------------
96
97print( "Generating Scale Topology SQL Command" )
98
99command <- paste( "SELECT * FROM cbench_bm_tests WHERE branch='",
100 args[ 6 ],
101 "' ORDER BY date DESC LIMIT 3",
102 sep="" )
103
104print( "Sending SQL command:" )
105print( command )
106
107fileData <- dbGetQuery( con, command )
108
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000109# **********************************************************
110# STEP 2: Organize data.
111# **********************************************************
112
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700113print( "**********************************************************" )
114print( "STEP 2: Organize Data." )
115print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000116
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700117# ------------
118# Data Sorting
119# ------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000120
121print( "Sorting data." )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700122
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000123avgs <- c( fileData[ 'avg' ] )
124
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700125# --------------------
126# Construct Data Frame
127# --------------------
128
129print( "Constructing Data Frame" )
130
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000131dataFrame <- melt( avgs )
132dataFrame$std <- c( fileData$std )
133dataFrame$date <- c( fileData$date )
134dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
135
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700136colnames( dataFrame ) <- c( "ms",
137 "type",
138 "std",
139 "date",
140 "iterative" )
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 )
146
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000147# **********************************************************
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 = iterative,
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." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700171
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 -0700173barWidth <- 0.3
174xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative,
175 label = dataFrame$date )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700176xLabel <- xlab( "Build Date" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000177yLabel <- ylab( "Responses / sec" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700178fillLabel <- labs( fill = "Type" )
179imageWidth <- 15
180imageHeight <- 10
181imageDPI <- 200
182errorBarColor <- rgb( 140,140,140, maxColorValue=255 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000183
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700184theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
185 legend.position = "bottom",
186 legend.text = element_text( size = 18, face = "bold" ),
187 legend.title = element_blank() )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000188
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700189title <- ggtitle( chartTitle )
190
191fundamentalGraphData <- mainPlot +
192 xScaleConfig +
193 xLabel +
194 yLabel +
195 fillLabel +
196 theme +
197 title
198
199# ---------------------------
200# Generating Bar Graph Format
201# ---------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000202
203print( "Generating bar graph with error bars." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000204
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700205barGraphFormat <- geom_bar( stat = "identity",
206 position = position_dodge(),
207 width = barWidth,
208 fill = "#00AA13" )
209
210errorBarFormat <- geom_errorbar( width = barWidth,
211 color = errorBarColor )
212
213values <- geom_text( aes( x=dataFrame$iterative,
214 y=fileData[ 'avg' ] + 0.025 * max( fileData[ 'avg' ] ),
215 label = format( fileData[ 'avg' ],
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 Ronquillo7673f802017-10-30 09:42:44 -0700232
233ggsave( errBarOutputFile,
234 width = imageWidth,
235 height = imageHeight,
236 dpi = imageDPI )
237
238print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) )