Skip to content

Commit ccf47f5

Browse files
mhiramatrostedt
authored andcommitted
tracing: Add nohitcount option for suppressing display of raw hitcount
Add 'nohitcount' ('NOHC' for short) option for suppressing display of the raw hitcount column in the histogram. Note that you must specify at least one value except raw 'hitcount' when you specify this nohitcount option. # cd /sys/kernel/debug/tracing/ # echo hist:keys=pid:vals=runtime.percent,runtime.graph:sort=pid:NOHC > \ events/sched/sched_stat_runtime/trigger # sleep 10 # cat events/sched/sched_stat_runtime/hist # event histogram # # trigger info: hist:keys=pid:vals=runtime.percent,runtime.graph:sort=pid:size=2048:nohitcount [active] # { pid: 8 } runtime (%): 3.02 runtime: # { pid: 14 } runtime (%): 2.25 runtime: { pid: 16 } runtime (%): 2.25 runtime: { pid: 26 } runtime (%): 0.17 runtime: { pid: 61 } runtime (%): 11.52 runtime: #### { pid: 67 } runtime (%): 1.56 runtime: { pid: 68 } runtime (%): 0.84 runtime: { pid: 76 } runtime (%): 0.92 runtime: { pid: 117 } runtime (%): 2.50 runtime: # { pid: 146 } runtime (%): 49.88 runtime: #################### { pid: 157 } runtime (%): 16.63 runtime: ###### { pid: 158 } runtime (%): 8.38 runtime: ### Link: https://lore.kernel.org/linux-trace-kernel/166610814787.56030.4980636083486339906.stgit@devnote2 Signed-off-by: Masami Hiramatsu (Google) <[email protected]> Reviewed-by: Tom Zanussi <[email protected]> Tested-by: Tom Zanussi <[email protected]>
1 parent a2c5425 commit ccf47f5

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

kernel/trace/trace.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5678,6 +5678,7 @@ static const char readme_msg[] =
56785678
"\t [:size=#entries]\n"
56795679
"\t [:pause][:continue][:clear]\n"
56805680
"\t [:name=histname1]\n"
5681+
"\t [:nohitcount]\n"
56815682
"\t [:<handler>.<action>]\n"
56825683
"\t [if <filter>]\n\n"
56835684
"\t Note, special fields can be used as well:\n"
@@ -5734,6 +5735,8 @@ static const char readme_msg[] =
57345735
"\t The 'clear' parameter will clear the contents of a running\n"
57355736
"\t hist trigger and leave its current paused/active state\n"
57365737
"\t unchanged.\n\n"
5738+
"\t The 'nohitcount' (or NOHC) parameter will suppress display of\n"
5739+
"\t raw hitcount in the histogram.\n\n"
57375740
"\t The enable_hist and disable_hist triggers can be used to\n"
57385741
"\t have one event conditionally start and stop another event's\n"
57395742
"\t already-attached hist trigger. The syntax is analogous to\n"

kernel/trace/trace_events_hist.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
C(INVALID_STR_OPERAND, "String type can not be an operand in expression"), \
7070
C(EXPECT_NUMBER, "Expecting numeric literal"), \
7171
C(UNARY_MINUS_SUBEXPR, "Unary minus not supported in sub-expressions"), \
72-
C(DIVISION_BY_ZERO, "Division by zero"),
72+
C(DIVISION_BY_ZERO, "Division by zero"), \
73+
C(NEED_NOHC_VAL, "Non-hitcount value is required for 'nohitcount'"),
7374

7475
#undef C
7576
#define C(a, b) HIST_ERR_##a
@@ -526,6 +527,7 @@ struct hist_trigger_attrs {
526527
bool cont;
527528
bool clear;
528529
bool ts_in_usecs;
530+
bool no_hitcount;
529531
unsigned int map_bits;
530532

531533
char *assignment_str[TRACING_MAP_VARS_MAX];
@@ -1550,7 +1552,10 @@ parse_hist_trigger_attrs(struct trace_array *tr, char *trigger_str)
15501552
ret = parse_assignment(tr, str, attrs);
15511553
if (ret)
15521554
goto free;
1553-
} else if (strcmp(str, "pause") == 0)
1555+
} else if (strcmp(str, "nohitcount") == 0 ||
1556+
strcmp(str, "NOHC") == 0)
1557+
attrs->no_hitcount = true;
1558+
else if (strcmp(str, "pause") == 0)
15541559
attrs->pause = true;
15551560
else if ((strcmp(str, "cont") == 0) ||
15561561
(strcmp(str, "continue") == 0))
@@ -4377,6 +4382,12 @@ static int create_val_fields(struct hist_trigger_data *hist_data,
43774382
if (fields_str && (strcmp(fields_str, "hitcount") != 0))
43784383
ret = -EINVAL;
43794384
out:
4385+
/* There is only raw hitcount but nohitcount suppresses it. */
4386+
if (j == 1 && hist_data->attrs->no_hitcount) {
4387+
hist_err(hist_data->event_file->tr, HIST_ERR_NEED_NOHC_VAL, 0);
4388+
ret = -ENOENT;
4389+
}
4390+
43804391
return ret;
43814392
}
43824393

@@ -5388,13 +5399,13 @@ static void hist_trigger_entry_print(struct seq_file *m,
53885399

53895400
hist_trigger_print_key(m, hist_data, key, elt);
53905401

5391-
/* At first, show the raw hitcount always */
5392-
hist_trigger_print_val(m, i, "hitcount", 0, stats, elt);
5402+
/* At first, show the raw hitcount if !nohitcount */
5403+
if (!hist_data->attrs->no_hitcount)
5404+
hist_trigger_print_val(m, i, "hitcount", 0, stats, elt);
53935405

53945406
for (i = 1; i < hist_data->n_vals; i++) {
53955407
field_name = hist_field_name(hist_data->fields[i], 0);
53965408
flags = hist_data->fields[i]->flags;
5397-
53985409
if (flags & HIST_FIELD_FL_VAR || flags & HIST_FIELD_FL_EXPR)
53995410
continue;
54005411

@@ -5839,6 +5850,7 @@ static int event_hist_trigger_print(struct seq_file *m,
58395850
struct hist_trigger_data *hist_data = data->private_data;
58405851
struct hist_field *field;
58415852
bool have_var = false;
5853+
bool show_val = false;
58425854
unsigned int i;
58435855

58445856
seq_puts(m, HIST_PREFIX);
@@ -5869,12 +5881,16 @@ static int event_hist_trigger_print(struct seq_file *m,
58695881
continue;
58705882
}
58715883

5872-
if (i == HITCOUNT_IDX)
5884+
if (i == HITCOUNT_IDX) {
5885+
if (hist_data->attrs->no_hitcount)
5886+
continue;
58735887
seq_puts(m, "hitcount");
5874-
else {
5875-
seq_puts(m, ",");
5888+
} else {
5889+
if (show_val)
5890+
seq_puts(m, ",");
58765891
hist_field_print(m, field);
58775892
}
5893+
show_val = true;
58785894
}
58795895

58805896
if (have_var) {
@@ -5925,6 +5941,8 @@ static int event_hist_trigger_print(struct seq_file *m,
59255941
seq_printf(m, ":size=%u", (1 << hist_data->map->map_bits));
59265942
if (hist_data->enable_timestamps)
59275943
seq_printf(m, ":clock=%s", hist_data->attrs->clock);
5944+
if (hist_data->attrs->no_hitcount)
5945+
seq_puts(m, ":nohitcount");
59285946

59295947
print_actions_spec(m, hist_data);
59305948

0 commit comments

Comments
 (0)