Skip to content

Commit 196b638

Browse files
Song Chenmhiramat
authored andcommitted
kernel/trace: Introduce trace_probe_print_args and use it in *probes
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/[email protected]/ Signed-off-by: Song Chen <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
1 parent c96abae commit 196b638

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

kernel/trace/trace_eprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ print_eprobe_event(struct trace_iterator *iter, int flags,
311311

312312
trace_seq_putc(s, ')');
313313

314-
if (print_probe_args(s, tp->args, tp->nr_args,
314+
if (trace_probe_print_args(s, tp->args, tp->nr_args,
315315
(u8 *)&field[1], field) < 0)
316316
goto out;
317317

kernel/trace/trace_kprobe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
14241424

14251425
trace_seq_putc(s, ')');
14261426

1427-
if (print_probe_args(s, tp->args, tp->nr_args,
1427+
if (trace_probe_print_args(s, tp->args, tp->nr_args,
14281428
(u8 *)&field[1], field) < 0)
14291429
goto out;
14301430

@@ -1459,7 +1459,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
14591459

14601460
trace_seq_putc(s, ')');
14611461

1462-
if (print_probe_args(s, tp->args, tp->nr_args,
1462+
if (trace_probe_print_args(s, tp->args, tp->nr_args,
14631463
(u8 *)&field[1], field) < 0)
14641464
goto out;
14651465

kernel/trace/trace_probe.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,3 +1239,30 @@ int trace_probe_create(const char *raw_command, int (*createfn)(int, const char
12391239

12401240
return ret;
12411241
}
1242+
1243+
int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
1244+
u8 *data, void *field)
1245+
{
1246+
void *p;
1247+
int i, j;
1248+
1249+
for (i = 0; i < nr_args; i++) {
1250+
struct probe_arg *a = args + i;
1251+
1252+
trace_seq_printf(s, " %s=", a->name);
1253+
if (likely(!a->count)) {
1254+
if (!a->type->print(s, data + a->offset, field))
1255+
return -ENOMEM;
1256+
continue;
1257+
}
1258+
trace_seq_putc(s, '{');
1259+
p = data + a->offset;
1260+
for (j = 0; j < a->count; j++) {
1261+
if (!a->type->print(s, p, field))
1262+
return -ENOMEM;
1263+
trace_seq_putc(s, j == a->count - 1 ? '}' : ',');
1264+
p += a->type->size;
1265+
}
1266+
}
1267+
return 0;
1268+
}

kernel/trace/trace_probe.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b);
349349
bool trace_probe_match_command_args(struct trace_probe *tp,
350350
int argc, const char **argv);
351351
int trace_probe_create(const char *raw_command, int (*createfn)(int, const char **));
352+
int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
353+
u8 *data, void *field);
352354

353355
#define trace_probe_for_each_link(pos, tp) \
354356
list_for_each_entry(pos, &(tp)->event->files, list)

kernel/trace/trace_probe_tmpl.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -253,31 +253,3 @@ store_trace_args(void *data, struct trace_probe *tp, void *rec,
253253
}
254254
}
255255
}
256-
257-
static inline int
258-
print_probe_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
259-
u8 *data, void *field)
260-
{
261-
void *p;
262-
int i, j;
263-
264-
for (i = 0; i < nr_args; i++) {
265-
struct probe_arg *a = args + i;
266-
267-
trace_seq_printf(s, " %s=", a->name);
268-
if (likely(!a->count)) {
269-
if (!a->type->print(s, data + a->offset, field))
270-
return -ENOMEM;
271-
continue;
272-
}
273-
trace_seq_putc(s, '{');
274-
p = data + a->offset;
275-
for (j = 0; j < a->count; j++) {
276-
if (!a->type->print(s, p, field))
277-
return -ENOMEM;
278-
trace_seq_putc(s, j == a->count - 1 ? '}' : ',');
279-
p += a->type->size;
280-
}
281-
}
282-
return 0;
283-
}

kernel/trace/trace_uprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e
10421042
data = DATAOF_TRACE_ENTRY(entry, false);
10431043
}
10441044

1045-
if (print_probe_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0)
1045+
if (trace_probe_print_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0)
10461046
goto out;
10471047

10481048
trace_seq_putc(s, '\n');

0 commit comments

Comments
 (0)