File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -473,3 +473,38 @@ function kill_servers () {
473
473
function collect_artifacts_from_subdir () {
474
474
cp * .* log* core* ../ || true
475
475
}
476
+
477
+ # Sort an array
478
+ # Call with sort_array <array_name>
479
+ # Example: remove_array_outliers array
480
+ sort_array () {
481
+ local -n arr=$1
482
+ local length=${# arr[@]}
483
+
484
+ if [ " $length " -le 1 ]; then
485
+ return
486
+ fi
487
+
488
+ IFS=$' \n ' sorted_arr=($( sort -n <<< " ${arr[*]}" ) )
489
+ unset IFS
490
+ arr=(" ${sorted_arr[@]} " )
491
+ }
492
+
493
+ # Remove an array's outliers
494
+ # Call with remove_array_outliers <array_name> <percent to trim from both sides>
495
+ # Example: remove_array_outliers array 5
496
+ remove_array_outliers () {
497
+ local -n arr=$1
498
+ local percent=$2
499
+ local length=${# arr[@]}
500
+
501
+ if [ " $length " -le 1 ]; then
502
+ return
503
+ fi
504
+
505
+ local trim_count=$(( length * percent / 100 ))
506
+ local start_index=$trim_count
507
+ local end_index=$(( length - (trim_count* 2 )) )
508
+
509
+ arr=(" ${arr[@]: $start_index : $end_index } " )
510
+ }
You can’t perform that action at this time.
0 commit comments