| 1 | #!/bin/bash -xeu |
| 2 | # Copyright (C) 2017 - Francis Deslauriers <francis.deslauriers@efficios.com> |
| 3 | # |
| 4 | # This program is free software: you can redistribute it and/or modify |
| 5 | # it under the terms of the GNU General Public License as published by |
| 6 | # the Free Software Foundation, either version 3 of the License, or |
| 7 | # (at your option) any later version. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | NB_KPROBE_PER_ITER=500 |
| 18 | SESSION_NAME="my_kprobe_session" |
| 19 | |
| 20 | # Silence the script to avoid redirection of kallsyms to fill the screen |
| 21 | set +x |
| 22 | syms=$(awk '{print $3;}' /proc/kallsyms | sort -R) |
| 23 | nb_syms=$(echo "$syms" | wc -l) |
| 24 | set -x |
| 25 | |
| 26 | # Loop over the list of symbols and enable the symbols in groups of |
| 27 | # $NB_KPROBE_PER_ITER |
| 28 | for i in $(seq 0 "$NB_KPROBE_PER_ITER" "$nb_syms"); do |
| 29 | # Pick $NB_KPROBE_PER_ITER symbols to instrument, craft enable-event |
| 30 | # command and save them to a file. We craft the commands and executed |
| 31 | # them in two steps so that the pipeline can be done without the bash |
| 32 | # '-x' option that would fill the serial buffer because of the multiple |
| 33 | # pipe redirections. |
| 34 | set +x |
| 35 | echo "$syms" | head -n $((i+NB_KPROBE_PER_ITER)) | tail -n $NB_KPROBE_PER_ITER |awk '{print "lttng enable-event --kernel --function=" $1 " " $1}' > lttng-enable-event.sh |
| 36 | set -x |
| 37 | |
| 38 | # Print what iteration we are at |
| 39 | echo "$i" $((i+NB_KPROBE_PER_ITER)) |
| 40 | |
| 41 | # Destroy previous session and create a new one |
| 42 | lttng create "$SESSION_NAME" |
| 43 | |
| 44 | # Expect commands to fail, turn off early exit of shell script on |
| 45 | # non-zero return value |
| 46 | set +e |
| 47 | source ./lttng-enable-event.sh |
| 48 | set -e |
| 49 | |
| 50 | # Run stress util to generate some kernel activity |
| 51 | stress --cpu 2 --io 4 --vm 2 --vm-bytes 128M --hdd 3 --timeout 5s |
| 52 | |
| 53 | lttng list "$SESSION_NAME" |
| 54 | lttng destroy "$SESSION_NAME" |
| 55 | done |