Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 1 | # 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 | # Example script: |
| 21 | # Cbench Graph (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFcbench_master_errGraph.jpg): |
| 22 | # Rscript SCPFspecificGraphRScripts/SCPFcbench.R <url> <port> <username> <pass> SCPFcbench master /path/to/save/directory/ |
| 23 | |
| 24 | # ********************************************************** |
| 25 | # STEP 1: Data management. |
| 26 | # ********************************************************** |
| 27 | |
| 28 | print( "**********************************************************" ) |
| 29 | print( "STEP 1: Data management." ) |
| 30 | print( "**********************************************************" ) |
| 31 | |
| 32 | save_directory <- 7 |
| 33 | |
| 34 | # Command line arguments are read. |
| 35 | print( "Reading commmand-line args." ) |
| 36 | args <- commandArgs( trailingOnly=TRUE ) |
| 37 | |
| 38 | # ---------------- |
| 39 | # Import Libraries |
| 40 | # ---------------- |
| 41 | |
| 42 | print( "Importing libraries." ) |
| 43 | library( ggplot2 ) |
| 44 | library( reshape2 ) |
| 45 | library( RPostgreSQL ) # For databases |
Devin Lim | 324806b | 2018-05-11 15:36:52 -0700 | [diff] [blame] | 46 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" ) |
| 47 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" ) |
| 48 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" ) |
| 49 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 50 | |
| 51 | # ------------------- |
| 52 | # Check CLI Arguments |
| 53 | # ------------------- |
| 54 | |
| 55 | print( "Verifying CLI args." ) |
| 56 | |
| 57 | if ( length( args ) != save_directory ){ |
| 58 | usage( "SCPFcbench.R" ) |
| 59 | quit( status = 1 ) |
| 60 | } |
| 61 | |
| 62 | # ----------------- |
| 63 | # Create File Names |
| 64 | # ----------------- |
| 65 | |
| 66 | print( "Creating filenames and title of graph." ) |
| 67 | |
| 68 | errBarOutputFile <- paste( args[ save_directory ], |
| 69 | args[ graph_title ], |
| 70 | "_", |
| 71 | args[ branch_name ], |
| 72 | "_errGraph.jpg", |
| 73 | sep="" ) |
| 74 | |
| 75 | chartTitle <- paste( "Single-Node CBench Throughput", "Last 3 Builds", sep = "\n" ) |
| 76 | |
| 77 | # ------------------ |
| 78 | # SQL Initialization |
| 79 | # ------------------ |
| 80 | |
| 81 | print( "Initializing SQL" ) |
| 82 | |
| 83 | con <- initSQL( args[ database_host ], |
| 84 | args[ database_port ], |
| 85 | args[ database_u_id ], |
| 86 | args[ database_pw ] ) |
| 87 | |
| 88 | # ------------------ |
| 89 | # Cbench SQL Command |
| 90 | # ------------------ |
| 91 | |
| 92 | print( "Generating Scale Topology SQL Command" ) |
| 93 | |
| 94 | command <- paste( "SELECT * FROM cbench_bm_tests WHERE branch='", |
| 95 | args[ branch_name ], |
| 96 | "' ORDER BY date DESC LIMIT 3", |
| 97 | sep="" ) |
| 98 | |
| 99 | fileData <- retrieveData( con, command ) |
| 100 | |
| 101 | # ********************************************************** |
| 102 | # STEP 2: Organize data. |
| 103 | # ********************************************************** |
| 104 | |
| 105 | print( "**********************************************************" ) |
| 106 | print( "STEP 2: Organize Data." ) |
| 107 | print( "**********************************************************" ) |
| 108 | |
| 109 | # ------------ |
| 110 | # Data Sorting |
| 111 | # ------------ |
| 112 | |
| 113 | print( "Sorting data." ) |
| 114 | |
| 115 | requiredColumns <- c( "avg" ) |
| 116 | |
| 117 | tryCatch( avgs <- c( fileData[ requiredColumns] ), |
| 118 | error = function( e ) { |
| 119 | print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." ) |
| 120 | print( "Required columns: " ) |
| 121 | print( requiredColumns ) |
| 122 | print( "Actual columns: " ) |
| 123 | print( names( fileData ) ) |
| 124 | print( "Error dump:" ) |
| 125 | print( e ) |
| 126 | quit( status = 1 ) |
| 127 | } |
| 128 | ) |
| 129 | |
| 130 | |
| 131 | # -------------------- |
| 132 | # Construct Data Frame |
| 133 | # -------------------- |
| 134 | |
| 135 | print( "Constructing Data Frame" ) |
| 136 | |
| 137 | dataFrame <- melt( avgs ) |
| 138 | dataFrame$std <- c( fileData$std ) |
| 139 | dataFrame$date <- c( fileData$date ) |
| 140 | dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) ) |
| 141 | |
| 142 | colnames( dataFrame ) <- c( "ms", |
| 143 | "type", |
| 144 | "std", |
| 145 | "date", |
| 146 | "iterative" ) |
| 147 | |
| 148 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 149 | |
| 150 | print( "Data Frame Results:" ) |
| 151 | print( dataFrame ) |
| 152 | |
| 153 | # ********************************************************** |
| 154 | # STEP 3: Generate graphs. |
| 155 | # ********************************************************** |
| 156 | |
| 157 | print( "**********************************************************" ) |
| 158 | print( "STEP 3: Generate Graph." ) |
| 159 | print( "**********************************************************" ) |
| 160 | |
| 161 | # ------------------ |
| 162 | # Generate Main Plot |
| 163 | # ------------------ |
| 164 | |
| 165 | print( "Creating main plot." ) |
| 166 | |
| 167 | mainPlot <- ggplot( data = dataFrame, aes( x = iterative, |
| 168 | y = ms, |
| 169 | ymin = ms, |
| 170 | ymax = ms + std ) ) |
| 171 | |
| 172 | # ------------------------------ |
| 173 | # Fundamental Variables Assigned |
| 174 | # ------------------------------ |
| 175 | |
| 176 | print( "Generating fundamental graph data." ) |
| 177 | |
| 178 | defaultTextSize() |
| 179 | |
| 180 | barWidth <- 0.3 |
| 181 | |
| 182 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, |
| 183 | label = dataFrame$date ) |
| 184 | xLabel <- xlab( "Build Date" ) |
| 185 | yLabel <- ylab( "Responses / sec" ) |
| 186 | fillLabel <- labs( fill = "Type" ) |
| 187 | |
| 188 | theme <- graphTheme() |
| 189 | |
| 190 | title <- labs( title = chartTitle, subtitle = lastUpdatedLabel() ) |
| 191 | |
| 192 | fundamentalGraphData <- mainPlot + |
| 193 | xScaleConfig + |
| 194 | xLabel + |
| 195 | yLabel + |
| 196 | fillLabel + |
| 197 | theme + |
| 198 | title |
| 199 | |
| 200 | # --------------------------- |
| 201 | # Generating Bar Graph Format |
| 202 | # --------------------------- |
| 203 | |
| 204 | print( "Generating bar graph with error bars." ) |
| 205 | |
| 206 | barGraphFormat <- geom_bar( stat = "identity", |
| 207 | position = position_dodge(), |
| 208 | width = barWidth, |
| 209 | fill = webColor( "green" ) ) |
| 210 | |
| 211 | errorBarFormat <- geom_errorbar( width = barWidth, |
| 212 | color = webColor( "darkerGray" ) ) |
| 213 | |
| 214 | values <- geom_text( aes( x=dataFrame$iterative, |
| 215 | y=fileData[ 'avg' ] + 0.025 * max( fileData[ 'avg' ] ), |
| 216 | label = format( fileData[ 'avg' ], |
| 217 | digits=3, |
| 218 | big.mark = ",", |
| 219 | scientific = FALSE ) ), |
| 220 | size = 7.0, |
| 221 | fontface = "bold" ) |
| 222 | |
| 223 | result <- fundamentalGraphData + |
| 224 | barGraphFormat + |
| 225 | errorBarFormat + |
| 226 | values |
| 227 | |
| 228 | # ----------------------- |
| 229 | # Exporting Graph to File |
| 230 | # ----------------------- |
| 231 | |
| 232 | saveGraph( errBarOutputFile ) # from saveGraph.R |