blob: a8d824897577da8a2180d0fe8cb9abe93467f9e5 [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[ 9 ] ) ){
46 print( "Usage: Rscript SCPFIntentEventTp.R <has-flow-obj> <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <has-neighbors> <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[ 9 ], args[ 6 ], sep="" )
54errBarOutputFile <- paste( errBarOutputFile, args[ 7 ], sep="_" )
55if ( args[ 8 ] == 'y' ){
56 errBarOutputFile <- paste( errBarOutputFile, "all-neighbors", sep="_" )
57} else {
58 errBarOutputFile <- paste( errBarOutputFile, "no-neighbors", sep="_" )
59}
60if ( args[ 1 ] == 'y' ){
61 errBarOutputFile <- paste( errBarOutputFile, "flowObj", sep="_")
62}
63errBarOutputFile <- paste( errBarOutputFile, "_graph.jpg", sep="" )
64
65print( "Reading from databases." )
66con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 2 ], port=strtoi( args[ 3 ] ), user=args[ 4 ],password=args[ 5 ] )
67
68commandNeighborModifier <- ""
69flowObjModifier <- ""
70if ( args[ 1 ] == 'y' ){
71 flowObjModifier <- "_fobj"
72}
73if ( args[ 8 ] == 'y' ){
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070074 commandNeighborModifier <- "scale=1 OR NOT "
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000075}
76
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070077command <- paste( "SELECT scale, SUM( avg ) as avg FROM intent_tp", flowObjModifier, sep="" )
78command <- paste( command, "_tests WHERE (", sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000079command <- paste( command, commandNeighborModifier, sep="" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070080command <- paste( command, "neighbors = 0 ) AND branch = '", sep="")
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000081command <- paste( command, args[ 7 ], sep="" )
82command <- paste( command, "' AND date IN ( SELECT max( date ) FROM intent_tp", sep="" )
83command <- paste( command, flowObjModifier, sep="" )
84command <- paste( command, "_tests WHERE branch='", sep="" )
85command <- paste( command, args[ 7 ], sep="" )
86command <- paste( command, "' ) GROUP BY scale ORDER BY scale", sep="" )
87
88print( paste( "Sending SQL command:", command ) )
89
90fileData <- dbGetQuery( con, command )
91
92title <- paste( args[ 6 ], args[ 7 ], sep="_" )
93
94# **********************************************************
95# STEP 2: Organize data.
96# **********************************************************
97
98print( "STEP 2: Organize data." )
99
100# Create lists c() and organize data into their corresponding list.
101print( "Sorting data." )
102avgs <- c( fileData[ 'avg' ] )
103
104# Parse lists into data frames.
105dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame
106dataFrame$scale <- fileData$scale # Add node scaling to the data frame.
107
108colnames( dataFrame ) <- c( "throughput", "type", "scale" )
109
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700110dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
111
112print( "Data Frame Results:" )
113print( dataFrame )
114
115
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000116# **********************************************************
117# STEP 3: Generate graphs.
118# **********************************************************
119
120print( "STEP 3: Generate graphs." )
121
122# 1. Graph fundamental data is generated first.
123# These are variables that apply to all of the graphs being generated, regardless of type.
124#
125# 2. Type specific graph data is generated.
126# Data specific for the error bar and stacked bar graphs are generated.
127#
128# 3. Generate and save the graphs.
129# Graphs are saved to the filename above, in the directory provided in command line args
130
131print( "Generating fundamental graph data." )
132
133# Create the primary plot here.
134# ggplot contains the following arguments:
135# - data: the data frame that the graph will be based off of
136# - aes: the asthetics of the graph which require:
137# - x: x-axis values (usually node scaling)
138# - y: y-axis values (usually time in milliseconds)
139# - fill: the category of the colored side-by-side bars (usually type)
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700140theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
141
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000142mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = throughput, fill = type ) )
143
144# Formatting the plot
145width <- 0.7 # Width of the bars.
146xScaleConfig <- scale_x_continuous( breaks = dataFrame$scale, label = dataFrame$scale )
147xLabel <- xlab( "Scale" )
148yLabel <- ylab( "Throughput (events/second)" )
149fillLabel <- labs( fill="Type" )
150chartTitle <- "Intent Event Throughput"
151if ( args[ 1 ] == 'y' ){
152 chartTitle <- paste( chartTitle, " With Flow Objectives", sep="" )
153}
154chartTitle <- paste( chartTitle, "\nevents/second with Neighbors =", sep="" )
155if ( args[ 8 ] == 'y' ){
156 chartTitle <- paste( chartTitle, "all" )
157} else {
158 chartTitle <- paste( chartTitle, "0" )
159}
160
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700161theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000162
163# Store plot configurations as 1 variable
164fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
165
166
167# Create the stacked bar graph with error bars.
168# geom_bar contains:
169# - stat: data formatting (usually "identity")
170# - width: the width of the bar types (declared above)
171# geom_errorbar contains similar arguments as geom_bar.
172print( "Generating bar graph." )
173barGraphFormat <- geom_bar( stat = "identity", width = width, fill="#169EFF" )
174title <- ggtitle( paste( chartTitle, "" ) )
175result <- fundamentalGraphData + barGraphFormat + title
176
177# Save graph to file
178print( paste( "Saving bar chart to", errBarOutputFile ) )
179ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
180
181print( paste( "Successfully wrote bar chart out to", errBarOutputFile ) )