-
Notifications
You must be signed in to change notification settings - Fork 1
/
capture_process_metrics.sh
47 lines (41 loc) · 1009 Bytes
/
capture_process_metrics.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
set -e -u
sleepSecs=1
outfile=""
swift_date=$(date)
if [[ $# -ge 1 && "$1" == -O ]]; then
outfile=$(date +%Y%m%d-%H%M%S.swiftnav-process-metrics.log)
echo "Saving output to $outfile"
fi
pgrep_cmd="pgrep -f swiftnav_console.main"
swift_pid=$($pgrep_cmd | head -1)
if [[ -z $swift_pid ]]; then
echo "Swift Toolbox not running, waiting 10 seconds for it to start."
for i in {10..0}; do
if [[ $i -eq 0 ]]; then
echo "exiting."
exit 1
fi
swift_pid=$($pgrep_cmd | head -1)
if [[ -n $swift_pid ]]; then
break;
fi
sleep 1
done
fi
echo $swift_date
if [[ -n $outfile ]]; then
echo $swift_date > $outfile
fi
cmd="ps -p $swift_pid -o etimes,%cpu,%mem"
$cmd
kill -s 0 $swift_pid 2>/dev/null
while [[ $? -eq 0 ]]; do
sleep $sleepSecs
if [[ -n $outfile ]]; then
$cmd --no-headers | tee -a $outfile
else
$cmd --no-headers
fi
kill -s 0 $swift_pid 2>/dev/null
done