Skip to content

Commit 0c4a6b4

Browse files
tzanussirostedt
authored andcommitted
tracing: Add hist trigger 'hex' modifier for displaying numeric fields
Allow users to have numeric fields displayed as hex values in the output by appending '.hex' to field names: # echo hist:keys=aaa,bbb.hex:vals=ccc.hex ... \ [ if filter] > event/trigger Link: http://lkml.kernel.org/r/67bd431edda2af5798d7694818f7e8d71b6b3463.1457029949.git.tom.zanussi@linux.intel.com Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Reviewed-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent e86ae9b commit 0c4a6b4

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

kernel/trace/trace.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3852,7 +3852,10 @@ static const char readme_msg[] =
38523852
"\t used to specify more or fewer than the default 2048 entries\n"
38533853
"\t for the hashtable size.\n\n"
38543854
"\t Reading the 'hist' file for the event will dump the hash\n"
3855-
"\t table in its entirety to stdout.\n\n"
3855+
"\t table in its entirety to stdout. The default format used to\n"
3856+
"\t display a given field can be modified by appending any of the\n"
3857+
"\t following modifiers to the field name, as applicable:\n\n"
3858+
"\t .hex display a number as a hex value\n\n"
38563859
"\t The 'pause' parameter can be used to pause an existing hist\n"
38573860
"\t trigger or to start a hist trigger but not log any events\n"
38583861
"\t until told to do so. 'continue' can be used to start or\n"

kernel/trace/trace_events_hist.c

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ enum hist_field_flags {
8080
HIST_FIELD_FL_HITCOUNT = 1,
8181
HIST_FIELD_FL_KEY = 2,
8282
HIST_FIELD_FL_STRING = 4,
83+
HIST_FIELD_FL_HEX = 8,
8384
};
8485

8586
struct hist_trigger_attrs {
@@ -303,11 +304,23 @@ static int create_val_field(struct hist_trigger_data *hist_data,
303304
{
304305
struct ftrace_event_field *field = NULL;
305306
unsigned long flags = 0;
307+
char *field_name;
306308
int ret = 0;
307309

308310
if (WARN_ON(val_idx >= TRACING_MAP_VALS_MAX))
309311
return -EINVAL;
310-
field = trace_find_event_field(file->event_call, field_str);
312+
313+
field_name = strsep(&field_str, ".");
314+
if (field_str) {
315+
if (strcmp(field_str, "hex") == 0)
316+
flags |= HIST_FIELD_FL_HEX;
317+
else {
318+
ret = -EINVAL;
319+
goto out;
320+
}
321+
}
322+
323+
field = trace_find_event_field(file->event_call, field_name);
311324
if (!field) {
312325
ret = -EINVAL;
313326
goto out;
@@ -372,14 +385,25 @@ static int create_key_field(struct hist_trigger_data *hist_data,
372385
struct ftrace_event_field *field = NULL;
373386
unsigned long flags = 0;
374387
unsigned int key_size;
388+
char *field_name;
375389
int ret = 0;
376390

377391
if (WARN_ON(key_idx >= TRACING_MAP_FIELDS_MAX))
378392
return -EINVAL;
379393

380394
flags |= HIST_FIELD_FL_KEY;
381395

382-
field = trace_find_event_field(file->event_call, field_str);
396+
field_name = strsep(&field_str, ".");
397+
if (field_str) {
398+
if (strcmp(field_str, "hex") == 0)
399+
flags |= HIST_FIELD_FL_HEX;
400+
else {
401+
ret = -EINVAL;
402+
goto out;
403+
}
404+
}
405+
406+
field = trace_find_event_field(file->event_call, field_name);
383407
if (!field) {
384408
ret = -EINVAL;
385409
goto out;
@@ -713,7 +737,11 @@ hist_trigger_entry_print(struct seq_file *m,
713737
if (i > hist_data->n_vals)
714738
seq_puts(m, ", ");
715739

716-
if (key_field->flags & HIST_FIELD_FL_STRING) {
740+
if (key_field->flags & HIST_FIELD_FL_HEX) {
741+
uval = *(u64 *)(key + key_field->offset);
742+
seq_printf(m, "%s: %llx",
743+
key_field->field->name, uval);
744+
} else if (key_field->flags & HIST_FIELD_FL_STRING) {
717745
seq_printf(m, "%s: %-50s", key_field->field->name,
718746
(char *)(key + key_field->offset));
719747
} else {
@@ -729,9 +757,15 @@ hist_trigger_entry_print(struct seq_file *m,
729757
tracing_map_read_sum(elt, HITCOUNT_IDX));
730758

731759
for (i = 1; i < hist_data->n_vals; i++) {
732-
seq_printf(m, " %s: %10llu",
733-
hist_data->fields[i]->field->name,
734-
tracing_map_read_sum(elt, i));
760+
if (hist_data->fields[i]->flags & HIST_FIELD_FL_HEX) {
761+
seq_printf(m, " %s: %10llx",
762+
hist_data->fields[i]->field->name,
763+
tracing_map_read_sum(elt, i));
764+
} else {
765+
seq_printf(m, " %s: %10llu",
766+
hist_data->fields[i]->field->name,
767+
tracing_map_read_sum(elt, i));
768+
}
735769
}
736770

737771
seq_puts(m, "\n");
@@ -816,9 +850,25 @@ const struct file_operations event_hist_fops = {
816850
.release = single_release,
817851
};
818852

853+
static const char *get_hist_field_flags(struct hist_field *hist_field)
854+
{
855+
const char *flags_str = NULL;
856+
857+
if (hist_field->flags & HIST_FIELD_FL_HEX)
858+
flags_str = "hex";
859+
860+
return flags_str;
861+
}
862+
819863
static void hist_field_print(struct seq_file *m, struct hist_field *hist_field)
820864
{
821865
seq_printf(m, "%s", hist_field->field->name);
866+
if (hist_field->flags) {
867+
const char *flags_str = get_hist_field_flags(hist_field);
868+
869+
if (flags_str)
870+
seq_printf(m, ".%s", flags_str);
871+
}
822872
}
823873

824874
static int event_hist_trigger_print(struct seq_file *m,

0 commit comments

Comments
 (0)