From: Steven Rostedt <rostedt@goodmis.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
kernel-team@lge.com
Subject: Re: [PATCH 2/4] ftrace: Add 'function-fork' trace option
Date: Tue, 28 Mar 2017 22:18:52 -0400 [thread overview]
Message-ID: <20170328221852.71367fd0@grimm.local.home> (raw)
In-Reply-To: <20170329014625.19346-3-namhyung@kernel.org>
On Wed, 29 Mar 2017 10:46:23 +0900
Namhyung Kim <namhyung@kernel.org> wrote:
> The function-fork option is same as event-fork that it tracks task
> fork/exit and set the pid filter properly. This can be useful if user
> wants to trace selected tasks including their children only.
Actually, I had every set, but it appears I stopped at this step. You
just finished it ;-)
Although, I think there was some issues with function tracing. I'll
have to do some more testing an analysis tomorrow. But looking at this
code, it currently appears fine.
-- Steve
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> kernel/trace/ftrace.c | 37 +++++++++++++++++++++++++++++++++++++
> kernel/trace/trace.c | 5 ++++-
> kernel/trace/trace.h | 6 +++++-
> 3 files changed, 46 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index b451a860e885..7ca2ed8d0a48 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -5575,6 +5575,43 @@ ftrace_filter_pid_sched_switch_probe(void *data, bool preempt,
> trace_ignore_this_task(pid_list, next));
> }
>
> +static void
> +ftrace_pid_follow_sched_process_fork(void *data,
> + struct task_struct *self,
> + struct task_struct *task)
> +{
> + struct trace_pid_list *pid_list;
> + struct trace_array *tr = data;
> +
> + pid_list = rcu_dereference_sched(tr->function_pids);
> + trace_filter_add_remove_task(pid_list, self, task);
> +}
> +
> +static void
> +ftrace_pid_follow_sched_process_exit(void *data, struct task_struct *task)
> +{
> + struct trace_pid_list *pid_list;
> + struct trace_array *tr = data;
> +
> + pid_list = rcu_dereference_sched(tr->function_pids);
> + trace_filter_add_remove_task(pid_list, NULL, task);
> +}
> +
> +void ftrace_pid_follow_fork(struct trace_array *tr, bool enable)
> +{
> + if (enable) {
> + register_trace_sched_process_fork(ftrace_pid_follow_sched_process_fork,
> + tr);
> + register_trace_sched_process_exit(ftrace_pid_follow_sched_process_exit,
> + tr);
> + } else {
> + unregister_trace_sched_process_fork(ftrace_pid_follow_sched_process_fork,
> + tr);
> + unregister_trace_sched_process_exit(ftrace_pid_follow_sched_process_exit,
> + tr);
> + }
> +}
> +
> static void clear_ftrace_pids(struct trace_array *tr)
> {
> struct trace_pid_list *pid_list;
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index b92489dfa829..291d8fc9dc36 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -257,7 +257,7 @@ unsigned long long ns2usecs(u64 nsec)
>
> /* trace_flags that are default zero for instances */
> #define ZEROED_TRACE_FLAGS \
> - TRACE_ITER_EVENT_FORK
> + (TRACE_ITER_EVENT_FORK | TRACE_ITER_FUNC_FORK)
>
> /*
> * The global_trace is the descriptor that holds the top-level tracing
> @@ -4205,6 +4205,9 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
> if (mask == TRACE_ITER_EVENT_FORK)
> trace_event_follow_fork(tr, enabled);
>
> + if (mask == TRACE_ITER_FUNC_FORK)
> + ftrace_pid_follow_fork(tr, enabled);
> +
> if (mask == TRACE_ITER_OVERWRITE) {
> ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled);
> #ifdef CONFIG_TRACER_MAX_TRACE
> diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
> index 4d9804fd9a2d..bacf5e845c55 100644
> --- a/kernel/trace/trace.h
> +++ b/kernel/trace/trace.h
> @@ -898,6 +898,7 @@ void ftrace_init_tracefs_toplevel(struct trace_array *tr,
> struct dentry *d_tracer);
> int init_function_trace(void);
> void ftrace_pid_reset(struct trace_array *tr, bool update);
> +void ftrace_pid_follow_fork(struct trace_array *tr, bool enable);
> #else
> static inline int ftrace_trace_task(struct trace_array *tr)
> {
> @@ -918,6 +919,7 @@ static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d)
> static inline void ftrace_init_tracefs_toplevel(struct trace_array *tr, struct dentry *d) { }
> static inline int init_function_trace(void) { return 0; }
> static inline void ftrace_pid_reset(struct trace_array *tr, bool update) { }
> +static inline void ftrace_pid_follow_fork(struct trace_array *tr, bool enable) { }
> /* ftace_func_t type is not defined, use macro instead of static inline */
> #define ftrace_init_array_ops(tr, func) do { } while (0)
> #endif /* CONFIG_FUNCTION_TRACER */
> @@ -991,11 +993,13 @@ extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
>
> #ifdef CONFIG_FUNCTION_TRACER
> # define FUNCTION_FLAGS \
> - C(FUNCTION, "function-trace"),
> + C(FUNCTION, "function-trace"), \
> + C(FUNC_FORK, "function-fork"),
> # define FUNCTION_DEFAULT_FLAGS TRACE_ITER_FUNCTION
> #else
> # define FUNCTION_FLAGS
> # define FUNCTION_DEFAULT_FLAGS 0UL
> +# define TRACE_ITER_FUNC_FORK 0UL
> #endif
>
> #ifdef CONFIG_STACKTRACE
next prev parent reply other threads:[~2017-03-29 2:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-29 1:46 [PATCH 0/4] ftrace: Add 'function-fork' trace option (v1) Namhyung Kim
2017-03-29 1:46 ` [PATCH 1/4] ftrace: Fix function pid filter on instances Namhyung Kim
2017-03-29 2:08 ` Steven Rostedt
2017-03-29 2:20 ` Namhyung Kim
2017-03-29 2:28 ` Steven Rostedt
2017-03-29 2:42 ` Namhyung Kim
2017-03-29 2:58 ` Steven Rostedt
2017-03-29 3:02 ` Namhyung Kim
2017-03-29 2:25 ` Namhyung Kim
2017-03-29 1:46 ` [PATCH 2/4] ftrace: Add 'function-fork' trace option Namhyung Kim
2017-03-29 2:18 ` Steven Rostedt [this message]
2017-03-29 2:21 ` Steven Rostedt
2017-03-29 1:46 ` [PATCH 3/4] selftests: ftrace: Add -l/--logdir option Namhyung Kim
2017-03-29 8:30 ` Masami Hiramatsu
2017-03-29 1:46 ` [PATCH 4/4] selftests: ftrace: Add a testcase for function PID filter Namhyung Kim
2017-03-29 1:51 ` [PATCH 0/4] ftrace: Add 'function-fork' trace option (v1) Steven Rostedt
2017-03-30 0:54 ` Masami Hiramatsu
2017-03-30 1:40 ` Namhyung Kim
2017-03-30 13:49 ` Steven Rostedt
2017-03-30 22:25 ` Masami Hiramatsu
2017-03-30 22:28 ` Steven Rostedt
2017-04-17 2:44 [PATCH 0/4] ftrace: Add 'function-fork' trace option (v2) Namhyung Kim
2017-04-17 2:44 ` [PATCH 2/4] ftrace: Add 'function-fork' trace option Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170328221852.71367fd0@grimm.local.home \
--to=rostedt@goodmis.org \
--cc=kernel-team@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®