blob: 75e2a45d5b077c55354b6d547b0fb19401045f1b [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
44# Check if sufficient args are provided.
45if ( is.na( args[ 7 ] ) ){
46 print( "Usage: Rscript SCPFhostLat <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
57print( "Reading from databases." )
58
59con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] )
60
61command <- paste( "SELECT * FROM host_latency_tests WHERE branch = '", args[ 6 ], sep = "" )
62command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM host_latency_tests WHERE branch = '", sep = "" )
63command <- paste( command, args[ 6 ], sep = "" )
64command <- paste( command, "' ) ", sep="" )
65
66print( paste( "Sending SQL command:", command ) )
67
68fileData <- dbGetQuery( con, command )
69
70chartTitle <- "Host Latency"
71
72
73# **********************************************************
74# STEP 2: Organize data.
75# **********************************************************
76
77print( "STEP 2: Organize data." )
78
79avgs <- c()
80
81print( "Sorting data." )
82avgs <- c( fileData[ 'avg' ] )
83
84dataFrame <- melt( avgs )
85dataFrame$scale <- fileData$scale
86dataFrame$std <- fileData$std
87
88colnames( dataFrame ) <- c( "ms", "type", "scale", "std" )
89
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070090dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
91
92print( "Data Frame Results:" )
93print( dataFrame )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000094
95# **********************************************************
96# STEP 3: Generate graphs.
97# **********************************************************
98
99print( "Generating fundamental graph data." )
100
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700101theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000102mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = ms, ymin = ms - std, ymax = ms + std ) )
103xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
104xLabel <- xlab( "Scale" )
105yLabel <- ylab( "Latency (ms)" )
106fillLabel <- labs( fill="Type" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700107theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000108
109fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
110
111
112print( "Generating bar graph with error bars." )
113width <- 0.9
114barGraphFormat <- geom_bar( stat="identity", position=position_dodge( ), width = width, fill="#E8BD00" )
115errorBarFormat <- geom_errorbar( position=position_dodge( ), width = width )
116title <- ggtitle( paste( chartTitle, "with Standard Error Bars" ) )
117result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
118
119
120print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
121ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
122
123print( paste( "Successfully wrote bar chart out to", errBarOutputFile ) )