[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220724091050.12711-1-iecedge@gmail.com>
Date: Sun, 24 Jul 2022 09:10:50 +0000
From: Jianlin Lv <iecedge@...il.com>
To: rostedt@...dmis.org, mingo@...hat.com
Cc: iecedge@...il.com, jianlv@...y.com, linux-kernel@...r.kernel.org
Subject: [PATCH] tracing/kprobe: Add tracefs to show private kprobe
List private kprobe event to new created local_event_list;
Add tracefs file kprobe_local_profile to show events which
in local_event_list.
Signed-off-by: Jianlin Lv <iecedge@...il.com>
---
kernel/trace/trace_dynevent.c | 18 +++++++++++++
kernel/trace/trace_dynevent.h | 33 +++++++++++++++++++++++
kernel/trace/trace_kprobe.c | 50 +++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+)
diff --git a/kernel/trace/trace_dynevent.c b/kernel/trace/trace_dynevent.c
index 076b447a1b88..8411104ad6d8 100644
--- a/kernel/trace/trace_dynevent.c
+++ b/kernel/trace/trace_dynevent.c
@@ -181,6 +181,24 @@ static const struct seq_operations dyn_event_seq_op = {
.show = dyn_event_seq_show
};
+LIST_HEAD(local_event_list);
+
+void *local_event_seq_start(struct seq_file *m, loff_t *pos)
+{
+ mutex_lock(&event_mutex);
+ return seq_list_start(&local_event_list, *pos);
+}
+
+void *local_event_seq_next(struct seq_file *m, void *v, loff_t *pos)
+{
+ return seq_list_next(v, &local_event_list, pos);
+}
+
+void local_event_seq_stop(struct seq_file *m, void *v)
+{
+ mutex_unlock(&event_mutex);
+}
+
/*
* dyn_events_release_all - Release all specific events
* @type: the dyn_event_operations * which filters releasing events
diff --git a/kernel/trace/trace_dynevent.h b/kernel/trace/trace_dynevent.h
index 936477a111d3..e6413969f9ed 100644
--- a/kernel/trace/trace_dynevent.h
+++ b/kernel/trace/trace_dynevent.h
@@ -64,6 +64,7 @@ struct dyn_event {
};
extern struct list_head dyn_event_list;
+extern struct list_head local_event_list;
static inline
int dyn_event_init(struct dyn_event *ev, struct dyn_event_operations *ops)
@@ -95,12 +96,44 @@ static inline void dyn_event_remove(struct dyn_event *ev)
list_del_init(&ev->list);
}
+static inline
+int local_event_init(struct dyn_event *ev, struct dyn_event_operations *ops)
+{
+ if (!ev || !ops)
+ return -EINVAL;
+
+ INIT_LIST_HEAD(&ev->list);
+ ev->ops = ops;
+ return 0;
+}
+
+static inline int local_event_add(struct dyn_event *ev)
+{
+ lockdep_assert_held(&event_mutex);
+
+ if (!ev || !ev->ops)
+ return -EINVAL;
+
+ list_add_tail(&ev->list, &local_event_list);
+ return 0;
+}
+
+static inline void local_event_remove(struct dyn_event *ev)
+{
+ lockdep_assert_held(&event_mutex);
+ list_del_init(&ev->list);
+}
+
void *dyn_event_seq_start(struct seq_file *m, loff_t *pos);
void *dyn_event_seq_next(struct seq_file *m, void *v, loff_t *pos);
void dyn_event_seq_stop(struct seq_file *m, void *v);
int dyn_events_release_all(struct dyn_event_operations *type);
int dyn_event_release(const char *raw_command, struct dyn_event_operations *type);
+void *local_event_seq_start(struct seq_file *m, loff_t *pos);
+void *local_event_seq_next(struct seq_file *m, void *v, loff_t *pos);
+void local_event_seq_stop(struct seq_file *m, void *v);
+
/*
* for_each_dyn_event - iterate over the dyn_event list
* @pos: the struct dyn_event * to use as a loop cursor
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index a245ea673715..8fd39033d2ba 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -1213,6 +1213,50 @@ static const struct file_operations kprobe_profile_ops = {
.release = seq_release,
};
+/* kprobe Local profile */
+static int local_probes_profile_seq_show(struct seq_file *m, void *v)
+{
+ struct dyn_event *ev = v;
+ struct trace_kprobe *tk;
+
+ if (!is_trace_kprobe(ev))
+ return 0;
+
+ tk = to_trace_kprobe(ev);
+ seq_printf(m, " %-44s %15lu %15lu\n",
+ trace_probe_name(&tk->tp),
+ trace_kprobe_nhit(tk),
+ tk->rp.kp.nmissed);
+
+ return 0;
+}
+
+static const struct seq_operations local_profile_seq_op = {
+ .start = local_event_seq_start,
+ .next = local_event_seq_next,
+ .stop = local_event_seq_stop,
+ .show = local_probes_profile_seq_show
+};
+
+static int local_profile_open(struct inode *inode, struct file *file)
+{
+ int ret;
+
+ ret = security_locked_down(LOCKDOWN_TRACEFS);
+ if (ret)
+ return ret;
+
+ return seq_open(file, &local_profile_seq_op);
+}
+
+static const struct file_operations kprobe_local_profile_ops = {
+ .owner = THIS_MODULE,
+ .open = local_profile_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = seq_release,
+};
+
/* Kprobe specific fetch functions */
/* Return the length of string -- including null terminal byte */
@@ -1830,6 +1874,7 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
if (ret < 0)
goto error;
+ local_event_add(&tk->devent);
return trace_probe_event_call(&tk->tp);
error:
free_trace_kprobe(tk);
@@ -1849,6 +1894,7 @@ void destroy_local_trace_kprobe(struct trace_event_call *event_call)
return;
}
+ local_event_remove(&tk->devent);
__unregister_trace_kprobe(tk);
free_trace_kprobe(tk);
@@ -1929,6 +1975,10 @@ static __init int init_kprobe_trace(void)
trace_create_file("kprobe_profile", TRACE_MODE_READ,
NULL, NULL, &kprobe_profile_ops);
+ /* kprobe Local profile */
+ tracefs_create_file("kprobe_local_profile", TRACE_MODE_READ,
+ NULL, NULL, &kprobe_local_profile_ops);
+
setup_boot_kprobe_events();
return 0;
--
2.25.1
Powered by blists - more mailing lists