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