blob: 999504e7146f28478431dbd58a2b6a62d6dc6524 [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[ 7 ] ) ){
46 print( "Usage: Rscript SCPFcbench <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 cbench_bm_tests WHERE branch='", args[ 6 ], sep="" )
62command <- paste( command, "' ORDER BY date DESC LIMIT 3", sep="" )
63
64print( paste( "Sending SQL command:", command ) )
65
66fileData <- dbGetQuery( con, command )
67
68chartTitle <- paste( "Single-Node CBench Throughput", "Last 3 Builds", sep = "\n" )
69
70# **********************************************************
71# STEP 2: Organize data.
72# **********************************************************
73
74fileDataNames <- names( fileData )
75
76avgs <- c()
77stds <- c()
78
79print( "Sorting data." )
80avgs <- c( fileData[ 'avg' ] )
81
82dataFrame <- melt( avgs )
83dataFrame$std <- c( fileData$std )
84dataFrame$date <- c( fileData$date )
85dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
86
87colnames( dataFrame ) <- c( "ms", "type", "std", "date", "iterative" )
88
89# **********************************************************
90# STEP 3: Generate graphs.
91# **********************************************************
92
93print( "Generating fundamental graph data." )
94mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = ms, ymin = ms - std, ymax = ms + std ) )
95xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$date )
96xLabel <- xlab( "date" )
97yLabel <- ylab( "Responses / sec" )
98fillLabel <- labs( fill="Type" )
99theme <- theme( plot.title=element_text( hjust = 0.5, size = 18, face='bold' ) )
100
101fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
102
103
104print( "Generating bar graph with error bars." )
105width <- 0.3
106barGraphFormat <- geom_bar( stat="identity", position = position_dodge(), width = width, fill="#00AA13" )
107errorBarFormat <- geom_errorbar( position=position_dodge( ), width = width )
108title <- ggtitle( chartTitle )
109result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
110
111
112print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
113ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
114print( paste( "Successfully wrote bar chart with error bars out to", errBarOutputFile ) )