Skip to content

Commit 2768362

Browse files
committed
tracing: Create set_event_notrace_pid to not trace tasks
There's currently a way to select a task that should only have its events traced, but there's no way to select a task not to have itsevents traced. Add a set_event_notrace_pid file that acts the same as set_event_pid (and is also affected by event-fork), but the task pids in this file will not be traced even if they are listed in the set_event_pid file. This makes it easy for tools like trace-cmd to "hide" itself from beint traced by events when it is recording other tasks. Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent b3b1e6e commit 2768362

File tree

3 files changed

+244
-72
lines changed

3 files changed

+244
-72
lines changed

kernel/trace/ftrace.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6987,11 +6987,6 @@ void ftrace_pid_follow_fork(struct trace_array *tr, bool enable)
69876987
}
69886988
}
69896989

6990-
enum {
6991-
TRACE_PIDS = BIT(0),
6992-
TRACE_NO_PIDS = BIT(1),
6993-
};
6994-
69956990
static void clear_ftrace_pids(struct trace_array *tr, int type)
69966991
{
69976992
struct trace_pid_list *pid_list;
@@ -7004,13 +6999,11 @@ static void clear_ftrace_pids(struct trace_array *tr, int type)
70046999
lockdep_is_held(&ftrace_lock));
70057000

70067001
/* Make sure there's something to do */
7007-
if (!(((type & TRACE_PIDS) && pid_list) ||
7008-
((type & TRACE_NO_PIDS) && no_pid_list)))
7002+
if (!pid_type_enabled(type, pid_list, no_pid_list))
70097003
return;
70107004

70117005
/* See if the pids still need to be checked after this */
7012-
if (!((!(type & TRACE_PIDS) && pid_list) ||
7013-
(!(type & TRACE_NO_PIDS) && no_pid_list))) {
7006+
if (!still_need_pid_events(type, pid_list, no_pid_list)) {
70147007
unregister_trace_sched_switch(ftrace_filter_pid_sched_switch_probe, tr);
70157008
for_each_possible_cpu(cpu)
70167009
per_cpu_ptr(tr->array_buffer.data, cpu)->ftrace_ignore_pid = FTRACE_PID_TRACE;

kernel/trace/trace.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,30 @@ struct trace_pid_list {
207207
unsigned long *pids;
208208
};
209209

210+
enum {
211+
TRACE_PIDS = BIT(0),
212+
TRACE_NO_PIDS = BIT(1),
213+
};
214+
215+
static inline bool pid_type_enabled(int type, struct trace_pid_list *pid_list,
216+
struct trace_pid_list *no_pid_list)
217+
{
218+
/* Return true if the pid list in type has pids */
219+
return ((type & TRACE_PIDS) && pid_list) ||
220+
((type & TRACE_NO_PIDS) && no_pid_list);
221+
}
222+
223+
static inline bool still_need_pid_events(int type, struct trace_pid_list *pid_list,
224+
struct trace_pid_list *no_pid_list)
225+
{
226+
/*
227+
* Turning off what is in @type, return true if the "other"
228+
* pid list, still has pids in it.
229+
*/
230+
return (!(type & TRACE_PIDS) && pid_list) ||
231+
(!(type & TRACE_NO_PIDS) && no_pid_list);
232+
}
233+
210234
typedef bool (*cond_update_fn_t)(struct trace_array *tr, void *cond_data);
211235

212236
/**
@@ -285,6 +309,7 @@ struct trace_array {
285309
#endif
286310
#endif
287311
struct trace_pid_list __rcu *filtered_pids;
312+
struct trace_pid_list __rcu *filtered_no_pids;
288313
/*
289314
* max_lock is used to protect the swapping of buffers
290315
* when taking a max snapshot. The buffers themselves are

0 commit comments

Comments
 (0)