blob: 940a14b5db2d453a9b219c6a0ba46a0550c9852a [file] [log] [blame]
Jeremy Ronquillodae11042018-02-21 09:21:44 -08001# 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# Example script:
21# Cbench Graph (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFcbench_master_errGraph.jpg):
22# Rscript SCPFspecificGraphRScripts/SCPFcbench.R <url> <port> <username> <pass> SCPFcbench master /path/to/save/directory/
23
24# **********************************************************
25# STEP 1: Data management.
26# **********************************************************
27
28print( "**********************************************************" )
29print( "STEP 1: Data management." )
30print( "**********************************************************" )
31
32save_directory <- 7
33
34# Command line arguments are read.
35print( "Reading commmand-line args." )
36args <- commandArgs( trailingOnly=TRUE )
37
38# ----------------
39# Import Libraries
40# ----------------
41
42print( "Importing libraries." )
43library( ggplot2 )
44library( reshape2 )
45library( RPostgreSQL ) # For databases
Devin Lim324806b2018-05-11 15:36:52 -070046source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" )
47source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" )
48source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" )
49source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" )
Jeremy Ronquillodae11042018-02-21 09:21:44 -080050
51# -------------------
52# Check CLI Arguments
53# -------------------
54
55print( "Verifying CLI args." )
56
57if ( length( args ) != save_directory ){
58 usage( "SCPFcbench.R" )
59 quit( status = 1 )
60}
61
62# -----------------
63# Create File Names
64# -----------------
65
66print( "Creating filenames and title of graph." )
67
68errBarOutputFile <- paste( args[ save_directory ],
69 args[ graph_title ],
70 "_",
71 args[ branch_name ],
72 "_errGraph.jpg",
73 sep="" )
74
75chartTitle <- paste( "Single-Node CBench Throughput", "Last 3 Builds", sep = "\n" )
76
77# ------------------
78# SQL Initialization
79# ------------------
80
81print( "Initializing SQL" )
82
83con <- initSQL( args[ database_host ],
84 args[ database_port ],
85 args[ database_u_id ],
86 args[ database_pw ] )
87
88# ------------------
89# Cbench SQL Command
90# ------------------
91
92print( "Generating Scale Topology SQL Command" )
93
94command <- paste( "SELECT * FROM cbench_bm_tests WHERE branch='",
95 args[ branch_name ],
96 "' ORDER BY date DESC LIMIT 3",
97 sep="" )
98
99fileData <- retrieveData( con, command )
100
101# **********************************************************
102# STEP 2: Organize data.
103# **********************************************************
104
105print( "**********************************************************" )
106print( "STEP 2: Organize Data." )
107print( "**********************************************************" )
108
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800109latestBuildDate <- fileData$date[1]
110
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800111# ------------
112# Data Sorting
113# ------------
114
115print( "Sorting data." )
116
117requiredColumns <- c( "avg" )
118
119tryCatch( avgs <- c( fileData[ requiredColumns] ),
120 error = function( e ) {
121 print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." )
122 print( "Required columns: " )
123 print( requiredColumns )
124 print( "Actual columns: " )
125 print( names( fileData ) )
126 print( "Error dump:" )
127 print( e )
128 quit( status = 1 )
129 }
130 )
131
132
133# --------------------
134# Construct Data Frame
135# --------------------
136
137print( "Constructing Data Frame" )
138
139dataFrame <- melt( avgs )
140dataFrame$std <- c( fileData$std )
141dataFrame$date <- c( fileData$date )
142dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
143
144colnames( dataFrame ) <- c( "ms",
145 "type",
146 "std",
147 "date",
148 "iterative" )
149
150dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
151
152print( "Data Frame Results:" )
153print( dataFrame )
154
155# **********************************************************
156# STEP 3: Generate graphs.
157# **********************************************************
158
159print( "**********************************************************" )
160print( "STEP 3: Generate Graph." )
161print( "**********************************************************" )
162
163# ------------------
164# Generate Main Plot
165# ------------------
166
167print( "Creating main plot." )
168
169mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
170 y = ms,
171 ymin = ms,
172 ymax = ms + std ) )
173
174# ------------------------------
175# Fundamental Variables Assigned
176# ------------------------------
177
178print( "Generating fundamental graph data." )
179
180defaultTextSize()
181
182barWidth <- 0.3
183
184xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative,
185 label = dataFrame$date )
186xLabel <- xlab( "Build Date" )
187yLabel <- ylab( "Responses / sec" )
188fillLabel <- labs( fill = "Type" )
189
190theme <- graphTheme()
191
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800192title <- labs( title = chartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800193
194fundamentalGraphData <- mainPlot +
195 xScaleConfig +
196 xLabel +
197 yLabel +
198 fillLabel +
199 theme +
200 title
201
202# ---------------------------
203# Generating Bar Graph Format
204# ---------------------------
205
206print( "Generating bar graph with error bars." )
207
208barGraphFormat <- geom_bar( stat = "identity",
209 position = position_dodge(),
210 width = barWidth,
211 fill = webColor( "green" ) )
212
213errorBarFormat <- geom_errorbar( width = barWidth,
214 color = webColor( "darkerGray" ) )
215
216values <- geom_text( aes( x=dataFrame$iterative,
217 y=fileData[ 'avg' ] + 0.025 * max( fileData[ 'avg' ] ),
218 label = format( fileData[ 'avg' ],
219 digits=3,
220 big.mark = ",",
221 scientific = FALSE ) ),
222 size = 7.0,
223 fontface = "bold" )
224
225result <- fundamentalGraphData +
226 barGraphFormat +
227 errorBarFormat +
228 values
229
230# -----------------------
231# Exporting Graph to File
232# -----------------------
233
234saveGraph( errBarOutputFile ) # from saveGraph.R