2 sudo apt-get install bc
3 #############################################################################################################################
4 ################################################ F U N C T I O N S ##########################################################
5 #############################################################################################################################
7 create_data="create_performance_data.txt"
8 read_data="read_performance_data.txt"
9 update_data="update_performance_data.txt"
10 delete_data="delete_performance_data.txt"
13 create_data_title_1="Creating openroadm anchors with large data"
14 read_data_title_1="Read datatrees using openroadm root"
15 update_data_title_1="Update 100 data nodes"
16 delete_data_title_1="Batch delete 100 whole lists"
18 # Text patterns to match in console log
19 creating_bookstore_pattern="^.*Creating openroadm anchors with large.*"
20 read_datatreees_pattern="^.*Read datatrees using openroadm root.*"
21 update_datanodes_pattern="^.*Update 100 data nodes.*"
22 batch_delete_pattern="^.*Batch delete 100 whole lists.*"
25 JENKINS_JOB_URL="https://jenkins.nordix.org/job/onap-cps-master-performance-test-java"
29 latestBuild=$(curl -s "${JENKINS_JOB_URL}/lastBuild/api/json" | jq -r '.number')
30 echo "latest build is $latestBuild"
33 latestBuild=$(getLatestBuild)
34 latestBuildToRecord=""
37 latestRecordedBuild=""
38 timestampOfLatestRecordedBuild=""
40 # Create and add header to the file
41 createAndAddHeader() {
44 if [[ ! -f "$file" ]]; then
47 echo "Build,$header" > $file
49 echo "$file already exists"
53 # Get the console text from specific build of the performance job
56 consoleURL="${JENKINS_JOB_URL}/${buildToRead}/consoleText"
57 consoleText=$(curl -s "$consoleURL")
60 getAndRecordDataResults() {
70 # Get and calculate data for plot
71 if matched_line=$(echo "$consoleText" | grep -o -P "$patternToMatch"); then
72 echo "Matched line: $matched_line"
73 limit_value=$(echo "$matched_line" | grep -o -P 'limit\s*\K\d+(\.\d+)?' | tr -cd '[:digit:].')
75 took_value=$(echo "$matched_line" | grep -o -P 'took\s*\K\d+(\.\d+)?' | tr -cd '[:digit:].')
77 percentage=$(echo "scale=2; $took_value * 100.00 / $limit_value" | bc)
80 echo "Limit value: $limit_value"
81 echo "Took value: $took_value"
82 echo "Percentage: $percentage"
84 if [ -z "$new_data" ]; then
85 new_data="$percentage"
87 new_data+=",$percentage"
89 echo "New data: $new_data"
92 echo "No match found."
96 lastLine=$(tail -n 1 "$dataFile")
97 newLine="$buildNumber,$new_data"
98 if [ -z "$new_data" ]; then
100 lastRecordedBuild=$(echo "$lastLine" | awk -F, '{print $1}')
101 recordLatestRecordedBuild "$lastRecordedBuild"
102 elif [ $newLine == $lastLine ]; then
103 echo "Data already exists"
104 recordLatestRecordedBuild "$buildNumber"
106 echo "$buildNumber,$new_data" >> $dataFile
107 echo "New data added"
108 recordLatestRecordedBuild "$buildNumber"
112 recordLatestRecordedBuild() {
113 latestBuildToRecord="$1"
114 timestampOfLatestRecordedBuild=$(curl -s "${JENKINS_JOB_URL}/${latestBuildToRecord}/api/json" | jq -r '.timestamp')
115 formattedTimestampOfLatestRecordedBuild=$(date -d "@$((timestampOfLatestRecordedBuild / 1000))" "+%B %e, %Y at %H:%M")
116 echo "Latest recorded build: $latestBuildToRecord"
117 echo "Date of latest recorded build: $formattedTimestampOfLatestRecordedBuild"
118 latestRecordedBuild=$latestBuildToRecord
121 buildStaticReport() {
122 dataFile="$1" # Get the input file name from the function parameter
126 sudo apt-get install -y gnuplot
128 # Create a temporary Gnuplot script
129 cat <<EOT > gnuplot_script.gp
130 set datafile separator ","
131 set terminal pngcairo size 1500,600
132 set output "${chartTitle}.png"
138 set ylabel "Percentage of limit %"
140 # Get stats for min and max
141 stats '$dataFile' using 1
144 xLabel(x) = (int((x - xmin) / freq) % 2 == 0) ? sprintf("%d", x) : ""
146 plot '$dataFile' using (column(0)+1):2:xtic(xLabel(column(1))) with linespoints title "limit"
149 # Run the Gnuplot script
150 gnuplot gnuplot_script.gp
152 # Remove the temporary script
158 chartTitle1="$1" # i.e Get the chart file name as the first parameter
170 reportTitle="$9" # i.e Get the report title as the ninth parameter
172 cat <<EOT > "index.html"
176 <title>$reportTitle</title>
179 <h1 style="text-align: center;">$reportTitle</h1>
180 <h4>Last updated for performance job build no. $latestRecordedBuild on $formattedTimestampOfLatestRecordedBuild</h4>
181 <p>The performance tests job runs daily at 02:15 UTC, providing performance metrics. The following graphs update at 04:15 UTC.</p>
182 <p>Successful performance tests job build adds new data, but even if a build fails, existing data is retained.</p>
183 <p>Updates occur whenever new successful data is available.</p>
185 <table align="center">
186 <tr> <!-- First Row -->
188 <figcaption>"$chartTitle1"</figcaption>
189 <img src="$chartFileName1" alt="Image 1" width="750" height="300">
191 <td align="center" style="padding: 10px;">
192 <figcaption>"$chartTitle2"</figcaption>
193 <img src="$chartFileName2" alt="Image 2" width="750" height="300">
196 <tr> <!-- Second Row -->
197 <td align="center" style="padding: 10px;">
198 <figcaption>"$chartTitle3"</figcaption>
199 <img src="$chartFileName3" alt="Image 3" width="750" height="300">
201 <td align="center" style="padding: 10px;">
202 <figcaption>"$chartTitle4"</figcaption>
203 <img src="$chartFileName4" alt="Image 4" width="750" height="300">
216 cat <<EOT > "$outputFile"
220 <title>$reportTitle</title>
223 <h1>$reportTitle</h1>
224 <h4>Last updated for performance job build no. $latestRecordedBuild on $formattedTimestampOfLatestRecordedBuild</h4>
225 <img src="$chartFileName" alt="Graph Image">
231 buildPlotForCreateOperation() {
233 createAndAddHeader "$create_data" "$create_data_title_1"
234 getAndRecordDataResults "$consoleText" "$creating_bookstore_pattern" "$create_data" "$buildNumber"
237 buildPlotForReadOperation() {
239 createAndAddHeader "$read_data" "$read_data_title_1"
240 getAndRecordDataResults "$consoleText" "$read_datatreees_pattern" "$read_data" "$buildNumber"
243 buildPlotForUpdateOperation() {
245 createAndAddHeader "$update_data" "$update_data_title_1"
246 getAndRecordDataResults "$consoleText" "$update_datanodes_pattern" "$update_data" "$buildNumber"
249 buildPlotForBatchOperation() {
251 createAndAddHeader "$delete_data" "$delete_data_title_1"
252 getAndRecordDataResults "$consoleText" "$batch_delete_pattern" "$delete_data" "$buildNumber"
255 #############################################################################################################################
256 #############################################################################################################################
257 #############################################################################################################################
258 #############################################################################################################################
263 if [ -z "$(ls -A)" ]; then
264 # Calculate the starting value for the loop
265 startValue=$((latestBuild - 100))
267 # Start the loop from startValue up to latestBuild
268 for ((i=startValue; i<=latestBuild; i++)); do
270 buildPlotForCreateOperation "$i"
271 buildPlotForReadOperation "$i"
272 buildPlotForUpdateOperation "$i"
273 buildPlotForBatchOperation "$i"
275 buildStaticReport "$create_data" "createLargeData"
276 buildStaticReport "$read_data" "readDataTrees"
277 buildStaticReport "$update_data" "updateDatanodes"
278 buildStaticReport "$delete_data" "batchDelete"
280 getConsoleText $latestBuild
281 buildPlotForCreateOperation $latestBuild
282 buildPlotForReadOperation $latestBuild
283 buildPlotForUpdateOperation $latestBuild
284 buildPlotForBatchOperation $latestBuild
286 buildStaticReport "$create_data" "createLargeData"
287 buildStaticReport "$read_data" "readDataTrees"
288 buildStaticReport "$update_data" "updateDatanodes"
289 buildStaticReport "$delete_data" "batchDelete"
293 touch index.html createOperation.html readOperation.html updateOperation.html deleteOperation.html
296 "Creating openroadm anchors with large data" \
297 "createLargeData.png" \
298 "Read datatrees using openroadm root" \
299 "readDataTrees.png" \
300 "Update 100 data nodes" \
301 "updateDatanodes.png" \
302 "Batch delete 100 whole lists" \
306 buildPageReport "createLargeData.png" "Creating openroadm anchors with large data" "createOperation.html"
307 buildPageReport "readDataTrees.png" "Read datatrees using openroadm root" "readOperation.html"
308 buildPageReport "updateDatanodes.png" "Update 100 data nodes" "updateOperation.html"
309 buildPageReport "batchDelete.png" "Batch delete 100 whole lists" "deleteOperation.html"
312 buildPlotForCreateOperation() {
314 createAndAddHeader "$create_data" "$create_data_title_1"
315 getAndRecordDataResults "$consoleText" "$creating_bookstore_pattern" "$create_data" "$buildNumber"
318 buildPlotForReadOperation() {
320 createAndAddHeader "$read_data" "$read_data_title_1"
321 getAndRecordDataResults "$consoleText" "$read_datatreees_pattern" "$read_data" "$buildNumber"
324 buildPlotForUpdateOperation() {
326 createAndAddHeader "$update_data" "$update_data_title_1"
327 getAndRecordDataResults "$consoleText" "$update_datanodes_pattern" "$update_data" "$buildNumber"
330 buildPlotForBatchOperation() {
332 createAndAddHeader "$delete_data" "$delete_data_title_1"
333 getAndRecordDataResults "$consoleText" "$batch_delete_pattern" "$delete_data" "$buildNumber"
336 #############################################################################################################################
337 #############################################################################################################################
338 #############################################################################################################################
339 #############################################################################################################################
344 if [ -z "$(ls -A)" ]; then
345 # Calculate the starting value for the loop
346 startValue=$((latestBuild - 50))
348 # Start the loop from startValue up to latestBuild
349 for ((i=startValue; i<=latestBuild; i++)); do
351 buildPlotForCreateOperation "$i"
352 buildPlotForReadOperation "$i"
353 buildPlotForUpdateOperation "$i"
354 buildPlotForBatchOperation "$i"
356 buildStaticReport "$create_data" "createLargeData"
357 buildStaticReport "$read_data" "readDataTrees"
358 buildStaticReport "$update_data" "updateDatanodes"
359 buildStaticReport "$delete_data" "batchDelete"
361 getConsoleText $latestBuild
362 buildPlotForCreateOperation $latestBuild
363 buildPlotForReadOperation $latestBuild
364 buildPlotForUpdateOperation $latestBuild
365 buildPlotForBatchOperation $latestBuild
367 buildStaticReport "$create_data" "createLargeData"
368 buildStaticReport "$read_data" "readDataTrees"
369 buildStaticReport "$update_data" "updateDatanodes"
370 buildStaticReport "$delete_data" "batchDelete"
374 touch index.html createOperation.html readOperation.html updateOperation.html deleteOperation.html
377 "Creating openroadm anchors with large data" \
378 "createLargeData.png" \
379 "Read datatrees using openroadm root" \
380 "readDataTrees.png" \
381 "Update 100 data nodes" \
382 "updateDatanodes.png" \
383 "Batch delete 100 whole lists" \
387 buildPageReport "createLargeData.png" "Creating openroadm anchors with large data" "createOperation.html"
388 buildPageReport "readDataTrees.png" "Read datatrees using openroadm root" "readOperation.html"
389 buildPageReport "updateDatanodes.png" "Update 100 data nodes" "updateOperation.html"
390 buildPageReport "batchDelete.png" "Batch delete 100 whole lists" "deleteOperation.html"