File: benchmark.sh

package info (click to toggle)
libatomic-queue 1.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,356 kB
  • sloc: cpp: 1,704; javascript: 315; makefile: 127; ansic: 91; python: 82; sh: 76
file content (40 lines) | stat: -rwxr-xr-x 1,168 bytes parent folder | download
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
#!/bin/bash

set -e # Exit on errors.

sched_rt=/proc/sys/kernel/sched_rt_runtime_us
orig_sched_rt=/tmp/${sched_rt##*/}.txt

function prologue {
    sudo hugeadm --pool-pages-min 1GB:1 || : # Ignore failures.
    sudo cpupower frequency-set --related --governor performance >/dev/null || : # Ignore failures.

    # Disable real-time throttling. Save its original value.
    if [[ -e ${sched_rt} ]]; then
        local tmp_orig_sched_rt=${orig_sched_rt}.${BASHPID}~
        [[ -e ${orig_sched_rt} ]] || cat ${sched_rt} > ${tmp_orig_sched_rt}
        echo -1 | {
            sudo tee ${sched_rt} >/dev/null
            [[ ! -e ${tmp_orig_sched_rt} ]] || mv -f ${tmp_orig_sched_rt} ${orig_sched_rt}
        }
    fi
}

function epilogue {
    sudo cpupower frequency-set --related --governor powersave >/dev/null || : # Ignore failures.

    # Restore original real-time throttling value.
    if [[ -f ${orig_sched_rt} ]]; then
        sudo tee ${sched_rt} >/dev/null <${orig_sched_rt} && rm ${orig_sched_rt}
    fi
}

function benchmark {
    trap epilogue EXIT
    prologue
    (set -e; exec "$@")
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
    benchmark "$@"
fi