Skip to content

Commit

Permalink
tools lib traceevent: Add filter on task CPU id
Browse files Browse the repository at this point in the history
Add a 'CPU' special field to allow the filter in trace-cmd report to
filter on the task's CPU.

By adding a special field 'CPU' (all caps) the user can now filter out
tasks based on which CPU they are on. This is useful when filtering out
(or in) a bunch of threads.

  -F 'CPU == 0'

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20160712093306.5b058103@gandalf.local.home
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Steven Rostedt authored and Arnaldo Carvalho de Melo committed Jul 12, 2016
1 parent 9881d7d commit 6d248fb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tools/lib/traceevent/parse-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@
#include "event-utils.h"

#define COMM "COMM"
#define CPU "CPU"

static struct format_field comm = {
.name = "COMM",
};

static struct format_field cpu = {
.name = "CPU",
};

struct event_list {
struct event_list *next;
struct event_format *event;
Expand Down Expand Up @@ -382,14 +387,17 @@ create_arg_item(struct event_format *event, const char *token,
/* Consider this a field */
field = pevent_find_any_field(event, token);
if (!field) {
if (strcmp(token, COMM) != 0) {
/* If token is 'COMM' or 'CPU' then it is special */
if (strcmp(token, COMM) == 0) {
field = &comm;
} else if (strcmp(token, CPU) == 0) {
field = &cpu;
} else {
/* not a field, Make it false */
arg->type = FILTER_ARG_BOOLEAN;
arg->boolean.value = FILTER_FALSE;
break;
}
/* If token is 'COMM' then it is special */
field = &comm;
}
arg->type = FILTER_ARG_FIELD;
arg->field.field = field;
Expand Down Expand Up @@ -1718,6 +1726,10 @@ get_value(struct event_format *event,
return (unsigned long)name;
}

/* Handle our dummy "cpu" field */
if (field == &cpu)
return record->cpu;

pevent_read_number_field(field, record->data, &val);

if (!(field->flags & FIELD_IS_SIGNED))
Expand Down

0 comments on commit 6d248fb

Please sign in to comment.