Skip to content

Commit 4564109

Browse files
committed
tracing: Have hist_debug show what function a field uses
When CONFIG_HIST_TRIGGERS_DEBUG is enabled, each trace event has a "hist_debug" file that explains the histogram internal data. This is very useful for debugging histograms. One bit of data that was missing from this file was what function a histogram field uses to process its data. The hist_field structure now has a fn_num that is used by a switch statement in hist_fn_call() to call a function directly (to avoid spectre mitigations). Instead of displaying that number, create a string array that maps to the histogram function enums so that the function for a field may be displayed: ~# cat /sys/kernel/tracing/events/sched/sched_switch/hist_debug [..] hist_data: 0000000043d62762 n_vals: 2 n_keys: 1 n_fields: 3 val fields: hist_data->fields[0]: flags: VAL: HIST_FIELD_FL_HITCOUNT type: u64 size: 8 is_signed: 0 function: hist_field_counter() hist_data->fields[1]: flags: HIST_FIELD_FL_VAR var.name: __arg_3921_2 var.idx (into tracing_map_elt.vars[]): 0 type: unsigned long[] size: 128 is_signed: 0 function: hist_field_nop() key fields: hist_data->fields[2]: flags: HIST_FIELD_FL_KEY ftrace_event_field name: prev_pid type: pid_t size: 8 is_signed: 1 function: hist_field_s32() The "function:" field above is added. Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Link: https://patch.msgid.link/20260122203822.58df4d80@gandalf.local.home Reviewed-by: Tom Zanussi <zanussi@kernel.org> Tested-by: Tom Zanussi <zanussi@kernel.org> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 6bdf073 commit 4564109

1 file changed

Lines changed: 44 additions & 31 deletions

File tree

kernel/trace/trace_events_hist.c

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -105,38 +105,44 @@ enum field_op_id {
105105
FIELD_OP_MULT,
106106
};
107107

108+
#define FIELD_FUNCS \
109+
C(NOP, "nop"), \
110+
C(VAR_REF, "var_ref"), \
111+
C(COUNTER, "counter"), \
112+
C(CONST, "const"), \
113+
C(LOG2, "log2"), \
114+
C(BUCKET, "bucket"), \
115+
C(TIMESTAMP, "timestamp"), \
116+
C(CPU, "cpu"), \
117+
C(COMM, "comm"), \
118+
C(STRING, "string"), \
119+
C(DYNSTRING, "dynstring"), \
120+
C(RELDYNSTRING, "reldynstring"), \
121+
C(PSTRING, "pstring"), \
122+
C(S64, "s64"), \
123+
C(U64, "u64"), \
124+
C(S32, "s32"), \
125+
C(U32, "u32"), \
126+
C(S16, "s16"), \
127+
C(U16, "u16"), \
128+
C(S8, "s8"), \
129+
C(U8, "u8"), \
130+
C(UMINUS, "uminus"), \
131+
C(MINUS, "minus"), \
132+
C(PLUS, "plus"), \
133+
C(DIV, "div"), \
134+
C(MULT, "mult"), \
135+
C(DIV_POWER2, "div_power2"), \
136+
C(DIV_NOT_POWER2, "div_not_power2"), \
137+
C(DIV_MULT_SHIFT, "div_mult_shift"), \
138+
C(EXECNAME, "execname"), \
139+
C(STACK, "stack"),
140+
141+
#undef C
142+
#define C(a, b) HIST_FIELD_FN_##a
143+
108144
enum hist_field_fn {
109-
HIST_FIELD_FN_NOP,
110-
HIST_FIELD_FN_VAR_REF,
111-
HIST_FIELD_FN_COUNTER,
112-
HIST_FIELD_FN_CONST,
113-
HIST_FIELD_FN_LOG2,
114-
HIST_FIELD_FN_BUCKET,
115-
HIST_FIELD_FN_TIMESTAMP,
116-
HIST_FIELD_FN_CPU,
117-
HIST_FIELD_FN_COMM,
118-
HIST_FIELD_FN_STRING,
119-
HIST_FIELD_FN_DYNSTRING,
120-
HIST_FIELD_FN_RELDYNSTRING,
121-
HIST_FIELD_FN_PSTRING,
122-
HIST_FIELD_FN_S64,
123-
HIST_FIELD_FN_U64,
124-
HIST_FIELD_FN_S32,
125-
HIST_FIELD_FN_U32,
126-
HIST_FIELD_FN_S16,
127-
HIST_FIELD_FN_U16,
128-
HIST_FIELD_FN_S8,
129-
HIST_FIELD_FN_U8,
130-
HIST_FIELD_FN_UMINUS,
131-
HIST_FIELD_FN_MINUS,
132-
HIST_FIELD_FN_PLUS,
133-
HIST_FIELD_FN_DIV,
134-
HIST_FIELD_FN_MULT,
135-
HIST_FIELD_FN_DIV_POWER2,
136-
HIST_FIELD_FN_DIV_NOT_POWER2,
137-
HIST_FIELD_FN_DIV_MULT_SHIFT,
138-
HIST_FIELD_FN_EXECNAME,
139-
HIST_FIELD_FN_STACK,
145+
FIELD_FUNCS
140146
};
141147

142148
/*
@@ -5854,6 +5860,12 @@ const struct file_operations event_hist_fops = {
58545860
};
58555861

58565862
#ifdef CONFIG_HIST_TRIGGERS_DEBUG
5863+
5864+
#undef C
5865+
#define C(a, b) b
5866+
5867+
static const char * const field_funcs[] = { FIELD_FUNCS };
5868+
58575869
static void hist_field_debug_show_flags(struct seq_file *m,
58585870
unsigned long flags)
58595871
{
@@ -5918,6 +5930,7 @@ static int hist_field_debug_show(struct seq_file *m,
59185930
seq_printf(m, " type: %s\n", field->type);
59195931
seq_printf(m, " size: %u\n", field->size);
59205932
seq_printf(m, " is_signed: %u\n", field->is_signed);
5933+
seq_printf(m, " function: hist_field_%s()\n", field_funcs[field->fn_num]);
59215934

59225935
return 0;
59235936
}

0 commit comments

Comments
 (0)