blob: 2b9e11b66dc7a8011bcaa2e018bde54aee57f0c4 (
plain)
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
48
49
50
51
52
53
54
55
56
57
58
|
# SPDX-License-Identifier: GPL-2.0
PERF_RECORD_LOGS=()
perf_record_with_retry() {
local perfdata="$1"
local check_cmd="$2"
local testprog_base="$3"
shift 3
local logfile
logfile=$(mktemp /tmp/__perf_record_retry.XXXXXX)
PERF_RECORD_LOGS+=("$logfile")
# Save the e flag state and disable it
local save_e
if [[ $- == *e* ]]; then
save_e="set -e"
else
save_e="set +e"
fi
set +e
local duration
local first_run=true
local ret=1
local cmd_prefix="perf record"
if [ -n "${PERF_RECORD_CMD}" ]; then
cmd_prefix="${PERF_RECORD_CMD}"
fi
for duration in 0.01 0.1 0.3 1.0 2.0; do
rm -f "${perfdata}".old
${cmd_prefix} "$@" -o "${perfdata}" ${testprog_base} ${duration} > "$logfile" 2>&1
local record_exit=$?
if [ "$first_run" = true ] && [ $record_exit -ne 0 ]; then
ret=2
break
fi
first_run=false
if [ -e "${perfdata}" ] && eval "${check_cmd}"; then
ret=0
break
fi
done
eval "$save_e"
return $ret
}
perf_record_cleanup() {
for logfile in "${PERF_RECORD_LOGS[@]}"; do
rm -f "$logfile"
done
PERF_RECORD_LOGS=()
}
|