blob: 55e39782db87d711484b7649506188c4f602def5 [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# Normal usage
42# Check if sufficient args are provided.
43if ( is.na( args[ 7 ] ) ){
44 print( "Usage: Rscript SCPFcbench <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 cbench_bm_tests WHERE branch='", args[ 6 ], sep="" )
58command <- paste( command, "' ORDER BY date DESC LIMIT 3", sep="" )
59
60print( paste( "Sending SQL command:", command ) )
61
62fileData <- dbGetQuery( con, command )
63
64chartTitle <- paste( "Single-Node CBench Throughput", "Last 3 Builds", sep = "\n" )
65
66# **********************************************************
67# STEP 2: Organize data.
68# **********************************************************
69
70fileDataNames <- names( fileData )
71
72avgs <- c()
73stds <- c()
74
75print( "Sorting data." )
76avgs <- c( fileData[ 'avg' ] )
77
78dataFrame <- melt( avgs )
79dataFrame$std <- c( fileData$std )
80dataFrame$date <- c( fileData$date )
81dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
82
83colnames( dataFrame ) <- c( "ms", "type", "std", "date", "iterative" )
84
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070085dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
86
87print( "Data Frame Results:" )
88print( dataFrame )
89
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000090# **********************************************************
91# STEP 3: Generate graphs.
92# **********************************************************
93
94print( "Generating fundamental graph data." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070095
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -070096theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070097
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -070098mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = ms, ymin = ms, ymax = ms + std ) )
99xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$date )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700100xLabel <- xlab( "Build Date" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000101yLabel <- ylab( "Responses / sec" )
102fillLabel <- labs( fill="Type" )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700103theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ), legend.position="bottom", legend.text=element_text( size=18, face="bold" ), legend.title = element_blank() )
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.3
110barGraphFormat <- geom_bar( stat="identity", position = position_dodge(), width = width, fill="#00AA13" )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700111errorBarFormat <- geom_errorbar( width = width, color=rgb( 140,140,140, maxColorValue=255 ) )
112values <- geom_text( aes( x=dataFrame$iterative, y=fileData[ 'avg' ] + 0.025 * max( fileData[ 'avg' ] ), label = format( fileData[ 'avg' ], digits=3, big.mark = ",", scientific = FALSE ) ), size = 7.0, fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000113title <- ggtitle( chartTitle )
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 ) )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700118ggsave( errBarOutputFile, width = 15, height = 10, dpi = 200 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000119print( paste( "Successfully wrote bar chart with error bars out to", errBarOutputFile ) )