kernel/trace: Introduce trace_probe_print_args and use it in *probes
authorSong Chen <chensong_2000@189.cn>
Fri, 30 Dec 2022 06:33:19 +0000 (14:33 +0800)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Fri, 24 Feb 2023 00:44:15 +0000 (09:44 +0900)
print_probe_args is currently inplemented in trace_probe_tmpl.h and
included by *probes, as a result, each probe has an identical copy.

This patch will move it to trace_probe.c as an new API, each probe
calls it to print their args in trace file.

Link: https://lore.kernel.org/all/1672382000-18304-1-git-send-email-chensong_2000@189.cn/
Signed-off-by: Song Chen <chensong_2000@189.cn>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
kernel/trace/trace_eprobe.c
kernel/trace/trace_kprobe.c
kernel/trace/trace_probe.c
kernel/trace/trace_probe.h
kernel/trace/trace_probe_tmpl.h
kernel/trace/trace_uprobe.c

index 594ac1d086aa33f3d46361310208cd768a2ad1f0..9d0ebcffb5391b474bb1384dedad91a565b5ceb1 100644 (file)
@@ -311,7 +311,7 @@ print_eprobe_event(struct trace_iterator *iter, int flags,
 
        trace_seq_putc(s, ')');
 
-       if (print_probe_args(s, tp->args, tp->nr_args,
+       if (trace_probe_print_args(s, tp->args, tp->nr_args,
                             (u8 *)&field[1], field) < 0)
                goto out;
 
index ee77c8203bd588552ddeabcb268e1400b2cd5d43..086e1e14f89e84af3cd8bbd689a7fb589919b92e 100644 (file)
@@ -1424,7 +1424,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
 
        trace_seq_putc(s, ')');
 
-       if (print_probe_args(s, tp->args, tp->nr_args,
+       if (trace_probe_print_args(s, tp->args, tp->nr_args,
                             (u8 *)&field[1], field) < 0)
                goto out;
 
@@ -1459,7 +1459,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
 
        trace_seq_putc(s, ')');
 
-       if (print_probe_args(s, tp->args, tp->nr_args,
+       if (trace_probe_print_args(s, tp->args, tp->nr_args,
                             (u8 *)&field[1], field) < 0)
                goto out;
 
index 11008c098727408daf51e495010ef949dafedbc6..20d0c4a9763324c1f411f00b552d2b0f0e13f31b 100644 (file)
@@ -1239,3 +1239,30 @@ int trace_probe_create(const char *raw_command, int (*createfn)(int, const char
 
        return ret;
 }
+
+int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
+                u8 *data, void *field)
+{
+       void *p;
+       int i, j;
+
+       for (i = 0; i < nr_args; i++) {
+               struct probe_arg *a = args + i;
+
+               trace_seq_printf(s, " %s=", a->name);
+               if (likely(!a->count)) {
+                       if (!a->type->print(s, data + a->offset, field))
+                               return -ENOMEM;
+                       continue;
+               }
+               trace_seq_putc(s, '{');
+               p = data + a->offset;
+               for (j = 0; j < a->count; j++) {
+                       if (!a->type->print(s, p, field))
+                               return -ENOMEM;
+                       trace_seq_putc(s, j == a->count - 1 ? '}' : ',');
+                       p += a->type->size;
+               }
+       }
+       return 0;
+}
index b4f99553411e286533db39adec80980b240de902..ef8ed3b65d0550bfd87b74c39b4657b7fc5044f4 100644 (file)
@@ -349,6 +349,8 @@ int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b);
 bool trace_probe_match_command_args(struct trace_probe *tp,
                                    int argc, const char **argv);
 int trace_probe_create(const char *raw_command, int (*createfn)(int, const char **));
+int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
+                u8 *data, void *field);
 
 #define trace_probe_for_each_link(pos, tp)     \
        list_for_each_entry(pos, &(tp)->event->files, list)
index 5cea672243f61dd52a9387aa401268170a018591..bd3e755434eb9ac97a2613f591f00defe2cb8a22 100644 (file)
@@ -253,31 +253,3 @@ store_trace_args(void *data, struct trace_probe *tp, void *rec,
                }
        }
 }
-
-static inline int
-print_probe_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
-                u8 *data, void *field)
-{
-       void *p;
-       int i, j;
-
-       for (i = 0; i < nr_args; i++) {
-               struct probe_arg *a = args + i;
-
-               trace_seq_printf(s, " %s=", a->name);
-               if (likely(!a->count)) {
-                       if (!a->type->print(s, data + a->offset, field))
-                               return -ENOMEM;
-                       continue;
-               }
-               trace_seq_putc(s, '{');
-               p = data + a->offset;
-               for (j = 0; j < a->count; j++) {
-                       if (!a->type->print(s, p, field))
-                               return -ENOMEM;
-                       trace_seq_putc(s, j == a->count - 1 ? '}' : ',');
-                       p += a->type->size;
-               }
-       }
-       return 0;
-}
index 8d64b6553aedf7244431caab9f7f6e7b07eaa4d8..a39018a0660a886231c1e5afb7c6299d4f187645 100644 (file)
@@ -1042,7 +1042,7 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e
                data = DATAOF_TRACE_ENTRY(entry, false);
        }
 
-       if (print_probe_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0)
+       if (trace_probe_print_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0)
                goto out;
 
        trace_seq_putc(s, '\n');