blob: dbf18e98cf96f6070f1fd1ab28f8166973764491 [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 SCPFbatchFlowResp <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
52errBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
53errBarOutputFile <- paste( errBarOutputFile, args[ 6 ], sep="_" )
54errBarOutputFile <- paste( errBarOutputFile, "_PostGraph.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 batch_flow_tests WHERE branch='", args[ 6 ], sep="" )
61command <- paste( command, "' ORDER BY date DESC LIMIT 3", sep="" )
62
63print( paste( "Sending SQL command:", command ) )
64
65fileData <- dbGetQuery( con, command )
66
67chartTitle <- paste( "Single Bench Flow Latency - Post", "Last 3 Builds", sep = "\n" )
68
69# **********************************************************
70# STEP 2: Organize data.
71# **********************************************************
72
73avgs <- c()
74
75print( "Sorting data." )
76avgs <- c( fileData[ 'posttoconfrm' ], fileData[ 'elapsepost' ] )
77
78dataFrame <- melt( avgs )
79dataFrame$scale <- fileData$scale
80dataFrame$date <- fileData$date
81dataFrame$iterative <- dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
82
83colnames( dataFrame ) <- c( "ms", "type", "scale", "date", "iterative" )
84
85# Format data frame so that the data is in the same order as it appeared in the file.
86dataFrame$type <- as.character( dataFrame$type )
87dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
88
89# **********************************************************
90# STEP 3: Generate graphs.
91# **********************************************************
92
93print( "Generating fundamental graph data." )
94
95mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = ms, fill = type ) )
96xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$date )
97xLabel <- xlab( "date" )
98yLabel <- ylab( "Latency (ms)" )
99fillLabel <- labs( fill="Type" )
100theme <- theme( plot.title=element_text( hjust = 0.5, size = 18, face='bold' ) )
101
102fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
103
104
105print( "Generating bar graph with error bars." )
106width <- 0.3
107barGraphFormat <- geom_bar( stat="identity", width = width )
108title <- ggtitle( chartTitle )
109result <- fundamentalGraphData + barGraphFormat + title
110
111
112print( paste( "Saving bar chart to", errBarOutputFile ) )
113ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
114
115print( paste( "Successfully wrote stacked bar chart out to", errBarOutputFile ) )
116
117
118# **********************************************************
119# STEP 2: Organize data.
120# **********************************************************
121
122avgs <- c()
123
124print( "Sorting data." )
125avgs <- c( fileData[ 'deltoconfrm' ], fileData[ 'elapsedel' ] )
126
127dataFrame <- melt( avgs )
128dataFrame$scale <- fileData$scale
129dataFrame$date <- fileData$date
130dataFrame$iterative <- dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
131
132colnames( dataFrame ) <- c( "ms", "type", "scale", "date", "iterative" )
133
134# Format data frame so that the data is in the same order as it appeared in the file.
135dataFrame$type <- as.character( dataFrame$type )
136dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
137
138
139# **********************************************************
140# STEP 3: Generate graphs.
141# **********************************************************
142
143print( "Generating fundamental graph data." )
144
145mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = ms, fill = type ) )
146xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$date )
147xLabel <- xlab( "Build Date" )
148yLabel <- ylab( "Latency (ms)" )
149fillLabel <- labs( fill="Type" )
150theme <- theme( plot.title=element_text( hjust = 0.5, size = 18, face='bold' ) )
151
152fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
153
154
155print( "Generating bar graph with error bars." )
156width <- 0.3
157barGraphFormat <- geom_bar( stat="identity", width = width )
158chartTitle <- paste( "Single Bench Flow Latency - Del", "Last 3 Builds", sep = "\n" )
159title <- ggtitle( chartTitle )
160result <- fundamentalGraphData + barGraphFormat + title
161
162errBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
163errBarOutputFile <- paste( errBarOutputFile, args[ 6 ], sep="_" )
164errBarOutputFile <- paste( errBarOutputFile, "_DelGraph.jpg", sep="" )
165
166print( paste( "Saving bar chart to", errBarOutputFile ) )
167ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
168
169print( paste( "Successfully wrote stacked bar chart out to", errBarOutputFile ) )