Skip to content

Commit 8b7622b

Browse files
tzanussirostedt
authored andcommitted
tracing: Add cpu field for hist triggers
A common key to use in a histogram is the cpuid - add a new cpu 'synthetic' field named 'cpu' for that purpose. Link: http://lkml.kernel.org/r/89537645bfc957e0d76e2cacf5f0ada88691a6cc.1516069914.git.tom.zanussi@linux.intel.com Signed-off-by: Tom Zanussi <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent ec5ce09 commit 8b7622b

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

Documentation/trace/histogram.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@
172172
The examples below provide a more concrete illustration of the
173173
concepts and typical usage patterns discussed above.
174174

175+
'special' event fields
176+
------------------------
177+
178+
There are a number of 'special event fields' available for use as
179+
keys or values in a hist trigger. These look like and behave as if
180+
they were actual event fields, but aren't really part of the event's
181+
field definition or format file. They are however available for any
182+
event, and can be used anywhere an actual event field could be.
183+
They are:
184+
185+
common_timestamp u64 - timestamp (from ring buffer) associated
186+
with the event, in nanoseconds. May be
187+
modified by .usecs to have timestamps
188+
interpreted as microseconds.
189+
cpu int - the cpu on which the event occurred.
175190

176191
6.2 'hist' trigger examples
177192
---------------------------

kernel/trace/trace_events_hist.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ enum hist_field_flags {
227227
HIST_FIELD_FL_VAR = 1 << 12,
228228
HIST_FIELD_FL_EXPR = 1 << 13,
229229
HIST_FIELD_FL_VAR_REF = 1 << 14,
230+
HIST_FIELD_FL_CPU = 1 << 15,
230231
};
231232

232233
struct var_defs {
@@ -1164,6 +1165,16 @@ static u64 hist_field_timestamp(struct hist_field *hist_field,
11641165
return ts;
11651166
}
11661167

1168+
static u64 hist_field_cpu(struct hist_field *hist_field,
1169+
struct tracing_map_elt *elt,
1170+
struct ring_buffer_event *rbe,
1171+
void *event)
1172+
{
1173+
int cpu = smp_processor_id();
1174+
1175+
return cpu;
1176+
}
1177+
11671178
static struct hist_field *
11681179
check_field_for_var_ref(struct hist_field *hist_field,
11691180
struct hist_trigger_data *var_data,
@@ -1602,6 +1613,8 @@ static const char *hist_field_name(struct hist_field *field,
16021613
field_name = hist_field_name(field->operands[0], ++level);
16031614
else if (field->flags & HIST_FIELD_FL_TIMESTAMP)
16041615
field_name = "common_timestamp";
1616+
else if (field->flags & HIST_FIELD_FL_CPU)
1617+
field_name = "cpu";
16051618
else if (field->flags & HIST_FIELD_FL_EXPR ||
16061619
field->flags & HIST_FIELD_FL_VAR_REF) {
16071620
if (field->system) {
@@ -2109,6 +2122,15 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
21092122
goto out;
21102123
}
21112124

2125+
if (flags & HIST_FIELD_FL_CPU) {
2126+
hist_field->fn = hist_field_cpu;
2127+
hist_field->size = sizeof(int);
2128+
hist_field->type = kstrdup("unsigned int", GFP_KERNEL);
2129+
if (!hist_field->type)
2130+
goto free;
2131+
goto out;
2132+
}
2133+
21122134
if (WARN_ON_ONCE(!field))
21132135
goto out;
21142136

@@ -2345,7 +2367,9 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file,
23452367
hist_data->enable_timestamps = true;
23462368
if (*flags & HIST_FIELD_FL_TIMESTAMP_USECS)
23472369
hist_data->attrs->ts_in_usecs = true;
2348-
} else {
2370+
} else if (strcmp(field_name, "cpu") == 0)
2371+
*flags |= HIST_FIELD_FL_CPU;
2372+
else {
23492373
field = trace_find_event_field(file->event_call, field_name);
23502374
if (!field || !field->size) {
23512375
field = ERR_PTR(-EINVAL);
@@ -4619,6 +4643,8 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field)
46194643

46204644
if (hist_field->flags & HIST_FIELD_FL_TIMESTAMP)
46214645
seq_puts(m, "common_timestamp");
4646+
else if (hist_field->flags & HIST_FIELD_FL_CPU)
4647+
seq_puts(m, "cpu");
46224648
else if (field_name) {
46234649
if (hist_field->flags & HIST_FIELD_FL_VAR_REF)
46244650
seq_putc(m, '$');

0 commit comments

Comments
 (0)