lkml.org 
[lkml]   [2020]   [Oct]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] tracing: add tgid into common field
Date
Sometimes we want to trace a specific mutil-threaded process, which may
create threads dynamically. Currently it is not easy to trace all its
threads, because we can only filter these threads out by using
common_pid.

This patch adds the tgid into the common field as well, with which we
can easily filter this mutil-threaded process out. E.g.

$ cd /sys/kernel/debug/tracing
$ echo 'common_tgid == 4054' > events/sched/sched_wakeup/filter
$ cat trace_pipe
python-4057 [005] d... 48003.898560: sched_wakeup: comm=python pid=4054 prio=120 target_cpu=002
python-4054 [002] dNs. 48003.932906: sched_wakeup: comm=kworker/2:2 pid=130 prio=120 target_cpu=002
python-4054 [002] dNH. 48003.932907: sched_wakeup: comm=cat pid=4084 prio=120 target_cpu=004
python-4055 [003] d... 48004.816596: sched_wakeup: comm=python pid=4054 prio=120 target_cpu=002

With record-tgid set into trace_options, we can show the tgid,

$ echo record-tgid > trace_options
$ cat trace_pipe
python-4054 ( 4054) [002] d... 48166.611771: sched_wakeup: comm=python pid=4055 prio=120 target_cpu=004
python-4057 ( 4054) [005] d... 48166.611776: sched_wakeup: comm=python pid=4054 prio=120 target_cpu=002
python-4055 ( 4054) [004] d... 48166.611848: sched_wakeup: comm=python pid=4054 prio=120 target_cpu=002

After that change, tgid_map is only used by saved_tgid, which may be
used by some user tools, so I just keep it as-is.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
include/linux/trace_events.h | 1 +
kernel/trace/trace.c | 1 +
kernel/trace/trace_events.c | 1 +
kernel/trace/trace_output.c | 2 +-
4 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 5c6943354049..3725c05f0b01 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -67,6 +67,7 @@ struct trace_entry {
unsigned char flags;
unsigned char preempt_count;
int pid;
+ int tgid;
};

#define TRACE_EVENT_TYPE_MAX \
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index d3e5de717df2..c2423efaac2c 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2445,6 +2445,7 @@ tracing_generic_entry_update(struct trace_entry *entry, unsigned short type,

entry->preempt_count = pc & 0xff;
entry->pid = (tsk) ? tsk->pid : 0;
+ entry->tgid = (tsk) ? tsk->tgid : 0;
entry->type = type;
entry->flags =
#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index a85effb2373b..9a5adcecf245 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -182,6 +182,7 @@ static int trace_define_common_fields(void)
__common_field(unsigned char, flags);
__common_field(unsigned char, preempt_count);
__common_field(int, pid);
+ __common_field(int, tgid);

return ret;
}
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 000e9dc224c6..e04dd45267c7 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -591,7 +591,7 @@ int trace_print_context(struct trace_iterator *iter)
trace_seq_printf(s, "%16s-%-7d ", comm, entry->pid);

if (tr->trace_flags & TRACE_ITER_RECORD_TGID) {
- unsigned int tgid = trace_find_tgid(entry->pid);
+ unsigned int tgid = entry->tgid;

if (!tgid)
trace_seq_printf(s, "(-------) ");
--
2.17.1
\
 
 \ /
  Last update: 2020-10-13 07:56    [W:0.069 / U:0.296 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site