blob: 8d0b6b44e5eb4642a31db6eea8fdc16407a6eb24 [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# **********************************************************
24# STEP 1: File management.
25# **********************************************************
26
27print( "STEP 1: File management." )
28
Jeremy Ronquillob6268842017-10-03 13:02:58 -070029# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000030print( "Reading commmand-line args." )
31args <- commandArgs( trailingOnly=TRUE )
32
33# Import libraries to be used for graphing and organizing data, respectively.
34# Find out more about ggplot2: https://github.com/tidyverse/ggplot2
35# reshape2: https://github.com/hadley/reshape
36print( "Importing libraries." )
37library( ggplot2 )
38library( reshape2 )
39library( RPostgreSQL ) # For databases
40
41# Check if sufficient args are provided.
42if ( is.na( args[ 7 ] ) ){
43 print( "Usage: Rscript SCPFbatchFlowResp <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <directory-to-save-graphs>" )
44 q() # basically exit(), but in R
45}
46
Jeremy Ronquillob6268842017-10-03 13:02:58 -070047# paste() is used to concatenate strings.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000048errBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
49errBarOutputFile <- paste( errBarOutputFile, args[ 6 ], sep="_" )
50errBarOutputFile <- paste( errBarOutputFile, "_PostGraph.jpg", sep="" )
51
52print( "Reading from databases." )
53
54con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] )
55
56command <- paste( "SELECT * FROM batch_flow_tests WHERE branch='", args[ 6 ], sep="" )
57command <- paste( command, "' ORDER BY date DESC LIMIT 3", sep="" )
58
59print( paste( "Sending SQL command:", command ) )
60
61fileData <- dbGetQuery( con, command )
62
63chartTitle <- paste( "Single Bench Flow Latency - Post", "Last 3 Builds", sep = "\n" )
64
65# **********************************************************
66# STEP 2: Organize data.
67# **********************************************************
68
69avgs <- c()
70
71print( "Sorting data." )
72avgs <- c( fileData[ 'posttoconfrm' ], fileData[ 'elapsepost' ] )
73
74dataFrame <- melt( avgs )
75dataFrame$scale <- fileData$scale
76dataFrame$date <- fileData$date
77dataFrame$iterative <- dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
78
79colnames( dataFrame ) <- c( "ms", "type", "scale", "date", "iterative" )
80
81# Format data frame so that the data is in the same order as it appeared in the file.
82dataFrame$type <- as.character( dataFrame$type )
83dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
84
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070085dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
86
87print( "Data Frame Results:" )
88print( dataFrame )
89
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000090# **********************************************************
91# STEP 3: Generate graphs.
92# **********************************************************
93
94print( "Generating fundamental graph data." )
95
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -070096theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070097
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000098mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = ms, fill = type ) )
99xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$date )
Jeremy Ronquillob6268842017-10-03 13:02:58 -0700100xLabel <- xlab( "Build Date" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000101yLabel <- ylab( "Latency (ms)" )
102fillLabel <- labs( fill="Type" )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700103theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ), legend.position="bottom", legend.text=element_text( size=22 ), legend.title = element_blank(), legend.key.size = unit( 1.5, 'lines' ) )
104colors <- scale_fill_manual( values=c( "#F77670", "#619DFA" ) )
105wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000106fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
107
108
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700109print( "Generating bar graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000110width <- 0.3
111barGraphFormat <- geom_bar( stat="identity", width = width )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700112sum <- fileData[ 'posttoconfrm' ] + fileData[ 'elapsepost' ]
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700113values <- geom_text( aes( x=dataFrame$iterative, y=sum + 0.03 * max( sum ), label = format( sum, digits=3, big.mark = ",", scientific = FALSE ) ), size = 7.0, fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000114title <- ggtitle( chartTitle )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700115result <- fundamentalGraphData + barGraphFormat + colors + title + values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000116
117
118print( paste( "Saving bar chart to", errBarOutputFile ) )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700119ggsave( errBarOutputFile, width = 15, height = 10, dpi = 200 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000120
121print( paste( "Successfully wrote stacked bar chart out to", errBarOutputFile ) )
122
123
124# **********************************************************
125# STEP 2: Organize data.
126# **********************************************************
127
128avgs <- c()
129
130print( "Sorting data." )
131avgs <- c( fileData[ 'deltoconfrm' ], fileData[ 'elapsedel' ] )
132
133dataFrame <- melt( avgs )
134dataFrame$scale <- fileData$scale
135dataFrame$date <- fileData$date
136dataFrame$iterative <- dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
137
138colnames( dataFrame ) <- c( "ms", "type", "scale", "date", "iterative" )
139
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 ) )
143
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700144dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
145
146print( "Data Frame Results:" )
147print( dataFrame )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000148
149# **********************************************************
150# STEP 3: Generate graphs.
151# **********************************************************
152
153print( "Generating fundamental graph data." )
154
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700155theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700156
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000157mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = ms, fill = type ) )
158xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$date )
159xLabel <- xlab( "Build Date" )
160yLabel <- ylab( "Latency (ms)" )
161fillLabel <- labs( fill="Type" )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700162theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ), legend.position="bottom", legend.text=element_text( size=22 ), legend.title = element_blank(), legend.key.size = unit( 1.5, 'lines' ) )
163colors <- scale_fill_manual( values=c( "#F77670", "#619DFA" ) )
164wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
165fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme + wrapLegend
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000166
167
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700168print( "Generating bar graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000169width <- 0.3
170barGraphFormat <- geom_bar( stat="identity", width = width )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700171sum <- fileData[ 'deltoconfrm' ] + fileData[ 'elapsedel' ]
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700172values <- geom_text( aes( x=dataFrame$iterative, y=sum + 0.03 * max( sum ), label = format( sum, digits=3, big.mark = ",", scientific = FALSE ) ), size = 7.0, fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000173chartTitle <- paste( "Single Bench Flow Latency - Del", "Last 3 Builds", sep = "\n" )
174title <- ggtitle( chartTitle )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700175result <- fundamentalGraphData + barGraphFormat + colors + title + values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000176
177errBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
178errBarOutputFile <- paste( errBarOutputFile, args[ 6 ], sep="_" )
179errBarOutputFile <- paste( errBarOutputFile, "_DelGraph.jpg", sep="" )
180
181print( paste( "Saving bar chart to", errBarOutputFile ) )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700182ggsave( errBarOutputFile, width = 15, height = 10, dpi = 200 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000183
184print( paste( "Successfully wrote stacked bar chart out to", errBarOutputFile ) )