tracing: Add support for recording tgid of tasks
PATCH v5 1/3 tracing: Add support for recording tgid of tasks
Inorder to support recording of tgid, the following changes are made:
* Introduce a new API (tracing_record_taskinfo) to additionally record the tgid along with the task's comm at the same time. This has has the benefit of not setting trace_cmdline_save before all the information for a task is saved.
* Add a new API tracing_record_taskinfo_sched_switch to record task information for 2 tasks at a time (previous and next) and use it from sched_switch probe.
* Preserve the old API (tracing_record_cmdline) and create it as a wrapper around the new one so that existing callers aren't affected.
* Reuse the existing sched_switch and sched_wakeup probes to record tgid information and add a new option 'record-tgid' to enable recording of tgid
When record-tgid option isn't enabled to being with, we take care to make sure that there's isn't memory or runtime overhead.
---
Hi Steven, Here's the reworked patch addressing the allocator concerns. I'm just sending you this single patch since all our discussion in the morning was on this patch. Let me know if you still want me to resend 2/3 and 3/3 which are the same as v4 sent last evening.
include/linux/trace_events.h | 13 ++++- kernel/trace/trace.c | 105 ++++++++++++++++++++++++++++++++++---- kernel/trace/trace.h | 7 +++ kernel/trace/trace_events.c | 42 ++++++++++++++- kernel/trace/trace_sched_switch.c | 72 +++++++++++++++++++++----- 5 files changed, 213 insertions(+), 26 deletions(-)
include/linux/trace_events.h +12 -1
@@ -151,7 +151,15 @@ trace_event_buffer_lock_reserve(struct ring_buffer **current_buffer, int type, unsigned long len, unsigned long flags, int pc); -void tracing_record_cmdline (struct task_struct *tsk); +#define TRACE_RECORD_CMDLINE BIT(0) +#define TRACE_RECORD_TGID BIT(1) + +void tracing_record_taskinfo (struct task_struct *task,int flags); +void tracing_record_taskinfo_sched_switch (struct task_struct *prev, +struct task_struct *next,int flags); + +void tracing_record_cmdline (struct task_struct *task); +void tracing_record_tgid (struct task_struct *task);int trace_output_call (struct trace_iterator *iter,char *name,char *fmt, ...);
@@ -290,6 +298,7 @@ struct trace_subsystem_dir;enum {EVENT_FILE_FL_ENABLED_BIT ,EVENT_FILE_FL_RECORDED_CMD_BIT , +EVENT_FILE_FL_RECORDED_TGID_BIT ,EVENT_FILE_FL_FILTERED_BIT ,EVENT_FILE_FL_NO_SET_FILTER_BIT ,EVENT_FILE_FL_SOFT_MODE_BIT ,
@@ -303,6 +312,7 @@ enum {* Event file flags: * ENABLED - The event is enabled * RECORDED_CMD - The comms should be recorded at sched_switch +* RECORDED_TGID - The tgids should be recorded at sched_switch * FILTERED - The event has a filter attached * NO_SET_FILTER - Set when filter has error and is to be ignored * SOFT_MODE - The event is enabled/disabled by SOFT_DISABLED
@@ -315,6 +325,7 @@ enum {enum {EVENT_FILE_FL_ENABLED = (1 <<EVENT_FILE_FL_ENABLED_BIT ),EVENT_FILE_FL_RECORDED_CMD = (1 <<EVENT_FILE_FL_RECORDED_CMD_BIT ), +EVENT_FILE_FL_RECORDED_TGID = (1 <<EVENT_FILE_FL_RECORDED_TGID_BIT ),EVENT_FILE_FL_FILTERED = (1 <<EVENT_FILE_FL_FILTERED_BIT ),EVENT_FILE_FL_NO_SET_FILTER = (1 <<EVENT_FILE_FL_NO_SET_FILTER_BIT ),EVENT_FILE_FL_SOFT_MODE = (1 <<EVENT_FILE_FL_SOFT_MODE_BIT ),
kernel/trace/trace.c +95 -10
158 lines not on this page · raw message
kernel/trace/trace.h +7 -0
@@ -637,6 +637,9 @@ void set_graph_array(struct trace_array *tr);void tracing_start_cmdline_record (void );void tracing_stop_cmdline_record (void ); +void tracing_start_tgid_record (void ); +void tracing_stop_tgid_record (void ); +int register_tracer (struct tracer *type);int is_tracing_stopped (void );
@@ -697,6 +700,7 @@ static inline void __trace_stack(struct trace_array *tr, unsigned long flags,extern u64 ftrace_now (int cpu);extern void trace_find_cmdline (int pid,char comm[]); +extern int trace_find_tgid (int pid);extern void trace_event_follow_fork (struct trace_array *tr,bool enable);#ifdef CONFIG_DYNAMIC_FTRACE
@@ -1107,6 +1111,7 @@ extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,C (CONTEXT_INFO ,"context-info" ),/* Print pid/cpu/time */ \C (LATENCY_FMT ,"latency-format" ), \C (RECORD_CMD ,"record-cmd" ), \ +C (RECORD_TGID ,"record-tgid" ), \C (OVERWRITE ,"overwrite" ), \C (STOP_ON_FREE ,"disable_on_free" ), \ C(IRQ_INFO, "irq-info"), \
@@ -1423,6 +1428,8 @@ struct ftrace_event_field * trace_find_event_field(struct trace_event_call *call, char *name);extern void trace_event_enable_cmd_record (bool enable); +extern void trace_event_enable_tgid_record (bool enable); +extern int event_trace_add_tracer (struct dentry *parent,struct trace_array *tr);extern int event_trace_del_tracer (struct trace_array *tr);
kernel/trace/trace_events.c +41 -1
71 lines not on this page · raw message
kernel/trace/trace_sched_switch.c +58 -14
113 lines not on this page · raw message
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog