All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/2] kernel/trace: Introduce trace_probe_print_args and use it in *probes
@ 2022-12-28  7:08 Song Chen
  2022-12-29  8:07 ` Masami Hiramatsu
  0 siblings, 1 reply; 2+ messages in thread
From: Song Chen @ 2022-12-28  7:08 UTC (permalink / raw)
  To: rostedt, mhiramat, arnd
  Cc: linux-kernel, linux-trace-kernel, linux-arch, Song Chen

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.

Signed-off-by: Song Chen <chensong_2000@189.cn>
---
 kernel/trace/trace_eprobe.c     |  2 +-
 kernel/trace/trace_kprobe.c     |  4 ++--
 kernel/trace/trace_probe.c      | 27 +++++++++++++++++++++++++++
 kernel/trace/trace_probe.h      |  2 ++
 kernel/trace/trace_probe_tmpl.h | 28 ----------------------------
 kernel/trace/trace_uprobe.c     |  2 +-
 6 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c
index 5dd0617e5df6..bdb26eee7a0c 100644
--- a/kernel/trace/trace_eprobe.c
+++ b/kernel/trace/trace_eprobe.c
@@ -310,7 +310,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;
 
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 5a75b039e586..a4ffa864dbb7 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -1426,7 +1426,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;
 
@@ -1461,7 +1461,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;
 
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 36dff277de46..ae13b6b2d5da 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -1218,3 +1218,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;
+}
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index de38f1c03776..cfef198013af 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -343,6 +343,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)
diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h
index b3bdb8ddb862..1b57420857e1 100644
--- a/kernel/trace/trace_probe_tmpl.h
+++ b/kernel/trace/trace_probe_tmpl.h
@@ -212,31 +212,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;
-}
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index fb58e86dd117..1ff8f87211a6 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -1041,7 +1041,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');
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v4 1/2] kernel/trace: Introduce trace_probe_print_args and use it in *probes
  2022-12-28  7:08 [PATCH v4 1/2] kernel/trace: Introduce trace_probe_print_args and use it in *probes Song Chen
@ 2022-12-29  8:07 ` Masami Hiramatsu
  0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2022-12-29  8:07 UTC (permalink / raw)
  To: Song Chen; +Cc: rostedt, arnd, linux-kernel, linux-trace-kernel, linux-arch

On Wed, 28 Dec 2022 15:08:11 +0800
Song Chen <chensong_2000@189.cn> wrote:

> 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.
> 

OK, This looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thank you!


> Signed-off-by: Song Chen <chensong_2000@189.cn>
> ---
>  kernel/trace/trace_eprobe.c     |  2 +-
>  kernel/trace/trace_kprobe.c     |  4 ++--
>  kernel/trace/trace_probe.c      | 27 +++++++++++++++++++++++++++
>  kernel/trace/trace_probe.h      |  2 ++
>  kernel/trace/trace_probe_tmpl.h | 28 ----------------------------
>  kernel/trace/trace_uprobe.c     |  2 +-
>  6 files changed, 33 insertions(+), 32 deletions(-)
> 
> diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c
> index 5dd0617e5df6..bdb26eee7a0c 100644
> --- a/kernel/trace/trace_eprobe.c
> +++ b/kernel/trace/trace_eprobe.c
> @@ -310,7 +310,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;
>  
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 5a75b039e586..a4ffa864dbb7 100644
> --- a/kernel/trace/trace_kprobe.c
> +++ b/kernel/trace/trace_kprobe.c
> @@ -1426,7 +1426,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;
>  
> @@ -1461,7 +1461,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;
>  
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index 36dff277de46..ae13b6b2d5da 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -1218,3 +1218,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;
> +}
> diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
> index de38f1c03776..cfef198013af 100644
> --- a/kernel/trace/trace_probe.h
> +++ b/kernel/trace/trace_probe.h
> @@ -343,6 +343,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)
> diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h
> index b3bdb8ddb862..1b57420857e1 100644
> --- a/kernel/trace/trace_probe_tmpl.h
> +++ b/kernel/trace/trace_probe_tmpl.h
> @@ -212,31 +212,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;
> -}
> diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
> index fb58e86dd117..1ff8f87211a6 100644
> --- a/kernel/trace/trace_uprobe.c
> +++ b/kernel/trace/trace_uprobe.c
> @@ -1041,7 +1041,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');
> -- 
> 2.25.1
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-29  8:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-28  7:08 [PATCH v4 1/2] kernel/trace: Introduce trace_probe_print_args and use it in *probes Song Chen
2022-12-29  8:07 ` Masami Hiramatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.