blob: 476cafbe7fd13db4626138eac052f7d19b32a967 [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,
21# please contact Jeremy Ronquillo: jeremyr@opennetworking.org
22
23# **********************************************************
24# STEP 1: File management.
25# **********************************************************
26
27print( "STEP 1: File management." )
28
29# Command line arguments are read. Args usually include the database filename and the output
30# directory for the graphs to save to.
31# ie: Rscript SCPFgraphGenerator SCPFsampleDataDB.csv ~/tmp/
32print( "Reading commmand-line args." )
33args <- commandArgs( trailingOnly=TRUE )
34
35# Import libraries to be used for graphing and organizing data, respectively.
36# Find out more about ggplot2: https://github.com/tidyverse/ggplot2
37# reshape2: https://github.com/hadley/reshape
38print( "Importing libraries." )
39library( ggplot2 )
40library( reshape2 )
41library( RPostgreSQL ) # For databases
42
43# Check if sufficient args are provided.
44if ( is.na( args[ 7 ] ) ){
45 print( "Usage: Rscript SCPFbatchFlowResp <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <directory-to-save-graphs>" )
46 q() # basically exit(), but in R
47}
48
49# Filenames for output graphs include the testname and the graph type.
50# See the examples below. paste() is used to concatenate strings.
51
52errBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
53errBarOutputFile <- paste( errBarOutputFile, args[ 6 ], sep="_" )
54errBarOutputFile <- paste( errBarOutputFile, "_PostGraph.jpg", sep="" )
55
56print( "Reading from databases." )
57
58con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] )
59
60command <- paste( "SELECT * FROM batch_flow_tests WHERE branch='", args[ 6 ], sep="" )
61command <- paste( command, "' ORDER BY date DESC LIMIT 3", sep="" )
62
63print( paste( "Sending SQL command:", command ) )
64
65fileData <- dbGetQuery( con, command )
66
67chartTitle <- paste( "Single Bench Flow Latency - Post", "Last 3 Builds", sep = "\n" )
68
69# **********************************************************
70# STEP 2: Organize data.
71# **********************************************************
72
73avgs <- c()
74
75print( "Sorting data." )
76avgs <- c( fileData[ 'posttoconfrm' ], fileData[ 'elapsepost' ] )
77
78dataFrame <- melt( avgs )
79dataFrame$scale <- fileData$scale
80dataFrame$date <- fileData$date
81dataFrame$iterative <- dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
82
83colnames( dataFrame ) <- c( "ms", "type", "scale", "date", "iterative" )
84
85# Format data frame so that the data is in the same order as it appeared in the file.
86dataFrame$type <- as.character( dataFrame$type )
87dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
88
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070089dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
90
91print( "Data Frame Results:" )
92print( dataFrame )
93
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000094# **********************************************************
95# STEP 3: Generate graphs.
96# **********************************************************
97
98print( "Generating fundamental graph data." )
99
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700100theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
101
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000102mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = ms, fill = type ) )
103xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$date )
104xLabel <- xlab( "date" )
105yLabel <- ylab( "Latency (ms)" )
106fillLabel <- labs( fill="Type" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700107theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000108
109fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
110
111
112print( "Generating bar graph with error bars." )
113width <- 0.3
114barGraphFormat <- geom_bar( stat="identity", width = width )
115title <- ggtitle( chartTitle )
116result <- fundamentalGraphData + barGraphFormat + title
117
118
119print( paste( "Saving bar chart to", errBarOutputFile ) )
120ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
121
122print( paste( "Successfully wrote stacked bar chart out to", errBarOutputFile ) )
123
124
125# **********************************************************
126# STEP 2: Organize data.
127# **********************************************************
128
129avgs <- c()
130
131print( "Sorting data." )
132avgs <- c( fileData[ 'deltoconfrm' ], fileData[ 'elapsedel' ] )
133
134dataFrame <- melt( avgs )
135dataFrame$scale <- fileData$scale
136dataFrame$date <- fileData$date
137dataFrame$iterative <- dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
138
139colnames( dataFrame ) <- c( "ms", "type", "scale", "date", "iterative" )
140
141# Format data frame so that the data is in the same order as it appeared in the file.
142dataFrame$type <- as.character( dataFrame$type )
143dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
144
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700145dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
146
147print( "Data Frame Results:" )
148print( dataFrame )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000149
150# **********************************************************
151# STEP 3: Generate graphs.
152# **********************************************************
153
154print( "Generating fundamental graph data." )
155
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700156theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
157
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000158mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = ms, fill = type ) )
159xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$date )
160xLabel <- xlab( "Build Date" )
161yLabel <- ylab( "Latency (ms)" )
162fillLabel <- labs( fill="Type" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700163theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000164
165fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
166
167
168print( "Generating bar graph with error bars." )
169width <- 0.3
170barGraphFormat <- geom_bar( stat="identity", width = width )
171chartTitle <- paste( "Single Bench Flow Latency - Del", "Last 3 Builds", sep = "\n" )
172title <- ggtitle( chartTitle )
173result <- fundamentalGraphData + barGraphFormat + title
174
175errBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
176errBarOutputFile <- paste( errBarOutputFile, args[ 6 ], sep="_" )
177errBarOutputFile <- paste( errBarOutputFile, "_DelGraph.jpg", sep="" )
178
179print( paste( "Saving bar chart to", errBarOutputFile ) )
180ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
181
182print( paste( "Successfully wrote stacked bar chart out to", errBarOutputFile ) )