blob: 738765af848280876deb804af2c363dee8b18761 [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
42# Check if sufficient args are provided.
43if ( is.na( args[ 7 ] ) ){
44 print( "Usage: Rscript SCPFhostLat <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <directory-to-save-graphs>" )
45 q() # basically exit(), but in R
46}
47
Jeremy Ronquillob6268842017-10-03 13:02:58 -070048# paste() is used to concatenate strings
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000049errBarOutputFile <- paste( args[ 7 ], args[ 5 ], sep="" )
50errBarOutputFile <- paste( errBarOutputFile, args[ 6 ], sep="_" )
51errBarOutputFile <- paste( errBarOutputFile, "_errGraph.jpg", sep="" )
52
53print( "Reading from databases." )
54
55con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] )
56
57command <- paste( "SELECT * FROM host_latency_tests WHERE branch = '", args[ 6 ], sep = "" )
58command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM host_latency_tests WHERE branch = '", sep = "" )
59command <- paste( command, args[ 6 ], sep = "" )
60command <- paste( command, "' ) ", sep="" )
61
62print( paste( "Sending SQL command:", command ) )
63
64fileData <- dbGetQuery( con, command )
65
66chartTitle <- "Host Latency"
67
68
69# **********************************************************
70# STEP 2: Organize data.
71# **********************************************************
72
73print( "STEP 2: Organize data." )
74
75avgs <- c()
76
77print( "Sorting data." )
78avgs <- c( fileData[ 'avg' ] )
79
80dataFrame <- melt( avgs )
81dataFrame$scale <- fileData$scale
82dataFrame$std <- fileData$std
83
84colnames( dataFrame ) <- c( "ms", "type", "scale", "std" )
85
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070086dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
87
88print( "Data Frame Results:" )
89print( dataFrame )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000090
91# **********************************************************
92# STEP 3: Generate graphs.
93# **********************************************************
94
95print( "Generating fundamental graph data." )
96
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070097theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000098mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = ms, ymin = ms - std, ymax = ms + std ) )
99xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
100xLabel <- xlab( "Scale" )
101yLabel <- ylab( "Latency (ms)" )
102fillLabel <- labs( fill="Type" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700103theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000104
105fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
106
107
108print( "Generating bar graph with error bars." )
109width <- 0.9
110barGraphFormat <- geom_bar( stat="identity", position=position_dodge( ), width = width, fill="#E8BD00" )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700111errorBarFormat <- geom_errorbar( position=position_dodge(), width = width, color=rgb( 140, 140, 140, maxColorValue=255 ) )
112values <- geom_text( aes( x=dataFrame$scale, y=dataFrame$ms + 0.08 * max( dataFrame$ms ), label = format( dataFrame$ms, digits=3, big.mark = ",", scientific = FALSE ) ), size = 5, fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000113title <- ggtitle( paste( chartTitle, "with Standard Error Bars" ) )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700114result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title + values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000115
116
117print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
118ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
119
120print( paste( "Successfully wrote bar chart out to", errBarOutputFile ) )