2 #############################################################################################################################
3 ################################################ F U N C T I O N S ##########################################################
4 #############################################################################################################################
6 create_data="create_performance_data.txt"
7 read_data="read_performance_data.txt"
8 update_data="update_performance_data.txt"
9 delete_data="delete_performance_data.txt"
12 create_data_title_1="Creating openroadm anchors with large data"
13 read_data_title_1="Read datatrees using openroadm root"
14 update_data_title_1="Update 100 data nodes"
15 delete_data_title_1="Batch delete 100 whole lists"
17 # Text patterns to match in console log
18 creating_bookstore_pattern="^.*Creating openroadm anchors with large.*"
19 read_datatreees_pattern="^.*Read datatrees using openroadm root.*"
20 update_datanodes_pattern="^.*Update 100 data nodes.*"
21 batch_delete_pattern="^.*Batch delete 100 whole lists.*"
23 all_patterns=("$creating_bookstore_pattern" "$read_datatreees_pattern" "$update_datanodes_pattern" "$batch_delete_pattern")
28 latestBuild=$(curl -s "${JENKINS_JOB_URL}/lastBuild/api/json" | jq -r '.number')
29 echo "latest build is $latestBuild"
32 latestBuild=$(getLatestBuild)
35 dateOfLastRecordedBuild=""
36 JENKINS_JOB_URL="https://jenkins.nordix.org/job/onap-cps-master-performance-test-java"
38 # Create and add header to the file
39 createAndAddHeader() {
42 if [[ ! -f "$file" ]]; then
45 echo "Build,$header" > $file
47 echo "$file already exists"
53 consoleURL="${JENKINS_JOB_URL}/${buildToRead}/consoleText"
54 consoleText=$(curl -s "$consoleURL")
57 getAndRecordDataResults() {
67 # Get and calculate data for plot
68 if matched_line=$(echo "$consoleText" | grep -o -P "$patternToMatch"); then
69 echo "Matched line: $matched_line"
70 limit_value=$(echo "$matched_line" | grep -o -P 'limit\s*\K\d+(,\d+)?' | tr -cd '[:digit:]')
72 took_value=$(echo "$matched_line" | grep -o -P 'took\s*\K\d+(,\d+)?' | tr -cd '[:digit:]')
74 percentage=$(($took_value * 100 / $limit_value))
76 echo "Limit value: $limit_value"
77 echo "Took value: $took_value"
78 echo "Percentage: $percentage"
80 if [ -z "$new_data" ]; then
81 new_data="$percentage"
83 new_data+=",$percentage"
85 echo "New data: $new_data"
88 echo "No match found."
92 lastLine=$(tail -n 1 "$dataFile")
93 newLine="$buildNumber,$new_data"
94 if [ -z "$new_data" ]; then
96 elif [ $newLine == $lastLine ]; then
97 echo "Data already exists"
99 echo "$buildNumber,$new_data" >> $dataFile
100 echo "New data added"
102 lastRecordedBuild=$buildNumber
103 dateOfLastRecordedBuild=$(curl -s "${JENKINS_JOB_URL}/${lastRecordedBuild}/api/json" | jq -r '.timestamp' | xargs -I {} date -d "@{}")
104 echo "last Recorded build: $lastRecordedBuild"
105 echo "date of last recorded build: $dateOfLastRecordedBuild"
108 buildStaticReport() {
109 dataFile="$1" # Get the input file name from the function parameter
113 sudo apt-get install -y gnuplot
115 # Create a temporary Gnuplot script
116 cat <<EOT > gnuplot_script.gp
117 set datafile separator ","
118 set terminal pngcairo size 1500,600
119 set output "${chartTitle}.png"
125 set ylabel "Percentage of limit %"
127 # Get stats for min and max
128 stats '$dataFile' using 1
131 xLabel(x) = (int((x - xmin) / freq) % 2 == 0) ? sprintf("%d", x) : ""
133 plot '$dataFile' using (column(0)+1):2:xtic(xLabel(column(1))) with linespoints title "limit"
136 # Run the Gnuplot script
137 gnuplot gnuplot_script.gp
139 # Remove the temporary script
146 chartFileName1="$2" # Get the chart file name as the first parameter
157 reportTitle="$9" # Get the report title as the second parameter
159 cat <<EOT > "index.html"
163 <title>$reportTitle</title>
166 <h1 style="text-align: center;">$reportTitle</h1>
167 <h4>Last recorded build number: $lastRecordedBuild</h4>
168 <h4>Date of the last recoded build: $dateOfLastRecordedBuild</h4>
169 <table align="center">
170 <tr> <!-- First Row -->
172 <figcaption>"$chartTitle1"</figcaption>
173 <img src="$chartFileName1" alt="Image 1" width="750" height="300">
175 <td align="center" style="padding: 10px;">
176 <figcaption>"$chartTitle2"</figcaption>
177 <img src="$chartFileName2" alt="Image 2" width="750" height="300">
180 <tr> <!-- Second Row -->
181 <td align="center" style="padding: 10px;">
182 <figcaption>"$chartTitle3"</figcaption>
183 <img src="$chartFileName3" alt="Image 3" width="750" height="300">
185 <td align="center" style="padding: 10px;">
186 <figcaption>"$chartTitle4"</figcaption>
187 <img src="$chartFileName4" alt="Image 4" width="750" height="300">
200 cat <<EOT > "$outputFile"
204 <title>$reportTitle</title>
207 <h1>$reportTitle</h1>
208 <h4>Last recorded build number: $lastRecordedBuild</h4>
209 <h4>Date of the last recoded build: $dateOfLastRecordedBuild</h4>
210 <img src="$chartFileName" alt="Graph Image">
216 buildPlotForCreateOperation() {
218 createAndAddHeader "$create_data" "$create_data_title_1"
219 getAndRecordDataResults "$consoleText" "$creating_bookstore_pattern" "$create_data" "$buildNumber"
222 buildPlotForReadOperation() {
224 createAndAddHeader "$read_data" "$read_data_title_1"
225 getAndRecordDataResults "$consoleText" "$read_datatreees_pattern" "$read_data" "$buildNumber"
228 buildPlotForUpdateOperation() {
230 createAndAddHeader "$update_data" "$update_data_title_1"
231 getAndRecordDataResults "$consoleText" "$update_datanodes_pattern" "$update_data" "$buildNumber"
234 buildPlotForBatchOperation() {
236 createAndAddHeader "$delete_data" "$delete_data_title_1"
237 getAndRecordDataResults "$consoleText" "$batch_delete_pattern" "$delete_data" "$buildNumber"
240 #############################################################################################################################
241 #############################################################################################################################
242 #############################################################################################################################
243 #############################################################################################################################
248 if [ -z "$(ls -A)" ]; then
249 # Calculate the starting value for the loop
250 startValue=$((latestBuild - 70))
252 # Start the loop from startValue up to latestBuild
253 for ((i=startValue; i<=latestBuild; i++)); do
255 buildPlotForCreateOperation "$i"
256 buildPlotForReadOperation "$i"
257 buildPlotForUpdateOperation "$i"
258 buildPlotForBatchOperation "$i"
260 buildStaticReport "$create_data" "createLargeData"
261 buildStaticReport "$read_data" "readDataTrees"
262 buildStaticReport "$update_data" "updateDatanodes"
263 buildStaticReport "$delete_data" "batchDelete"
265 getConsoleText $latestBuild
266 buildPlotForCreateOperation $latestBuild
267 buildPlotForReadOperation $latestBuild
268 buildPlotForUpdateOperation $latestBuild
269 buildPlotForBatchOperation $latestBuild
271 buildStaticReport "$create_data" "createLargeData"
272 buildStaticReport "$read_data" "readDataTrees"
273 buildStaticReport "$update_data" "updateDatanodes"
274 buildStaticReport "$delete_data" "batchDelete"
278 touch index.html createOperation.html readOperation.html updateOperation.html deleteOperation.html
281 "Creating openroadm anchors with large data" \
282 "createLargeData.png" \
283 "Read datatrees using openroadm root" \
284 "readDataTrees.png" \
285 "Update 100 data nodes" \
286 "updateDatanodes.png" \
287 "Batch delete 100 whole lists" \
291 buildPageReport "createLargeData.png" "Creating openroadm anchors with large data" "createOperation.html"
292 buildPageReport "readDataTrees.png" "Read datatrees using openroadm root" "readOperation.html"
293 buildPageReport "updateDatanodes.png" "Update 100 data nodes" "updateOperation.html"
294 buildPageReport "batchDelete.png" "Batch delete 100 whole lists" "deleteOperation.html"
297 buildPlotForCreateOperation() {
299 createAndAddHeader "$create_data" "$create_data_title_1"
300 getAndRecordDataResults "$consoleText" "$creating_bookstore_pattern" "$create_data" "$buildNumber"
303 buildPlotForReadOperation() {
305 createAndAddHeader "$read_data" "$read_data_title_1"
306 getAndRecordDataResults "$consoleText" "$read_datatreees_pattern" "$read_data" "$buildNumber"
309 buildPlotForUpdateOperation() {
311 createAndAddHeader "$update_data" "$update_data_title_1"
312 getAndRecordDataResults "$consoleText" "$update_datanodes_pattern" "$update_data" "$buildNumber"
315 buildPlotForBatchOperation() {
317 createAndAddHeader "$delete_data" "$delete_data_title_1"
318 getAndRecordDataResults "$consoleText" "$batch_delete_pattern" "$delete_data" "$buildNumber"
321 #############################################################################################################################
322 #############################################################################################################################
323 #############################################################################################################################
324 #############################################################################################################################
329 if [ -z "$(ls -A)" ]; then
330 # Calculate the starting value for the loop
331 startValue=$((latestBuild - 50))
333 # Start the loop from startValue up to latestBuild
334 for ((i=startValue; i<=latestBuild; i++)); do
336 buildPlotForCreateOperation "$i"
337 buildPlotForReadOperation "$i"
338 buildPlotForUpdateOperation "$i"
339 buildPlotForBatchOperation "$i"
341 buildStaticReport "$create_data" "createLargeData"
342 buildStaticReport "$read_data" "readDataTrees"
343 buildStaticReport "$update_data" "updateDatanodes"
344 buildStaticReport "$delete_data" "batchDelete"
346 getConsoleText $latestBuild
347 buildPlotForCreateOperation $latestBuild
348 buildPlotForReadOperation $latestBuild
349 buildPlotForUpdateOperation $latestBuild
350 buildPlotForBatchOperation $latestBuild
352 buildStaticReport "$create_data" "createLargeData"
353 buildStaticReport "$read_data" "readDataTrees"
354 buildStaticReport "$update_data" "updateDatanodes"
355 buildStaticReport "$delete_data" "batchDelete"
359 touch index.html createOperation.html readOperation.html updateOperation.html deleteOperation.html
362 "Creating openroadm anchors with large data" \
363 "createLargeData.png" \
364 "Read datatrees using openroadm root" \
365 "readDataTrees.png" \
366 "Update 100 data nodes" \
367 "updateDatanodes.png" \
368 "Batch delete 100 whole lists" \
372 buildPageReport "createLargeData.png" "Creating openroadm anchors with large data" "createOperation.html"
373 buildPageReport "readDataTrees.png" "Read datatrees using openroadm root" "readOperation.html"
374 buildPageReport "updateDatanodes.png" "Update 100 data nodes" "updateOperation.html"
375 buildPageReport "batchDelete.png" "Batch delete 100 whole lists" "deleteOperation.html"