blob: 87f1f57f4b3cbd725b5603eecde5532959ade2c1 [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 SCPFgraphGenerator <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
52outputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
53outputFile <- paste( outputFile, args[ 6 ], sep="_" )
54outputFile <- paste( outputFile, "_graph.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 scale_topo_latency_details WHERE branch = '", args[ 6 ], sep = "" )
61command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM scale_topo_latency_details WHERE branch = '", sep = "" )
62command <- paste( command, args[ 6 ], sep = "" )
63command <- paste( command, "' ) ", sep="" )
64
65print( paste( "Sending SQL command:", command ) )
66
67fileData <- dbGetQuery( con, command )
68
69title <- paste( args[ 5 ], args[ 6 ], sep="_" )
70
71# **********************************************************
72# STEP 2: Organize data.
73# **********************************************************
74
75print( "STEP 2: Organize data." )
76
77# Create lists c() and organize data into their corresponding list.
78print( "Sorting data." )
79avgs <- c( fileData[ 'last_role_request_to_last_topology' ], fileData[ 'last_connection_to_last_role_request' ], fileData[ 'first_connection_to_last_connection' ] )
80
81# Parse lists into data frames.
82dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame
83dataFrame$scale <- fileData$scale # Add node scaling to the data frame.
84colnames( dataFrame ) <- c( "ms", "type", "scale")
85
86
87# Format data frame so that the data is in the same order as it appeared in the file.
88dataFrame$type <- as.character( dataFrame$type )
89dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
90dataFrame$iterative <- seq( 1, nrow( fileData ), by = 1 )
91
92# Obtain the sum of the averages for the plot size and center of standard deviation bars.
93avgsSum <- fileData$total_time
94
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070095dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
96
97print( "Data Frame Results:" )
98print( dataFrame )
99
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000100# **********************************************************
101# STEP 3: Generate graphs.
102# **********************************************************
103
104print( "STEP 3: Generate graphs." )
105
106# 1. Graph fundamental data is generated first.
107# These are variables that apply to all of the graphs being generated, regardless of type.
108#
109# 2. Type specific graph data is generated.
110# Data specific for the error bar and stacked bar graphs are generated.
111#
112# 3. Generate and save the graphs.
113# Graphs are saved to the filename above, in the directory provided in command line args
114
115print( "Generating fundamental graph data." )
116
117# Calculate window to display graph, based on the lowest and highest points of the data.
118if ( min( avgsSum ) < 0){
119 yWindowMin <- min( avgsSum ) * 1.05
120} else {
121 yWindowMin <- 0
122}
123yWindowMax <- max( avgsSum )
124
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700125theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
126
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000127# Create the primary plot here.
128# ggplot contains the following arguments:
129# - data: the data frame that the graph will be based off of
130# - aes: the asthetics of the graph which require:
131# - x: x-axis values (usually node scaling)
132# - y: y-axis values (usually time in milliseconds)
133# - fill: the category of the colored side-by-side bars (usually type)
134mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = ms, fill = type ) )
135
136# Formatting the plot
137width <- 0.6 # Width of the bars.
138xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$scale )
139yLimit <- ylim( yWindowMin, yWindowMax )
140xLabel <- xlab( "Scale" )
141yLabel <- ylab( "Latency (ms)" )
142fillLabel <- labs( fill="Type" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700143chartTitle <- paste( "Scale Topology Latency Test" )
144theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000145
146# Store plot configurations as 1 variable
147fundamentalGraphData <- mainPlot + xScaleConfig + yLimit + xLabel + yLabel + fillLabel + theme
148
149# Create the stacked bar graph with error bars.
150# geom_bar contains:
151# - stat: data formatting (usually "identity")
152# - width: the width of the bar types (declared above)
153# geom_errorbar contains similar arguments as geom_bar.
154print( "Generating bar graph with error bars." )
155barGraphFormat <- geom_bar( stat = "identity", width = width )
156title <- ggtitle( paste( chartTitle, "" ) )
157result <- fundamentalGraphData + barGraphFormat + title
158
159# Save graph to file
160print( paste( "Saving bar chart with error bars to", outputFile ) )
161ggsave( outputFile, width = 10, height = 6, dpi = 200 )
162print( paste( "Successfully wrote bar chart with error bars out to", outputFile ) )