blob: 594a515afd4557077ef85fc1c5df026168adcf2d [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
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700107dataFrame <- na.omit( avgData ) # Omit any data that doesn't exist
108
109print( "Data Frame Results:" )
110print( avgData )
111
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000112
113# **********************************************************
114# STEP 3: Generate graphs.
115# **********************************************************
116
117print( "Generating fundamental graph data." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700118
119theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000120
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) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000123yLimit <- ylim( yMin, yMax )
124xLabel <- xlab( "Scale" )
125yLabel <- ylab( "Latency (ms)" )
126fillLabel <- labs( fill="Type" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700127theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000128
129fundamentalGraphData <- mainPlot + xScaleConfig + yLimit + xLabel + yLabel + fillLabel + theme
130
131
132print( "Generating bar graph with error bars." )
133width <- 0.9
134barGraphFormat <- geom_bar( stat="identity", position=position_dodge( ), width = width )
135errorBarFormat <- geom_errorbar( position=position_dodge( ), width = width )
136title <- ggtitle( paste( chartTitle, "with Standard Error Bars" ) )
137result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
138
139
140print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
141ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
142
143
144print( paste( "Successfully wrote bar chart with error bars out to", errBarOutputFile ) )
145
146
147print( "Generating stacked bar chart." )
148stackedBarFormat <- geom_bar( stat="identity", width=width )
149title <- ggtitle( paste( chartTitle, "Total Latency" ) )
150result <- fundamentalGraphData + stackedBarFormat + title
151
152
153print( paste( "Saving stacked bar chart to", stackedBarOutputFile ) )
154ggsave( stackedBarOutputFile, width = 10, height = 6, dpi = 200 )
155
156
157print( paste( "Successfully wrote stacked bar chart out to", stackedBarOutputFile ) )