summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2016-02-03 12:30:07 +0100
committerAndré Nusser <andre.nusser@googlemail.com>2016-02-03 12:30:07 +0100
commit72618685689a652db5a2ac98ce6ba53c43568008 (patch)
tree550437b35753cd565f4c309fb32f1e3fd5692fd1 /tools
parent9310177b736ddf8c6599f685cd38191a95933202 (diff)
Hopefully last fix to correct old top outputs in performance test.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/performance_test/performance_test.sh43
1 files changed, 38 insertions, 5 deletions
diff --git a/tools/performance_test/performance_test.sh b/tools/performance_test/performance_test.sh
index eb6d45d..984d6b4 100755
--- a/tools/performance_test/performance_test.sh
+++ b/tools/performance_test/performance_test.sh
@@ -73,18 +73,51 @@ time_elapsed=0
# log ram and cpu usage of process
function logData
{
+ # returns the (zero-indexed) position of $word in $line.
+ # returns -1 if $word isn't contained in $line.
+ function get_position
+ {
+ word="$1"
+ line=($2)
+
+ count=0
+ for w in "${line[@]}"
+ do
+ if [ "$w" == "$word" ]
+ then
+ echo "$count"
+ return
+ fi
+
+ count=$(($count+1))
+ done
+
+ echo "-1"
+ }
+
pid=$1
- top_output="$(top -b -n 1 -p $pid | grep "^[ ]*$pid")"
- top_arr=($top_output)
+ top_output_labels="$(top -b -n 1 -p $pid | grep "^[ ]*PID")"
+ top_output_values="$(top -b -n 1 -p $pid | grep "^[ ]*$pid")"
+ top_arr=($top_output_values)
+
+ cpu_pos=$(get_position "%CPU" "$top_output_labels")
+ ram_pos=$(get_position "%MEM" "$top_output_labels")
+
+ if [ "$cpu_pos" == "-1" ] || [ "$ram_pos" == "-1" ]
+ then
+ echo "The top output doesn't look like expected."
+ echo "Exiting..."
+ exit
+ fi
- cpu_usage="${top_arr[6]}"
- ram_usage="${top_arr[7]}"
+ cpu_usage="${top_arr[$cpu_pos]}"
+ ram_usage="${top_arr[$ram_pos]}"
cpu_data="${cpu_data}${time_elapsed} ${cpu_usage}\n"
ram_data="${ram_data}${time_elapsed} ${ram_usage}\n"
- avg_cpu_usage_candidate="$(ps -p $pid -o %cpu | grep "^[ ]*[0-9]*\.[0-9]*")"
+ avg_cpu_usage_candidate="$(ps -p $pid -o %cpu | grep "^[ ]*[0-9][0-9]*")"
# to make sure the process was still running when we executed the last command
if [ avg_cpu_usage_candidate != "" ]; then avg_cpu_usage=$avg_cpu_usage_candidate; fi