Skip to content

Commit dd6ae6d

Browse files
committed
tracing: Add __string_len() example
There's no example code that uses __string_len(), and since the sample code is used for testing the event logic, add a use case. Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent c759e60 commit dd6ae6d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

samples/trace_events/trace-events-sample.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ TRACE_EVENT(foo_bar,
303303
__bitmask( cpus, num_possible_cpus() )
304304
__cpumask( cpum )
305305
__vstring( vstr, fmt, va )
306+
__string_len( lstr, foo, bar / 2 < strlen(foo) ? bar / 2 : strlen(foo) )
306307
),
307308

308309
TP_fast_assign(
@@ -311,12 +312,13 @@ TRACE_EVENT(foo_bar,
311312
memcpy(__get_dynamic_array(list), lst,
312313
__length_of(lst) * sizeof(int));
313314
__assign_str(str, string);
315+
__assign_str(lstr, foo);
314316
__assign_vstr(vstr, fmt, va);
315317
__assign_bitmask(cpus, cpumask_bits(mask), num_possible_cpus());
316318
__assign_cpumask(cpum, cpumask_bits(mask));
317319
),
318320

319-
TP_printk("foo %s %d %s %s %s %s (%s) (%s) %s", __entry->foo, __entry->bar,
321+
TP_printk("foo %s %d %s %s %s %s %s (%s) (%s) %s", __entry->foo, __entry->bar,
320322

321323
/*
322324
* Notice here the use of some helper functions. This includes:
@@ -360,7 +362,8 @@ TRACE_EVENT(foo_bar,
360362
__print_array(__get_dynamic_array(list),
361363
__get_dynamic_array_len(list) / sizeof(int),
362364
sizeof(int)),
363-
__get_str(str), __get_bitmask(cpus), __get_cpumask(cpum),
365+
__get_str(str), __get_str(lstr),
366+
__get_bitmask(cpus), __get_cpumask(cpum),
364367
__get_str(vstr))
365368
);
366369

0 commit comments

Comments
 (0)