static DEFINE_MUTEX(event_mutex);
-#define events_for_each(event) \
- for (event = __start_ftrace_events; \
- (unsigned long)event < (unsigned long)__stop_ftrace_events; \
- event++)
-
-void event_trace_printk(unsigned long ip, const char *fmt, ...)
+int trace_define_field(struct ftrace_event_call *call, char *type,
+ char *name, int offset, int size)
{
- va_list ap;
+ struct ftrace_event_field *field;
+
+ field = kzalloc(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;
- va_start(ap, fmt);
- tracing_record_cmdline(current);
- trace_vprintk(ip, task_curr_ret_stack(current), fmt, ap);
- va_end(ap);
+ 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)
call->enabled = 0;
call->unregfunc();
}
- if (call->raw_enabled) {
- call->raw_enabled = 0;
- call->raw_unreg();
- }
break;
case 1:
- if (!call->enabled &&
- (call->type & TRACE_EVENT_TYPE_PRINTF)) {
+ if (!call->enabled) {
call->enabled = 1;
call->regfunc();
}
- if (!call->raw_enabled &&
- (call->type & TRACE_EVENT_TYPE_RAW)) {
- call->raw_enabled = 1;
- call->raw_reg();
- }
break;
}
}
}
mutex_lock(&event_mutex);
- events_for_each(call) {
+ for_each_event(call) {
- if (!call->name)
+ if (!call->name || !call->regfunc)
continue;
if (match &&
if (!cnt || cnt < 0)
return 0;
+ ret = tracing_update_buffers();
+ if (ret < 0)
+ return ret;
+
ret = get_user(ch, ubuf++);
if (ret)
return ret;
(*pos)++;
- if ((unsigned long)call >= (unsigned long)__stop_ftrace_events)
- return NULL;
+ for (;;) {
+ if ((unsigned long)call >= (unsigned long)__stop_ftrace_events)
+ return NULL;
+
+ /*
+ * The ftrace subsystem is for showing formats only.
+ * They can not be enabled or disabled via the event files.
+ */
+ if (call->regfunc)
+ break;
+
+ call++;
+ next = call;
+ }
m->private = ++next;
struct ftrace_event_call *call = filp->private_data;
char *buf;
- if (call->enabled || call->raw_enabled)
+ if (call->enabled)
buf = "1\n";
else
buf = "0\n";
if (ret < 0)
return ret;
+ ret = tracing_update_buffers();
+ if (ret < 0)
+ return ret;
+
switch (val) {
case 0:
case 1:
return cnt;
}
-static ssize_t
-event_type_read(struct file *filp, char __user *ubuf, size_t cnt,
- loff_t *ppos)
-{
- struct ftrace_event_call *call = filp->private_data;
- char buf[16];
- int r = 0;
-
- if (call->type & TRACE_EVENT_TYPE_PRINTF)
- r += sprintf(buf, "printf\n");
-
- if (call->type & TRACE_EVENT_TYPE_RAW)
- r += sprintf(buf+r, "raw\n");
-
- return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
-}
-
-static ssize_t
-event_type_write(struct file *filp, const char __user *ubuf, size_t cnt,
- loff_t *ppos)
-{
- struct ftrace_event_call *call = filp->private_data;
- char buf[64];
-
- /*
- * If there's only one type, we can't change it.
- * And currently we always have printf type, and we
- * may or may not have raw type.
- *
- * This is a redundant check, the file should be read
- * only if this is the case anyway.
- */
-
- if (!call->raw_init)
- return -EPERM;
-
- if (cnt >= sizeof(buf))
- return -EINVAL;
-
- if (copy_from_user(&buf, ubuf, cnt))
- return -EFAULT;
-
- buf[cnt] = 0;
-
- if (!strncmp(buf, "printf", 6) &&
- (!buf[6] || isspace(buf[6]))) {
-
- call->type = TRACE_EVENT_TYPE_PRINTF;
-
- /*
- * If raw enabled, the disable it and enable
- * printf type.
- */
- if (call->raw_enabled) {
- call->raw_enabled = 0;
- call->raw_unreg();
-
- call->enabled = 1;
- call->regfunc();
- }
-
- } else if (!strncmp(buf, "raw", 3) &&
- (!buf[3] || isspace(buf[3]))) {
-
- call->type = TRACE_EVENT_TYPE_RAW;
-
- /*
- * If printf enabled, the disable it and enable
- * raw type.
- */
- if (call->enabled) {
- call->enabled = 0;
- call->unregfunc();
-
- call->raw_enabled = 1;
- call->raw_reg();
- }
- } else
- return -EINVAL;
-
- *ppos += cnt;
-
- return cnt;
-}
-
-static ssize_t
-event_available_types_read(struct file *filp, char __user *ubuf, size_t cnt,
- loff_t *ppos)
-{
- struct ftrace_event_call *call = filp->private_data;
- char buf[16];
- int r = 0;
-
- r += sprintf(buf, "printf\n");
-
- if (call->raw_init)
- r += sprintf(buf+r, "raw\n");
-
- return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
-}
-
#undef FIELD
-#define FIELD(type, name) \
- #type, #name, offsetof(typeof(field), name), sizeof(field.name)
+#define FIELD(type, name) \
+ #type, "common_" #name, offsetof(typeof(field), name), \
+ sizeof(field.name)
static int trace_write_header(struct trace_seq *s)
{
/* struct trace_entry */
return trace_seq_printf(s,
- "\tfield:%s %s;\toffset:%lu;\tsize:%lu;\n"
- "\tfield:%s %s;\toffset:%lu;\tsize:%lu;\n"
- "\tfield:%s %s;\toffset:%lu;\tsize:%lu;\n"
- "\tfield:%s %s;\toffset:%lu;\tsize:%lu;\n"
- "\tfield:%s %s;\toffset:%lu;\tsize:%lu;\n"
+ "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
+ "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
+ "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
+ "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
+ "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
"\n",
FIELD(unsigned char, type),
FIELD(unsigned char, flags),
FIELD(int, pid),
FIELD(int, tgid));
}
+
static ssize_t
event_format_read(struct file *filp, char __user *ubuf, size_t cnt,
loff_t *ppos)
char *buf;
int r;
+ if (*ppos)
+ return 0;
+
s = kmalloc(sizeof(*s), GFP_KERNEL);
if (!s)
return -ENOMEM;
trace_seq_init(s);
- if (*ppos)
- return 0;
-
/* If any of the first writes fail, so will the show_format. */
trace_seq_printf(s, "name: %s\n", call->name);
return r;
}
+static ssize_t
+event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
+{
+ struct ftrace_event_call *call = filp->private_data;
+ struct trace_seq *s;
+ int r;
+
+ if (*ppos)
+ return 0;
+
+ s = kmalloc(sizeof(*s), GFP_KERNEL);
+ if (!s)
+ return -ENOMEM;
+
+ trace_seq_init(s);
+ trace_seq_printf(s, "%d\n", call->id);
+
+ r = simple_read_from_buffer(ubuf, cnt, ppos,
+ s->buffer, s->len);
+ kfree(s);
+ return r;
+}
+
+static ssize_t
+event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
+ loff_t *ppos)
+{
+ struct ftrace_event_call *call = filp->private_data;
+ struct trace_seq *s;
+ int r;
+
+ if (*ppos)
+ return 0;
+
+ s = kmalloc(sizeof(*s), GFP_KERNEL);
+ if (!s)
+ return -ENOMEM;
+
+ trace_seq_init(s);
+
+ filter_print_preds(call->preds, s);
+ r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
+
+ kfree(s);
+
+ return r;
+}
+
+static ssize_t
+event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
+ loff_t *ppos)
+{
+ struct ftrace_event_call *call = filp->private_data;
+ char buf[64], *pbuf = buf;
+ struct filter_pred *pred;
+ int err;
+
+ if (cnt >= sizeof(buf))
+ return -EINVAL;
+
+ if (copy_from_user(&buf, ubuf, cnt))
+ return -EFAULT;
+
+ pred = kzalloc(sizeof(*pred), GFP_KERNEL);
+ if (!pred)
+ return -ENOMEM;
+
+ err = filter_parse(&pbuf, pred);
+ if (err < 0) {
+ filter_free_pred(pred);
+ return err;
+ }
+
+ if (pred->clear) {
+ filter_free_preds(call);
+ filter_free_pred(pred);
+ return cnt;
+ }
+
+ if (filter_add_pred(call, pred)) {
+ filter_free_pred(pred);
+ return -EINVAL;
+ }
+
+ *ppos += cnt;
+
+ return cnt;
+}
+
+static ssize_t
+subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
+ loff_t *ppos)
+{
+ struct event_subsystem *system = filp->private_data;
+ struct trace_seq *s;
+ int r;
+
+ if (*ppos)
+ return 0;
+
+ s = kmalloc(sizeof(*s), GFP_KERNEL);
+ if (!s)
+ return -ENOMEM;
+
+ trace_seq_init(s);
+
+ filter_print_preds(system->preds, s);
+ r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
+
+ kfree(s);
+
+ return r;
+}
+
+static ssize_t
+subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
+ loff_t *ppos)
+{
+ struct event_subsystem *system = filp->private_data;
+ char buf[64], *pbuf = buf;
+ struct filter_pred *pred;
+ int err;
+
+ if (cnt >= sizeof(buf))
+ return -EINVAL;
+
+ if (copy_from_user(&buf, ubuf, cnt))
+ return -EFAULT;
+
+ pred = kzalloc(sizeof(*pred), GFP_KERNEL);
+ if (!pred)
+ return -ENOMEM;
+
+ err = filter_parse(&pbuf, pred);
+ if (err < 0) {
+ filter_free_pred(pred);
+ return err;
+ }
+
+ if (pred->clear) {
+ filter_free_subsystem_preds(system);
+ filter_free_pred(pred);
+ return cnt;
+ }
+
+ if (filter_add_subsystem_pred(system, pred)) {
+ filter_free_subsystem_preds(system);
+ filter_free_pred(pred);
+ return -EINVAL;
+ }
+
+ *ppos += cnt;
+
+ return cnt;
+}
+
static const struct seq_operations show_event_seq_ops = {
.start = t_start,
.next = t_next,
.write = event_enable_write,
};
-static const struct file_operations ftrace_type_fops = {
+static const struct file_operations ftrace_event_format_fops = {
.open = tracing_open_generic,
- .read = event_type_read,
- .write = event_type_write,
+ .read = event_format_read,
};
-static const struct file_operations ftrace_available_types_fops = {
+static const struct file_operations ftrace_event_id_fops = {
.open = tracing_open_generic,
- .read = event_available_types_read,
+ .read = event_id_read,
};
-static const struct file_operations ftrace_event_format_fops = {
+static const struct file_operations ftrace_event_filter_fops = {
.open = tracing_open_generic,
- .read = event_format_read,
+ .read = event_filter_read,
+ .write = event_filter_write,
+};
+
+static const struct file_operations ftrace_subsystem_filter_fops = {
+ .open = tracing_open_generic,
+ .read = subsystem_filter_read,
+ .write = subsystem_filter_write,
};
static struct dentry *event_trace_events_dir(void)
return d_events;
}
-struct event_subsystem {
- struct list_head list;
- const char *name;
- struct dentry *entry;
-};
-
static LIST_HEAD(event_subsystems);
static struct dentry *
system->name = name;
list_add(&system->list, &event_subsystems);
+ system->preds = NULL;
+
return system->entry;
}
}
}
- /* default the output to printf */
- call->type = TRACE_EVENT_TYPE_PRINTF;
-
call->dir = debugfs_create_dir(call->name, d_events);
if (!call->dir) {
pr_warning("Could not create debugfs "
return -1;
}
- entry = debugfs_create_file("enable", 0644, call->dir, call,
- &ftrace_enable_fops);
- if (!entry)
- pr_warning("Could not create debugfs "
- "'%s/enable' entry\n", call->name);
+ if (call->regfunc) {
+ entry = debugfs_create_file("enable", 0644, call->dir, call,
+ &ftrace_enable_fops);
+ if (!entry)
+ pr_warning("Could not create debugfs "
+ "'%s/enable' entry\n", call->name);
+ }
- /* Only let type be writable, if we can change it */
- entry = debugfs_create_file("type",
- call->raw_init ? 0644 : 0444,
- call->dir, call,
- &ftrace_type_fops);
- if (!entry)
- pr_warning("Could not create debugfs "
- "'%s/type' entry\n", call->name);
+ if (call->id) {
+ entry = debugfs_create_file("id", 0444, call->dir, call,
+ &ftrace_event_id_fops);
+ if (!entry)
+ pr_warning("Could not create debugfs '%s/id' entry\n",
+ call->name);
+ }
- entry = debugfs_create_file("available_types", 0444, call->dir, call,
- &ftrace_available_types_fops);
- if (!entry)
- pr_warning("Could not create debugfs "
- "'%s/available_types' 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;
+ }
+ entry = debugfs_create_file("filter", 0644, call->dir, call,
+ &ftrace_event_filter_fops);
+ if (!entry)
+ pr_warning("Could not create debugfs "
+ "'%s/filter' entry\n", call->name);
+ }
/* A trace may not want to export its format */
if (!call->show_format)
if (!d_events)
return 0;
- events_for_each(call) {
+ for_each_event(call) {
/* The linker may leave blanks */
if (!call->name)
continue;