blob: 6ec30989323931dcfb260ab5d4fa3db78d7f0a45 [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# Normal usage
44# Check if sufficient args are provided.
45if ( is.na( args[ 7 ] ) ){
46 print( "Usage: Rscript SCPFmastershipFailoverLat <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <directory-to-save-graphs>" )
47 q() # basically exit(), but in R
48}
49
50# Filenames for output graphs include the testname and the graph type.
51# See the examples below. paste() is used to concatenate strings.
52
53errBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
54errBarOutputFile <- paste( errBarOutputFile, args[ 6 ], sep="_" )
55errBarOutputFile <- paste( errBarOutputFile, "_errGraph.jpg", sep="" )
56
57stackedBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
58stackedBarOutputFile <- paste( stackedBarOutputFile, args[ 6 ], sep="_" )
59stackedBarOutputFile <- paste( stackedBarOutputFile, "_stackedGraph.jpg", sep="" )
60
61print( "Reading from databases." )
62
63con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] )
64
65command <- paste( "SELECT * FROM mastership_failover_tests WHERE branch = '", args[ 6 ], sep = "" )
66command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM mastership_failover_tests WHERE branch = '", sep = "" )
67command <- paste( command, args[ 6 ], sep = "" )
68command <- paste( command, "' ) ", sep="" )
69
70print( paste( "Sending SQL command:", command ) )
71
72fileData <- dbGetQuery( con, command )
73
74chartTitle <- "Mastership Failover Latency"
75
76
77# **********************************************************
78# STEP 2: Organize data.
79# **********************************************************
80
81fileDataNames <- names( fileData )
82
83avgs <- c()
84stds <- c()
85
86
87print( "Sorting data." )
88for ( name in fileDataNames ){
89 nameLen <- nchar( name )
90 if ( nameLen > 2 ){
91 if ( substring( name, nameLen - 2, nameLen ) == "avg" ){
92 avgs <- c( avgs, fileData[ name ] )
93 }
94 if ( substring( name, nameLen - 2, nameLen ) == "std" ){
95 stds <- c( stds, fileData[ name ] )
96 }
97 }
98}
99
100avgData <- melt( avgs )
101avgData$scale <- fileData$scale
102colnames( avgData ) <- c( "ms", "type", "scale" )
103
104stdData <- melt( stds )
105colnames( stdData ) <- c( "ms", "type" )
106
107
108# **********************************************************
109# STEP 3: Generate graphs.
110# **********************************************************
111
112print( "Generating fundamental graph data." )
113barBaseLength <- 16
114if (min( c( avgData$ms, stdData$ms ) ) < 0){
115 yMin <- min( c( avgData$ms, stdData$ms ) )
116} else {
117 yMin <- 0
118}
119yMax <- max( c( avgData$ms, stdData$ms, max( avgs$deact_role_avg + avgs$kill_deact_avg ) ) ) * 1.05
120
121mainPlot <- ggplot( data = avgData, aes( x = scale, y = ms, ymin = ms - stdData$ms, ymax = ms + stdData$ms,fill = type ) )
122xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
123#xLimit <- xlim( min( avgData$scale - 1 ), max( avgData$scale + 1 ) )
124yLimit <- ylim( yMin, yMax )
125xLabel <- xlab( "Scale" )
126yLabel <- ylab( "Latency (ms)" )
127fillLabel <- labs( fill="Type" )
128theme <- theme( plot.title=element_text( hjust = 0.5, size = 18, face='bold' ) )
129
130fundamentalGraphData <- mainPlot + xScaleConfig + yLimit + xLabel + yLabel + fillLabel + theme
131
132
133print( "Generating bar graph with error bars." )
134width <- 0.9
135barGraphFormat <- geom_bar( stat="identity", position=position_dodge( ), width = width )
136errorBarFormat <- geom_errorbar( position=position_dodge( ), width = width )
137title <- ggtitle( paste( chartTitle, "with Standard Error Bars" ) )
138result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
139
140
141print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
142ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
143
144
145print( paste( "Successfully wrote bar chart with error bars out to", errBarOutputFile ) )
146
147
148print( "Generating stacked bar chart." )
149stackedBarFormat <- geom_bar( stat="identity", width=width )
150title <- ggtitle( paste( chartTitle, "Total Latency" ) )
151result <- fundamentalGraphData + stackedBarFormat + title
152
153
154print( paste( "Saving stacked bar chart to", stackedBarOutputFile ) )
155ggsave( stackedBarOutputFile, width = 10, height = 6, dpi = 200 )
156
157
158print( paste( "Successfully wrote stacked bar chart out to", stackedBarOutputFile ) )