Skip to contentSkip to conversation

tracing: add run-time field descriptions for event filtering

RFC PATCH In review Tom Zanussi 1 participant 1 message Mar 17, 2009 Tracing

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/4 tracing: add run-time field descriptions for event filtering

This patch makes the field descriptions defined for event tracing available at run-time, for the event-filtering mechanism introduced in a subsequent patch.

NOTE: Because of the way the common event fields are implemented (pid, tgid, etc), there can be two fields of the same name for an event, as shown in the output of the event format. For now, to allow the user to unambiguously specify one or the other, the common field names are prepended with an underscore, although they don't show up that way in the format output. So for an event that defines its own pid field in addition to the common pid field, to filter on the common field, a filter on the common field would be specified as:

_pid != 0

while a filter on the event-specific pid field would be:

pid != 0

One way to fix this would be to make the common field names unique, or make the field names in the format match the names used in the run-time definition.

---
 kernel/trace/trace.h                |   32 +++++++++++++++++-------
 kernel/trace/trace_events.c         |   37 ++++++++++++++++++++++++++++
 kernel/trace/trace_events_stage_2.h |   45 +++++++++++++++++++++++++++++++++++
 kernel/trace/trace_events_stage_3.h |    2 +
 4 files changed, 106 insertions(+), 10 deletions(-)
kernel/trace/trace.h +22 -10
index f561628..6981e28 100644
@@ -776,18 +776,30 @@ enum {
 	TRACE_EVENT_TYPE_RAW		= 2,
 };
 
-struct ftrace_event_call {
-	char		*name;
-	char		*system;
-	struct dentry	*dir;
-	int		enabled;
-	int		(*regfunc)(void);
-	void		(*unregfunc)(void);
-	int		id;
-	int		(*raw_init)(void);
-	int		(*show_format)(struct trace_seq *s);
+struct ftrace_event_field {
+	struct list_head	link;
+	char			*name;
+	char			*type;
+	int			offset;
+	int			size;
 };
 
+struct ftrace_event_call {
+	char			*name;
+	char			*system;
+	struct dentry		*dir;
+	int			enabled;
+	int			(*regfunc)(void);
+	void			(*unregfunc)(void);
+	int			id;
+	int			(*raw_init)(void);
+	int			(*show_format)(struct trace_seq *s);
+	int			(*define_fields)(void);
+	struct list_head	fields;
+};
+
+int trace_define_field(struct ftrace_event_call *call, char *type,
+		       char *name, int offset, int size);
 void event_trace_printk(unsigned long ip, const char *fmt, ...);
 extern struct ftrace_event_call __start_ftrace_events[];
 extern struct ftrace_event_call __stop_ftrace_events[];
kernel/trace/trace_events.c +37 -0
index c88227b..8b74570 100644
@@ -24,6 +24,34 @@ static DEFINE_MUTEX(event_mutex);
 	     (unsigned long)event < (unsigned long)__stop_ftrace_events; \
 	     event++)
 
+int trace_define_field(struct ftrace_event_call *call, char *type,
+		       char *name, int offset, int size)
+{
+	struct ftrace_event_field *field;
+
+	field = kmalloc(sizeof(*field), GFP_KERNEL);
+	if (!field)
+		goto err;
+	field->name = kstrdup(name, GFP_KERNEL);
+	if (!field->name)
+		goto err;
+	field->type = kstrdup(type, GFP_KERNEL);
+	if (!field->type)
+		goto err;
+	field->offset = offset;
+	field->size = size;
+	list_add(&field->link, &call->fields);
+
+	return 0;
+err:
+	if (field) {
+		kfree(field->name);
+		kfree(field->type);
+	}
+	kfree(field);
+	return -ENOMEM;
+}
+
 static void ftrace_clear_events(void)
 {
 	struct ftrace_event_call *call = (void *)__start_ftrace_events;
@@ -550,6 +578,15 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events)
 				   "'%s/enable' entry\n", call->name);
 	}
 
+	if (call->define_fields) {
+		ret = call->define_fields();
+		if (ret < 0) {
+			pr_warning("Could not initialize trace point"
+				   " events/%s\n", call->name);
+			return ret;
+		}
+	}
+
 	/* A trace may not want to export its format */
 	if (!call->show_format)
 		return 0;
kernel/trace/trace_events_stage_2.h +45 -0

48 lines not on this page · raw message

kernel/trace/trace_events_stage_3.h +2 -0
index ae2e323..30627d8 100644
@@ -202,6 +202,7 @@ static int ftrace_raw_init_event_##call(void)				\
 	if (!id)							\
 		return -ENODEV;						\
 	event_##call.id = id;						\
+	INIT_LIST_HEAD(&event_##call.fields);				\
 	return 0;							\
 }									\
 									\
@@ -214,4 +215,5 @@ __attribute__((section("_ftrace_events"))) event_##call = {		\
 	.regfunc		= ftrace_raw_reg_event_##call,		\
 	.unregfunc		= ftrace_raw_unreg_event_##call,	\
 	.show_format		= ftrace_format_##call,			\
+	.define_fields		= ftrace_define_fields_##call,		\
 }
Signature · 1 line
1.5.6.3