mirror of
https://github.com/brendangregg/perf-tools.git
synced 2025-12-01 07:26:04 +07:00
kprobe: Make -p switch respect all process' threads
Signed-off-by: Sasha Goldshtein <goldshtn@gmail.com>
This commit is contained in:
@@ -346,10 +346,11 @@ This makes use of the kernel options/stacktrace feature.
|
||||
Use -h to print the USAGE message:
|
||||
|
||||
# ./kprobe -h
|
||||
USAGE: kprobe [-FhHsv] [-d secs] [-p PID] kprobe_definition [filter]
|
||||
USAGE: kprobe [-FhHsv] [-d secs] [-p PID] [-L TID] kprobe_definition [filter]
|
||||
-F # force. trace despite warnings.
|
||||
-d seconds # trace duration, and use buffers
|
||||
-p PID # PID to match on I/O issue
|
||||
-p PID # PID to match on events
|
||||
-L TID # thread id to match on events
|
||||
-v # view format file (don't trace)
|
||||
-H # include column headers
|
||||
-s # show kernel stack traces
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
# the probe alias is optional (it will become to kprobe:<funcname> if not
|
||||
# specified).
|
||||
#
|
||||
# USAGE: ./kprobe [-FhHsv] [-d secs] [-p pid] kprobe_definition [filter]
|
||||
# USAGE: ./kprobe [-FhHsv] [-d secs] [-p pid] [-L tid] kprobe_definition [filter]
|
||||
#
|
||||
# Run "kprobe -h" for full usage.
|
||||
#
|
||||
@@ -50,16 +50,18 @@
|
||||
### default variables
|
||||
tracing=/sys/kernel/debug/tracing
|
||||
flock=/var/tmp/.ftrace-lock; wroteflock=0
|
||||
opt_duration=0; duration=; opt_pid=0; pid=; opt_filter=0; filter=
|
||||
opt_view=0; opt_headers=0; opt_stack=0; dmesg=2; debug=0; opt_force=0
|
||||
opt_duration=0; duration=; opt_pid=0; pid=; opt_tid=0; tid=
|
||||
opt_filter=0; filter=; opt_view=0; opt_headers=0; opt_stack=0; dmesg=2
|
||||
debug=0; opt_force=0
|
||||
trap ':' INT QUIT TERM PIPE HUP # sends execution to end tracing section
|
||||
|
||||
function usage {
|
||||
cat <<-END >&2
|
||||
USAGE: kprobe [-FhHsv] [-d secs] [-p PID] kprobe_definition [filter]
|
||||
USAGE: kprobe [-FhHsv] [-d secs] [-p PID] [-L TID] kprobe_definition [filter]
|
||||
-F # force. trace despite warnings.
|
||||
-d seconds # trace duration, and use buffers
|
||||
-p PID # PID to match on events
|
||||
-L TID # thread id to match on events
|
||||
-v # view format file (don't trace)
|
||||
-H # include column headers
|
||||
-s # show kernel stack traces
|
||||
@@ -125,12 +127,13 @@ function edie {
|
||||
}
|
||||
|
||||
### process options
|
||||
while getopts Fd:hHp:sv opt
|
||||
while getopts Fd:hHp:L:sv opt
|
||||
do
|
||||
case $opt in
|
||||
F) opt_force=1 ;;
|
||||
d) opt_duration=1; duration=$OPTARG ;;
|
||||
p) opt_pid=1; pid=$OPTARG ;;
|
||||
L) opt_tid=1; tid=$OPTARG ;;
|
||||
H) opt_headers=1 ;;
|
||||
s) opt_stack=1 ;;
|
||||
v) opt_view=1 ;;
|
||||
@@ -147,12 +150,21 @@ if (( $# )); then
|
||||
fi
|
||||
|
||||
### option logic
|
||||
(( opt_pid && opt_filter )) && die "ERROR: use either -p or a filter."
|
||||
(( opt_pid + opt_filter + opt_tid > 1 )) && \
|
||||
die "ERROR: use at most one of -p, -L, or filter."
|
||||
(( opt_duration && opt_view )) && die "ERROR: use either -d or -v."
|
||||
if (( opt_pid )); then
|
||||
# convert to filter
|
||||
opt_filter=1
|
||||
filter="common_pid == $pid"
|
||||
# ftrace common_pid is thread id from user's perspective
|
||||
for tid in /proc/$pid/task/*; do
|
||||
filter="$filter || common_pid == ${tid##*/}"
|
||||
done
|
||||
filter=${filter:3} # trim leading ' || ' (four characters)
|
||||
fi
|
||||
if (( opt_tid )); then
|
||||
opt_filter=1
|
||||
filter="common_pid == $tid"
|
||||
fi
|
||||
if [[ "$kprobe" != p:* && "$kprobe" != r:* ]]; then
|
||||
echo >&2 "ERROR: invalid kprobe definition (should start with p: or r:)"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
kprobe \- trace a given kprobe definition. Kernel dynamic tracing. Uses Linux ftrace.
|
||||
.SH SYNOPSIS
|
||||
.B kprobe
|
||||
[\-FhHsv] [\-d secs] [\-p PID] kprobe_definition [filter]
|
||||
[\-FhHsv] [\-d secs] [\-p PID] [\-L TID] kprobe_definition [filter]
|
||||
.SH DESCRIPTION
|
||||
This will create, trace, then destroy a given kprobe definition. See
|
||||
Documentation/trace/kprobetrace.txt in the Linux kernel source for the
|
||||
@@ -60,6 +60,9 @@ for use in a custom filter.
|
||||
\-p PID
|
||||
Only trace kernel functions when this process ID is on-CPU.
|
||||
.TP
|
||||
\-L TID
|
||||
Only trace kernel functions when this thread ID is on-CPU.
|
||||
.TP
|
||||
kprobe_definition
|
||||
A full kprobe definition, as documented by Documentation/trace/kprobetrace.txt
|
||||
in the Linux kernel source. Note that the probe alias name is optional with
|
||||
|
||||
Reference in New Issue
Block a user