2009-03-22 09:31:04 +01:00
|
|
|
/*
|
|
|
|
* trace_events_filter - generic event filtering
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Tom Zanussi <tzanussi@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ctype.h>
|
2009-04-17 07:27:08 +02:00
|
|
|
#include <linux/mutex.h>
|
2009-10-15 05:21:42 +02:00
|
|
|
#include <linux/perf_event.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2009-03-22 09:31:04 +01:00
|
|
|
|
|
|
|
#include "trace.h"
|
2009-03-24 08:14:31 +01:00
|
|
|
#include "trace_output.h"
|
2009-03-22 09:31:04 +01:00
|
|
|
|
2011-11-02 21:46:46 +01:00
|
|
|
#define DEFAULT_SYS_FILTER_MESSAGE \
|
|
|
|
"### global filter ###\n" \
|
|
|
|
"# Use this to set filters for multiple events.\n" \
|
|
|
|
"# Only events with the given fields will be affected.\n" \
|
|
|
|
"# If no events are modified, an error message will be displayed here"
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
enum filter_op_ids
|
2009-03-22 09:31:04 +01:00
|
|
|
{
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
OP_OR,
|
|
|
|
OP_AND,
|
2009-10-15 05:21:12 +02:00
|
|
|
OP_GLOB,
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
OP_NE,
|
|
|
|
OP_EQ,
|
|
|
|
OP_LT,
|
|
|
|
OP_LE,
|
|
|
|
OP_GT,
|
|
|
|
OP_GE,
|
tracing: Add binary '&' filter for events
There are some cases when filtering on a set flag of a field of a tracepoint
is useful. But currently the only filtering commands for numbered fields
is ==, !=, <, <=, >, >=. This does not help when you just want to trace if
a specific flag is set. For example:
> # sudo trace-cmd record -e brcmfmac:brcmf_dbg -f 'level & 0x40000'
> disable all
> enable brcmfmac:brcmf_dbg
> path = /sys/kernel/debug/tracing/events/brcmfmac/brcmf_dbg/enable
> (level & 0x40000)
> ^
> parse_error: Invalid operator
>
When trying to trace brcmf_dbg when level has its 1 << 18 bit set, the
filter fails to perform.
By allowing a binary '&' operation, this gives the user the ability to
test a bit.
Note, a binary '|' is not added, as it doesn't make sense as fields must
be compared to constants (for now), and ORing a constant will always return
true.
Link: http://lkml.kernel.org/r/1371057385.9844.261.camel@gandalf.local.home
Suggested-by: Arend van Spriel <arend@broadcom.com>
Tested-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-06-12 19:16:25 +02:00
|
|
|
OP_BAND,
|
2014-12-02 17:55:36 +01:00
|
|
|
OP_NOT,
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
OP_NONE,
|
|
|
|
OP_OPEN_PAREN,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct filter_op {
|
|
|
|
int id;
|
|
|
|
char *string;
|
|
|
|
int precedence;
|
|
|
|
};
|
|
|
|
|
tracing: Add binary '&' filter for events
There are some cases when filtering on a set flag of a field of a tracepoint
is useful. But currently the only filtering commands for numbered fields
is ==, !=, <, <=, >, >=. This does not help when you just want to trace if
a specific flag is set. For example:
> # sudo trace-cmd record -e brcmfmac:brcmf_dbg -f 'level & 0x40000'
> disable all
> enable brcmfmac:brcmf_dbg
> path = /sys/kernel/debug/tracing/events/brcmfmac/brcmf_dbg/enable
> (level & 0x40000)
> ^
> parse_error: Invalid operator
>
When trying to trace brcmf_dbg when level has its 1 << 18 bit set, the
filter fails to perform.
By allowing a binary '&' operation, this gives the user the ability to
test a bit.
Note, a binary '|' is not added, as it doesn't make sense as fields must
be compared to constants (for now), and ORing a constant will always return
true.
Link: http://lkml.kernel.org/r/1371057385.9844.261.camel@gandalf.local.home
Suggested-by: Arend van Spriel <arend@broadcom.com>
Tested-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-06-12 19:16:25 +02:00
|
|
|
/* Order must be the same as enum filter_op_ids above */
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
static struct filter_op filter_ops[] = {
|
2009-10-15 05:21:12 +02:00
|
|
|
{ OP_OR, "||", 1 },
|
|
|
|
{ OP_AND, "&&", 2 },
|
|
|
|
{ OP_GLOB, "~", 4 },
|
|
|
|
{ OP_NE, "!=", 4 },
|
|
|
|
{ OP_EQ, "==", 4 },
|
|
|
|
{ OP_LT, "<", 5 },
|
|
|
|
{ OP_LE, "<=", 5 },
|
|
|
|
{ OP_GT, ">", 5 },
|
|
|
|
{ OP_GE, ">=", 5 },
|
tracing: Add binary '&' filter for events
There are some cases when filtering on a set flag of a field of a tracepoint
is useful. But currently the only filtering commands for numbered fields
is ==, !=, <, <=, >, >=. This does not help when you just want to trace if
a specific flag is set. For example:
> # sudo trace-cmd record -e brcmfmac:brcmf_dbg -f 'level & 0x40000'
> disable all
> enable brcmfmac:brcmf_dbg
> path = /sys/kernel/debug/tracing/events/brcmfmac/brcmf_dbg/enable
> (level & 0x40000)
> ^
> parse_error: Invalid operator
>
When trying to trace brcmf_dbg when level has its 1 << 18 bit set, the
filter fails to perform.
By allowing a binary '&' operation, this gives the user the ability to
test a bit.
Note, a binary '|' is not added, as it doesn't make sense as fields must
be compared to constants (for now), and ORing a constant will always return
true.
Link: http://lkml.kernel.org/r/1371057385.9844.261.camel@gandalf.local.home
Suggested-by: Arend van Spriel <arend@broadcom.com>
Tested-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-06-12 19:16:25 +02:00
|
|
|
{ OP_BAND, "&", 6 },
|
2014-12-02 17:55:36 +01:00
|
|
|
{ OP_NOT, "!", 6 },
|
2009-10-15 05:21:12 +02:00
|
|
|
{ OP_NONE, "OP_NONE", 0 },
|
|
|
|
{ OP_OPEN_PAREN, "(", 0 },
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FILT_ERR_NONE,
|
|
|
|
FILT_ERR_INVALID_OP,
|
|
|
|
FILT_ERR_UNBALANCED_PAREN,
|
|
|
|
FILT_ERR_TOO_MANY_OPERANDS,
|
|
|
|
FILT_ERR_OPERAND_TOO_LONG,
|
|
|
|
FILT_ERR_FIELD_NOT_FOUND,
|
|
|
|
FILT_ERR_ILLEGAL_FIELD_OP,
|
|
|
|
FILT_ERR_ILLEGAL_INTVAL,
|
|
|
|
FILT_ERR_BAD_SUBSYS_FILTER,
|
|
|
|
FILT_ERR_TOO_MANY_PREDS,
|
|
|
|
FILT_ERR_MISSING_FIELD,
|
|
|
|
FILT_ERR_INVALID_FILTER,
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 15:51:54 +01:00
|
|
|
FILT_ERR_IP_FIELD_ONLY,
|
2014-12-02 17:55:36 +01:00
|
|
|
FILT_ERR_ILLEGAL_NOT_OP,
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static char *err_text[] = {
|
|
|
|
"No error",
|
|
|
|
"Invalid operator",
|
|
|
|
"Unbalanced parens",
|
|
|
|
"Too many operands",
|
|
|
|
"Operand too long",
|
|
|
|
"Field not found",
|
|
|
|
"Illegal operation for field type",
|
|
|
|
"Illegal integer value",
|
|
|
|
"Couldn't find or set field in one of a subsystem's events",
|
|
|
|
"Too many terms in predicate expression",
|
|
|
|
"Missing field name and/or value",
|
|
|
|
"Meaningless filter expression",
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 15:51:54 +01:00
|
|
|
"Only 'ip' field is supported for function trace",
|
2014-12-02 17:55:36 +01:00
|
|
|
"Illegal use of '!'",
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct opstack_op {
|
|
|
|
int op;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct postfix_elt {
|
|
|
|
int op;
|
|
|
|
char *operand;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct filter_parse_state {
|
|
|
|
struct filter_op *ops;
|
|
|
|
struct list_head opstack;
|
|
|
|
struct list_head postfix;
|
|
|
|
int lasterr;
|
|
|
|
int lasterr_pos;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char *string;
|
|
|
|
unsigned int cnt;
|
|
|
|
unsigned int tail;
|
|
|
|
} infix;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char string[MAX_FILTER_STR_VAL];
|
|
|
|
int pos;
|
|
|
|
unsigned int tail;
|
|
|
|
} operand;
|
|
|
|
};
|
|
|
|
|
2011-01-28 04:54:33 +01:00
|
|
|
struct pred_stack {
|
|
|
|
struct filter_pred **preds;
|
|
|
|
int index;
|
|
|
|
};
|
|
|
|
|
2014-12-02 17:55:36 +01:00
|
|
|
/* If not of not match is equal to not of not, then it is a match */
|
2009-09-10 03:34:19 +02:00
|
|
|
#define DEFINE_COMPARISON_PRED(type) \
|
2011-01-28 04:37:09 +01:00
|
|
|
static int filter_pred_##type(struct filter_pred *pred, void *event) \
|
2009-09-10 03:34:19 +02:00
|
|
|
{ \
|
|
|
|
type *addr = (type *)(event + pred->offset); \
|
|
|
|
type val = (type)pred->val; \
|
|
|
|
int match = 0; \
|
|
|
|
\
|
|
|
|
switch (pred->op) { \
|
|
|
|
case OP_LT: \
|
|
|
|
match = (*addr < val); \
|
|
|
|
break; \
|
|
|
|
case OP_LE: \
|
|
|
|
match = (*addr <= val); \
|
|
|
|
break; \
|
|
|
|
case OP_GT: \
|
|
|
|
match = (*addr > val); \
|
|
|
|
break; \
|
|
|
|
case OP_GE: \
|
|
|
|
match = (*addr >= val); \
|
|
|
|
break; \
|
tracing: Add binary '&' filter for events
There are some cases when filtering on a set flag of a field of a tracepoint
is useful. But currently the only filtering commands for numbered fields
is ==, !=, <, <=, >, >=. This does not help when you just want to trace if
a specific flag is set. For example:
> # sudo trace-cmd record -e brcmfmac:brcmf_dbg -f 'level & 0x40000'
> disable all
> enable brcmfmac:brcmf_dbg
> path = /sys/kernel/debug/tracing/events/brcmfmac/brcmf_dbg/enable
> (level & 0x40000)
> ^
> parse_error: Invalid operator
>
When trying to trace brcmf_dbg when level has its 1 << 18 bit set, the
filter fails to perform.
By allowing a binary '&' operation, this gives the user the ability to
test a bit.
Note, a binary '|' is not added, as it doesn't make sense as fields must
be compared to constants (for now), and ORing a constant will always return
true.
Link: http://lkml.kernel.org/r/1371057385.9844.261.camel@gandalf.local.home
Suggested-by: Arend van Spriel <arend@broadcom.com>
Tested-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-06-12 19:16:25 +02:00
|
|
|
case OP_BAND: \
|
|
|
|
match = (*addr & val); \
|
|
|
|
break; \
|
2009-09-10 03:34:19 +02:00
|
|
|
default: \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
\
|
2014-12-02 17:55:36 +01:00
|
|
|
return !!match == !pred->not; \
|
2009-09-10 03:34:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_EQUALITY_PRED(size) \
|
2011-01-28 04:37:09 +01:00
|
|
|
static int filter_pred_##size(struct filter_pred *pred, void *event) \
|
2009-09-10 03:34:19 +02:00
|
|
|
{ \
|
|
|
|
u##size *addr = (u##size *)(event + pred->offset); \
|
|
|
|
u##size val = (u##size)pred->val; \
|
|
|
|
int match; \
|
|
|
|
\
|
|
|
|
match = (val == *addr) ^ pred->not; \
|
|
|
|
\
|
|
|
|
return match; \
|
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
DEFINE_COMPARISON_PRED(s64);
|
|
|
|
DEFINE_COMPARISON_PRED(u64);
|
|
|
|
DEFINE_COMPARISON_PRED(s32);
|
|
|
|
DEFINE_COMPARISON_PRED(u32);
|
|
|
|
DEFINE_COMPARISON_PRED(s16);
|
|
|
|
DEFINE_COMPARISON_PRED(u16);
|
|
|
|
DEFINE_COMPARISON_PRED(s8);
|
|
|
|
DEFINE_COMPARISON_PRED(u8);
|
|
|
|
|
|
|
|
DEFINE_EQUALITY_PRED(64);
|
|
|
|
DEFINE_EQUALITY_PRED(32);
|
|
|
|
DEFINE_EQUALITY_PRED(16);
|
|
|
|
DEFINE_EQUALITY_PRED(8);
|
|
|
|
|
2009-05-03 02:48:52 +02:00
|
|
|
/* Filter predicate for fixed sized arrays of characters */
|
2011-01-28 04:37:09 +01:00
|
|
|
static int filter_pred_string(struct filter_pred *pred, void *event)
|
2009-03-22 09:31:04 +01:00
|
|
|
{
|
|
|
|
char *addr = (char *)(event + pred->offset);
|
|
|
|
int cmp, match;
|
|
|
|
|
2009-09-24 21:10:44 +02:00
|
|
|
cmp = pred->regex.match(addr, &pred->regex, pred->regex.field_len);
|
2009-03-22 09:31:04 +01:00
|
|
|
|
2009-09-24 21:10:44 +02:00
|
|
|
match = cmp ^ pred->not;
|
2009-03-22 09:31:04 +01:00
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2009-08-07 04:33:43 +02:00
|
|
|
/* Filter predicate for char * pointers */
|
2011-01-28 04:37:09 +01:00
|
|
|
static int filter_pred_pchar(struct filter_pred *pred, void *event)
|
2009-08-07 04:33:43 +02:00
|
|
|
{
|
|
|
|
char **addr = (char **)(event + pred->offset);
|
|
|
|
int cmp, match;
|
2010-01-14 03:54:27 +01:00
|
|
|
int len = strlen(*addr) + 1; /* including tailing '\0' */
|
2009-08-07 04:33:43 +02:00
|
|
|
|
2010-01-14 03:54:27 +01:00
|
|
|
cmp = pred->regex.match(*addr, &pred->regex, len);
|
2009-08-07 04:33:43 +02:00
|
|
|
|
2009-09-24 21:10:44 +02:00
|
|
|
match = cmp ^ pred->not;
|
2009-08-07 04:33:43 +02:00
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2009-05-03 02:48:52 +02:00
|
|
|
/*
|
|
|
|
* Filter predicate for dynamic sized arrays of characters.
|
|
|
|
* These are implemented through a list of strings at the end
|
|
|
|
* of the entry.
|
|
|
|
* Also each of these strings have a field in the entry which
|
|
|
|
* contains its offset from the beginning of the entry.
|
|
|
|
* We have then first to get this field, dereference it
|
|
|
|
* and add it to the address of the entry, and at last we have
|
|
|
|
* the address of the string.
|
|
|
|
*/
|
2011-01-28 04:37:09 +01:00
|
|
|
static int filter_pred_strloc(struct filter_pred *pred, void *event)
|
2009-05-03 02:48:52 +02:00
|
|
|
{
|
2009-07-16 04:54:02 +02:00
|
|
|
u32 str_item = *(u32 *)(event + pred->offset);
|
|
|
|
int str_loc = str_item & 0xffff;
|
|
|
|
int str_len = str_item >> 16;
|
2009-05-03 02:48:52 +02:00
|
|
|
char *addr = (char *)(event + str_loc);
|
|
|
|
int cmp, match;
|
|
|
|
|
2009-09-24 21:10:44 +02:00
|
|
|
cmp = pred->regex.match(addr, &pred->regex, str_len);
|
2009-05-03 02:48:52 +02:00
|
|
|
|
2009-09-24 21:10:44 +02:00
|
|
|
match = cmp ^ pred->not;
|
2009-05-03 02:48:52 +02:00
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2011-01-28 04:37:09 +01:00
|
|
|
static int filter_pred_none(struct filter_pred *pred, void *event)
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-14 03:54:40 +01:00
|
|
|
/*
|
|
|
|
* regex_match_foo - Basic regex callbacks
|
|
|
|
*
|
|
|
|
* @str: the string to be searched
|
|
|
|
* @r: the regex structure containing the pattern string
|
|
|
|
* @len: the length of the string to be searched (including '\0')
|
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* - @str might not be NULL-terminated if it's of type DYN_STRING
|
|
|
|
* or STATIC_STRING
|
|
|
|
*/
|
|
|
|
|
2009-09-24 21:10:44 +02:00
|
|
|
static int regex_match_full(char *str, struct regex *r, int len)
|
|
|
|
{
|
|
|
|
if (strncmp(str, r->pattern, len) == 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int regex_match_front(char *str, struct regex *r, int len)
|
|
|
|
{
|
2010-01-14 03:53:21 +01:00
|
|
|
if (strncmp(str, r->pattern, r->len) == 0)
|
2009-09-24 21:10:44 +02:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int regex_match_middle(char *str, struct regex *r, int len)
|
|
|
|
{
|
2010-01-14 03:54:11 +01:00
|
|
|
if (strnstr(str, r->pattern, len))
|
2009-09-24 21:10:44 +02:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int regex_match_end(char *str, struct regex *r, int len)
|
|
|
|
{
|
2010-01-14 03:53:41 +01:00
|
|
|
int strlen = len - 1;
|
2009-09-24 21:10:44 +02:00
|
|
|
|
2010-01-14 03:53:41 +01:00
|
|
|
if (strlen >= r->len &&
|
|
|
|
memcmp(str + strlen - r->len, r->pattern, r->len) == 0)
|
2009-09-24 21:10:44 +02:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-24 21:31:51 +02:00
|
|
|
/**
|
|
|
|
* filter_parse_regex - parse a basic regex
|
|
|
|
* @buff: the raw regex
|
|
|
|
* @len: length of the regex
|
|
|
|
* @search: will point to the beginning of the string to compare
|
|
|
|
* @not: tell whether the match will have to be inverted
|
|
|
|
*
|
|
|
|
* This passes in a buffer containing a regex and this function will
|
2009-09-24 21:10:44 +02:00
|
|
|
* set search to point to the search part of the buffer and
|
|
|
|
* return the type of search it is (see enum above).
|
|
|
|
* This does modify buff.
|
|
|
|
*
|
|
|
|
* Returns enum type.
|
|
|
|
* search returns the pointer to use for comparison.
|
|
|
|
* not returns 1 if buff started with a '!'
|
|
|
|
* 0 otherwise.
|
|
|
|
*/
|
2009-09-24 21:31:51 +02:00
|
|
|
enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not)
|
2009-09-24 21:10:44 +02:00
|
|
|
{
|
|
|
|
int type = MATCH_FULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (buff[0] == '!') {
|
|
|
|
*not = 1;
|
|
|
|
buff++;
|
|
|
|
len--;
|
|
|
|
} else
|
|
|
|
*not = 0;
|
|
|
|
|
|
|
|
*search = buff;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (buff[i] == '*') {
|
|
|
|
if (!i) {
|
|
|
|
*search = buff + 1;
|
|
|
|
type = MATCH_END_ONLY;
|
|
|
|
} else {
|
|
|
|
if (type == MATCH_END_ONLY)
|
|
|
|
type = MATCH_MIDDLE_ONLY;
|
|
|
|
else
|
|
|
|
type = MATCH_FRONT_ONLY;
|
|
|
|
buff[i] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2009-10-15 05:21:12 +02:00
|
|
|
static void filter_build_regex(struct filter_pred *pred)
|
2009-09-24 21:10:44 +02:00
|
|
|
{
|
|
|
|
struct regex *r = &pred->regex;
|
2009-10-15 05:21:12 +02:00
|
|
|
char *search;
|
|
|
|
enum regex_type type = MATCH_FULL;
|
|
|
|
int not = 0;
|
|
|
|
|
|
|
|
if (pred->op == OP_GLOB) {
|
|
|
|
type = filter_parse_regex(r->pattern, r->len, &search, ¬);
|
|
|
|
r->len = strlen(search);
|
|
|
|
memmove(r->pattern, search, r->len+1);
|
|
|
|
}
|
2009-09-24 21:10:44 +02:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MATCH_FULL:
|
|
|
|
r->match = regex_match_full;
|
|
|
|
break;
|
|
|
|
case MATCH_FRONT_ONLY:
|
|
|
|
r->match = regex_match_front;
|
|
|
|
break;
|
|
|
|
case MATCH_MIDDLE_ONLY:
|
|
|
|
r->match = regex_match_middle;
|
|
|
|
break;
|
|
|
|
case MATCH_END_ONLY:
|
|
|
|
r->match = regex_match_end;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pred->not ^= not;
|
|
|
|
}
|
|
|
|
|
2011-01-28 04:54:33 +01:00
|
|
|
enum move_type {
|
|
|
|
MOVE_DOWN,
|
|
|
|
MOVE_UP_FROM_LEFT,
|
|
|
|
MOVE_UP_FROM_RIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct filter_pred *
|
|
|
|
get_pred_parent(struct filter_pred *pred, struct filter_pred *preds,
|
|
|
|
int index, enum move_type *move)
|
|
|
|
{
|
|
|
|
if (pred->parent & FILTER_PRED_IS_RIGHT)
|
|
|
|
*move = MOVE_UP_FROM_RIGHT;
|
|
|
|
else
|
|
|
|
*move = MOVE_UP_FROM_LEFT;
|
|
|
|
pred = &preds[pred->parent & ~FILTER_PRED_IS_RIGHT];
|
|
|
|
|
|
|
|
return pred;
|
|
|
|
}
|
|
|
|
|
2011-08-11 16:25:49 +02:00
|
|
|
enum walk_return {
|
|
|
|
WALK_PRED_ABORT,
|
|
|
|
WALK_PRED_PARENT,
|
|
|
|
WALK_PRED_DEFAULT,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef int (*filter_pred_walkcb_t) (enum move_type move,
|
|
|
|
struct filter_pred *pred,
|
|
|
|
int *err, void *data);
|
|
|
|
|
|
|
|
static int walk_pred_tree(struct filter_pred *preds,
|
|
|
|
struct filter_pred *root,
|
|
|
|
filter_pred_walkcb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct filter_pred *pred = root;
|
|
|
|
enum move_type move = MOVE_DOWN;
|
|
|
|
int done = 0;
|
|
|
|
|
|
|
|
if (!preds)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
do {
|
|
|
|
int err = 0, ret;
|
|
|
|
|
|
|
|
ret = cb(move, pred, &err, data);
|
|
|
|
if (ret == WALK_PRED_ABORT)
|
|
|
|
return err;
|
|
|
|
if (ret == WALK_PRED_PARENT)
|
|
|
|
goto get_parent;
|
|
|
|
|
|
|
|
switch (move) {
|
|
|
|
case MOVE_DOWN:
|
|
|
|
if (pred->left != FILTER_PRED_INVALID) {
|
|
|
|
pred = &preds[pred->left];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
goto get_parent;
|
|
|
|
case MOVE_UP_FROM_LEFT:
|
|
|
|
pred = &preds[pred->right];
|
|
|
|
move = MOVE_DOWN;
|
|
|
|
continue;
|
|
|
|
case MOVE_UP_FROM_RIGHT:
|
|
|
|
get_parent:
|
|
|
|
if (pred == root)
|
|
|
|
break;
|
|
|
|
pred = get_pred_parent(pred, preds,
|
|
|
|
pred->parent,
|
|
|
|
&move);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
done = 1;
|
|
|
|
} while (!done);
|
|
|
|
|
|
|
|
/* We are fine. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-28 05:16:51 +01:00
|
|
|
/*
|
|
|
|
* A series of AND or ORs where found together. Instead of
|
|
|
|
* climbing up and down the tree branches, an array of the
|
|
|
|
* ops were made in order of checks. We can just move across
|
|
|
|
* the array and short circuit if needed.
|
|
|
|
*/
|
|
|
|
static int process_ops(struct filter_pred *preds,
|
|
|
|
struct filter_pred *op, void *rec)
|
|
|
|
{
|
|
|
|
struct filter_pred *pred;
|
2011-03-18 14:41:27 +01:00
|
|
|
int match = 0;
|
2011-01-28 05:16:51 +01:00
|
|
|
int type;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Micro-optimization: We set type to true if op
|
|
|
|
* is an OR and false otherwise (AND). Then we
|
|
|
|
* just need to test if the match is equal to
|
|
|
|
* the type, and if it is, we can short circuit the
|
|
|
|
* rest of the checks:
|
|
|
|
*
|
|
|
|
* if ((match && op->op == OP_OR) ||
|
|
|
|
* (!match && op->op == OP_AND))
|
|
|
|
* return match;
|
|
|
|
*/
|
|
|
|
type = op->op == OP_OR;
|
|
|
|
|
|
|
|
for (i = 0; i < op->val; i++) {
|
|
|
|
pred = &preds[op->ops[i]];
|
2011-08-11 16:25:53 +02:00
|
|
|
if (!WARN_ON_ONCE(!pred->fn))
|
|
|
|
match = pred->fn(pred, rec);
|
2011-01-28 05:16:51 +01:00
|
|
|
if (!!match == type)
|
2014-12-03 01:08:30 +01:00
|
|
|
break;
|
2011-01-28 05:16:51 +01:00
|
|
|
}
|
2014-12-03 01:08:30 +01:00
|
|
|
/* If not of not match is equal to not of not, then it is a match */
|
|
|
|
return !!match == !op->not;
|
2011-01-28 05:16:51 +01:00
|
|
|
}
|
|
|
|
|
2011-08-11 16:25:53 +02:00
|
|
|
struct filter_match_preds_data {
|
|
|
|
struct filter_pred *preds;
|
|
|
|
int match;
|
|
|
|
void *rec;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int filter_match_preds_cb(enum move_type move, struct filter_pred *pred,
|
|
|
|
int *err, void *data)
|
|
|
|
{
|
|
|
|
struct filter_match_preds_data *d = data;
|
|
|
|
|
|
|
|
*err = 0;
|
|
|
|
switch (move) {
|
|
|
|
case MOVE_DOWN:
|
|
|
|
/* only AND and OR have children */
|
|
|
|
if (pred->left != FILTER_PRED_INVALID) {
|
|
|
|
/* If ops is set, then it was folded. */
|
|
|
|
if (!pred->ops)
|
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
/* We can treat folded ops as a leaf node */
|
|
|
|
d->match = process_ops(d->preds, pred, d->rec);
|
|
|
|
} else {
|
|
|
|
if (!WARN_ON_ONCE(!pred->fn))
|
|
|
|
d->match = pred->fn(pred, d->rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
return WALK_PRED_PARENT;
|
|
|
|
case MOVE_UP_FROM_LEFT:
|
|
|
|
/*
|
|
|
|
* Check for short circuits.
|
|
|
|
*
|
|
|
|
* Optimization: !!match == (pred->op == OP_OR)
|
|
|
|
* is the same as:
|
|
|
|
* if ((match && pred->op == OP_OR) ||
|
|
|
|
* (!match && pred->op == OP_AND))
|
|
|
|
*/
|
|
|
|
if (!!d->match == (pred->op == OP_OR))
|
|
|
|
return WALK_PRED_PARENT;
|
|
|
|
break;
|
|
|
|
case MOVE_UP_FROM_RIGHT:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2009-03-22 09:31:04 +01:00
|
|
|
/* return 1 if event matches, 0 otherwise (discard) */
|
2009-10-15 05:21:42 +02:00
|
|
|
int filter_match_preds(struct event_filter *filter, void *rec)
|
2009-03-22 09:31:04 +01:00
|
|
|
{
|
2011-01-28 04:49:48 +01:00
|
|
|
struct filter_pred *preds;
|
2011-01-28 04:54:33 +01:00
|
|
|
struct filter_pred *root;
|
2011-08-11 16:25:53 +02:00
|
|
|
struct filter_match_preds_data data = {
|
|
|
|
/* match is currently meaningless */
|
|
|
|
.match = -1,
|
|
|
|
.rec = rec,
|
|
|
|
};
|
|
|
|
int n_preds, ret;
|
2009-03-22 09:31:04 +01:00
|
|
|
|
2011-01-28 04:33:26 +01:00
|
|
|
/* no filter is considered a match */
|
2011-02-04 05:25:46 +01:00
|
|
|
if (!filter)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
n_preds = filter->n_preds;
|
2011-01-28 04:33:26 +01:00
|
|
|
if (!n_preds)
|
|
|
|
return 1;
|
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
/*
|
2011-01-28 04:54:33 +01:00
|
|
|
* n_preds, root and filter->preds are protect with preemption disabled.
|
2011-01-28 04:42:43 +01:00
|
|
|
*/
|
2011-01-28 04:54:33 +01:00
|
|
|
root = rcu_dereference_sched(filter->root);
|
|
|
|
if (!root)
|
|
|
|
return 1;
|
2011-01-28 04:42:43 +01:00
|
|
|
|
2011-08-11 16:25:53 +02:00
|
|
|
data.preds = preds = rcu_dereference_sched(filter->preds);
|
|
|
|
ret = walk_pred_tree(preds, root, filter_match_preds_cb, &data);
|
|
|
|
WARN_ON(ret);
|
|
|
|
return data.match;
|
2009-03-22 09:31:04 +01:00
|
|
|
}
|
2009-04-11 00:12:50 +02:00
|
|
|
EXPORT_SYMBOL_GPL(filter_match_preds);
|
2009-03-22 09:31:04 +01:00
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
static void parse_error(struct filter_parse_state *ps, int err, int pos)
|
2009-03-22 09:31:04 +01:00
|
|
|
{
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
ps->lasterr = err;
|
|
|
|
ps->lasterr_pos = pos;
|
|
|
|
}
|
2009-03-22 09:31:04 +01:00
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
static void remove_filter_string(struct event_filter *filter)
|
|
|
|
{
|
2011-02-04 05:25:46 +01:00
|
|
|
if (!filter)
|
|
|
|
return;
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
kfree(filter->filter_string);
|
|
|
|
filter->filter_string = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int replace_filter_string(struct event_filter *filter,
|
|
|
|
char *filter_string)
|
|
|
|
{
|
|
|
|
kfree(filter->filter_string);
|
|
|
|
filter->filter_string = kstrdup(filter_string, GFP_KERNEL);
|
|
|
|
if (!filter->filter_string)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int append_filter_string(struct event_filter *filter,
|
|
|
|
char *string)
|
|
|
|
{
|
|
|
|
int newlen;
|
|
|
|
char *new_filter_string;
|
|
|
|
|
|
|
|
BUG_ON(!filter->filter_string);
|
|
|
|
newlen = strlen(filter->filter_string) + strlen(string) + 1;
|
|
|
|
new_filter_string = kmalloc(newlen, GFP_KERNEL);
|
|
|
|
if (!new_filter_string)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
strcpy(new_filter_string, filter->filter_string);
|
|
|
|
strcat(new_filter_string, string);
|
|
|
|
kfree(filter->filter_string);
|
|
|
|
filter->filter_string = new_filter_string;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void append_filter_err(struct filter_parse_state *ps,
|
|
|
|
struct event_filter *filter)
|
|
|
|
{
|
|
|
|
int pos = ps->lasterr_pos;
|
|
|
|
char *buf, *pbuf;
|
|
|
|
|
|
|
|
buf = (char *)__get_free_page(GFP_TEMPORARY);
|
|
|
|
if (!buf)
|
2009-03-24 08:14:31 +01:00
|
|
|
return;
|
2009-03-22 09:31:04 +01:00
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
append_filter_string(filter, "\n");
|
|
|
|
memset(buf, ' ', PAGE_SIZE);
|
|
|
|
if (pos > PAGE_SIZE - 128)
|
|
|
|
pos = 0;
|
|
|
|
buf[pos] = '^';
|
|
|
|
pbuf = &buf[pos] + 1;
|
|
|
|
|
|
|
|
sprintf(pbuf, "\nparse_error: %s\n", err_text[ps->lasterr]);
|
|
|
|
append_filter_string(filter, buf);
|
|
|
|
free_page((unsigned long) buf);
|
2009-03-22 09:31:04 +01:00
|
|
|
}
|
|
|
|
|
2015-05-05 16:09:53 +02:00
|
|
|
static inline struct event_filter *event_filter(struct trace_event_file *file)
|
2013-10-24 15:34:17 +02:00
|
|
|
{
|
|
|
|
if (file->event_call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
|
|
|
|
return file->event_call->filter;
|
|
|
|
else
|
|
|
|
return file->filter;
|
|
|
|
}
|
|
|
|
|
2013-07-26 19:25:40 +02:00
|
|
|
/* caller must hold event_mutex */
|
2015-05-05 16:09:53 +02:00
|
|
|
void print_event_filter(struct trace_event_file *file, struct trace_seq *s)
|
2009-04-17 07:27:08 +02:00
|
|
|
{
|
2013-10-24 15:34:17 +02:00
|
|
|
struct event_filter *filter = event_filter(file);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
2009-08-31 10:49:41 +02:00
|
|
|
if (filter && filter->filter_string)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
trace_seq_printf(s, "%s\n", filter->filter_string);
|
|
|
|
else
|
2013-07-15 10:32:44 +02:00
|
|
|
trace_seq_puts(s, "none\n");
|
2009-04-17 07:27:08 +02:00
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
void print_subsystem_event_filter(struct event_subsystem *system,
|
2009-04-17 07:27:08 +02:00
|
|
|
struct trace_seq *s)
|
|
|
|
{
|
2011-02-04 05:25:46 +01:00
|
|
|
struct event_filter *filter;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
2009-06-16 10:39:41 +02:00
|
|
|
mutex_lock(&event_mutex);
|
2011-02-04 05:25:46 +01:00
|
|
|
filter = system->filter;
|
2009-08-31 10:49:41 +02:00
|
|
|
if (filter && filter->filter_string)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
trace_seq_printf(s, "%s\n", filter->filter_string);
|
|
|
|
else
|
2013-07-15 10:32:44 +02:00
|
|
|
trace_seq_puts(s, DEFAULT_SYS_FILTER_MESSAGE "\n");
|
2009-06-16 10:39:41 +02:00
|
|
|
mutex_unlock(&event_mutex);
|
2009-04-17 07:27:08 +02:00
|
|
|
}
|
|
|
|
|
2011-01-28 04:54:33 +01:00
|
|
|
static int __alloc_pred_stack(struct pred_stack *stack, int n_preds)
|
|
|
|
{
|
2011-11-29 22:08:00 +01:00
|
|
|
stack->preds = kcalloc(n_preds + 1, sizeof(*stack->preds), GFP_KERNEL);
|
2011-01-28 04:54:33 +01:00
|
|
|
if (!stack->preds)
|
|
|
|
return -ENOMEM;
|
|
|
|
stack->index = n_preds;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __free_pred_stack(struct pred_stack *stack)
|
|
|
|
{
|
|
|
|
kfree(stack->preds);
|
|
|
|
stack->index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __push_pred_stack(struct pred_stack *stack,
|
|
|
|
struct filter_pred *pred)
|
|
|
|
{
|
|
|
|
int index = stack->index;
|
|
|
|
|
|
|
|
if (WARN_ON(index == 0))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
stack->preds[--index] = pred;
|
|
|
|
stack->index = index;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct filter_pred *
|
|
|
|
__pop_pred_stack(struct pred_stack *stack)
|
|
|
|
{
|
|
|
|
struct filter_pred *pred;
|
|
|
|
int index = stack->index;
|
|
|
|
|
|
|
|
pred = stack->preds[index++];
|
|
|
|
if (!pred)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stack->index = index;
|
|
|
|
return pred;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int filter_set_pred(struct event_filter *filter,
|
|
|
|
int idx,
|
|
|
|
struct pred_stack *stack,
|
2011-08-11 16:25:46 +02:00
|
|
|
struct filter_pred *src)
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
{
|
2011-01-28 04:54:33 +01:00
|
|
|
struct filter_pred *dest = &filter->preds[idx];
|
|
|
|
struct filter_pred *left;
|
|
|
|
struct filter_pred *right;
|
|
|
|
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
*dest = *src;
|
2011-01-28 04:54:33 +01:00
|
|
|
dest->index = idx;
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
|
2011-01-28 04:54:33 +01:00
|
|
|
if (dest->op == OP_OR || dest->op == OP_AND) {
|
|
|
|
right = __pop_pred_stack(stack);
|
|
|
|
left = __pop_pred_stack(stack);
|
|
|
|
if (!left || !right)
|
|
|
|
return -EINVAL;
|
2011-01-28 05:16:51 +01:00
|
|
|
/*
|
|
|
|
* If both children can be folded
|
|
|
|
* and they are the same op as this op or a leaf,
|
|
|
|
* then this op can be folded.
|
|
|
|
*/
|
|
|
|
if (left->index & FILTER_PRED_FOLD &&
|
2014-12-03 01:08:30 +01:00
|
|
|
((left->op == dest->op && !left->not) ||
|
2011-01-28 05:16:51 +01:00
|
|
|
left->left == FILTER_PRED_INVALID) &&
|
|
|
|
right->index & FILTER_PRED_FOLD &&
|
2014-12-03 01:08:30 +01:00
|
|
|
((right->op == dest->op && !right->not) ||
|
2011-01-28 05:16:51 +01:00
|
|
|
right->left == FILTER_PRED_INVALID))
|
|
|
|
dest->index |= FILTER_PRED_FOLD;
|
|
|
|
|
|
|
|
dest->left = left->index & ~FILTER_PRED_FOLD;
|
|
|
|
dest->right = right->index & ~FILTER_PRED_FOLD;
|
|
|
|
left->parent = dest->index & ~FILTER_PRED_FOLD;
|
2011-01-28 04:54:33 +01:00
|
|
|
right->parent = dest->index | FILTER_PRED_IS_RIGHT;
|
2011-01-28 05:16:51 +01:00
|
|
|
} else {
|
2011-01-28 04:54:33 +01:00
|
|
|
/*
|
|
|
|
* Make dest->left invalid to be used as a quick
|
|
|
|
* way to know this is a leaf node.
|
|
|
|
*/
|
|
|
|
dest->left = FILTER_PRED_INVALID;
|
|
|
|
|
2011-01-28 05:16:51 +01:00
|
|
|
/* All leafs allow folding the parent ops. */
|
|
|
|
dest->index |= FILTER_PRED_FOLD;
|
|
|
|
}
|
|
|
|
|
2011-01-28 04:54:33 +01:00
|
|
|
return __push_pred_stack(stack, dest);
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
}
|
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
static void __free_preds(struct event_filter *filter)
|
|
|
|
{
|
2013-05-14 21:40:48 +02:00
|
|
|
int i;
|
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
if (filter->preds) {
|
2013-05-14 21:40:48 +02:00
|
|
|
for (i = 0; i < filter->n_preds; i++)
|
|
|
|
kfree(filter->preds[i].ops);
|
2011-01-28 04:42:43 +01:00
|
|
|
kfree(filter->preds);
|
|
|
|
filter->preds = NULL;
|
|
|
|
}
|
|
|
|
filter->a_preds = 0;
|
|
|
|
filter->n_preds = 0;
|
|
|
|
}
|
|
|
|
|
2015-05-05 16:09:53 +02:00
|
|
|
static void filter_disable(struct trace_event_file *file)
|
2013-10-24 15:34:17 +02:00
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = file->event_call;
|
2013-10-24 15:34:17 +02:00
|
|
|
|
|
|
|
if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
|
2014-07-15 20:48:21 +02:00
|
|
|
call->flags &= ~TRACE_EVENT_FL_FILTERED;
|
2013-10-24 15:34:17 +02:00
|
|
|
else
|
2015-05-13 21:12:33 +02:00
|
|
|
file->flags &= ~EVENT_FILE_FL_FILTERED;
|
2013-10-24 15:34:17 +02:00
|
|
|
}
|
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
static void __free_filter(struct event_filter *filter)
|
2009-05-06 04:33:04 +02:00
|
|
|
{
|
2009-08-31 10:49:41 +02:00
|
|
|
if (!filter)
|
|
|
|
return;
|
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
__free_preds(filter);
|
2009-06-16 10:39:12 +02:00
|
|
|
kfree(filter->filter_string);
|
2009-05-06 04:33:04 +02:00
|
|
|
kfree(filter);
|
2009-10-15 05:21:42 +02:00
|
|
|
}
|
|
|
|
|
tracing: Add and use generic set_trigger_filter() implementation
Add a generic event_command.set_trigger_filter() op implementation and
have the current set of trigger commands use it - this essentially
gives them all support for filters.
Syntactically, filters are supported by adding 'if <filter>' just
after the command, in which case only events matching the filter will
invoke the trigger. For example, to add a filter to an
enable/disable_event command:
echo 'enable_event:system:event if common_pid == 999' > \
.../othersys/otherevent/trigger
The above command will only enable the system:event event if the
common_pid field in the othersys:otherevent event is 999.
As another example, to add a filter to a stacktrace command:
echo 'stacktrace if common_pid == 999' > \
.../somesys/someevent/trigger
The above command will only trigger a stacktrace if the common_pid
field in the event is 999.
The filter syntax is the same as that described in the 'Event
filtering' section of Documentation/trace/events.txt.
Because triggers can now use filters, the trigger-invoking logic needs
to be moved in those cases - e.g. for ftrace_raw_event_calls, if a
trigger has a filter associated with it, the trigger invocation now
needs to happen after the { assign; } part of the call, in order for
the trigger condition to be tested.
There's still a SOFT_DISABLED-only check at the top of e.g. the
ftrace_raw_events function, so when an event is soft disabled but not
because of the presence of a trigger, the original SOFT_DISABLED
behavior remains unchanged.
There's also a bit of trickiness in that some triggers need to avoid
being invoked while an event is currently in the process of being
logged, since the trigger may itself log data into the trace buffer.
Thus we make sure the current event is committed before invoking those
triggers. To do that, we split the trigger invocation in two - the
first part (event_triggers_call()) checks the filter using the current
trace record; if a command has the post_trigger flag set, it sets a
bit for itself in the return value, otherwise it directly invoks the
trigger. Once all commands have been either invoked or set their
return flag, event_triggers_call() returns. The current record is
then either committed or discarded; if any commands have deferred
their triggers, those commands are finally invoked following the close
of the current event by event_triggers_post_call().
To simplify the above and make it more efficient, the TRIGGER_COND bit
is introduced, which is set only if a soft-disabled trigger needs to
use the log record for filter testing or needs to wait until the
current log record is closed.
The syscall event invocation code is also changed in analogous ways.
Because event triggers need to be able to create and free filters,
this also adds a couple external wrappers for the existing
create_filter and free_filter functions, which are too generic to be
made extern functions themselves.
Link: http://lkml.kernel.org/r/7164930759d8719ef460357f143d995406e4eead.1382622043.git.tom.zanussi@linux.intel.com
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-10-24 15:59:29 +02:00
|
|
|
void free_event_filter(struct event_filter *filter)
|
|
|
|
{
|
|
|
|
__free_filter(filter);
|
|
|
|
}
|
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
static struct event_filter *__alloc_filter(void)
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
{
|
2009-04-28 10:04:47 +02:00
|
|
|
struct event_filter *filter;
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
|
2009-10-15 05:21:42 +02:00
|
|
|
filter = kzalloc(sizeof(*filter), GFP_KERNEL);
|
2011-01-28 04:42:43 +01:00
|
|
|
return filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __alloc_preds(struct event_filter *filter, int n_preds)
|
|
|
|
{
|
|
|
|
struct filter_pred *pred;
|
|
|
|
int i;
|
|
|
|
|
2011-02-04 05:29:06 +01:00
|
|
|
if (filter->preds)
|
|
|
|
__free_preds(filter);
|
|
|
|
|
2011-11-29 22:08:00 +01:00
|
|
|
filter->preds = kcalloc(n_preds, sizeof(*filter->preds), GFP_KERNEL);
|
2011-01-28 04:42:43 +01:00
|
|
|
|
2009-04-28 10:04:47 +02:00
|
|
|
if (!filter->preds)
|
2011-01-28 04:42:43 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-02-04 05:29:06 +01:00
|
|
|
filter->a_preds = n_preds;
|
|
|
|
filter->n_preds = 0;
|
2009-04-28 10:04:47 +02:00
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
for (i = 0; i < n_preds; i++) {
|
2011-01-28 04:49:48 +01:00
|
|
|
pred = &filter->preds[i];
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
pred->fn = filter_pred_none;
|
|
|
|
}
|
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
return 0;
|
2009-10-15 05:21:42 +02:00
|
|
|
}
|
|
|
|
|
2015-05-05 16:09:53 +02:00
|
|
|
static inline void __remove_filter(struct trace_event_file *file)
|
2009-08-31 10:49:41 +02:00
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = file->event_call;
|
2013-10-24 15:34:17 +02:00
|
|
|
|
|
|
|
filter_disable(file);
|
|
|
|
if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
|
|
|
|
remove_filter_string(call->filter);
|
|
|
|
else
|
|
|
|
remove_filter_string(file->filter);
|
|
|
|
}
|
|
|
|
|
2015-05-13 20:59:40 +02:00
|
|
|
static void filter_free_subsystem_preds(struct trace_subsystem_dir *dir,
|
2013-10-24 15:34:17 +02:00
|
|
|
struct trace_array *tr)
|
|
|
|
{
|
2015-05-05 16:09:53 +02:00
|
|
|
struct trace_event_file *file;
|
2009-08-31 10:49:41 +02:00
|
|
|
|
2013-10-24 15:34:17 +02:00
|
|
|
list_for_each_entry(file, &tr->events, list) {
|
2014-07-15 20:48:29 +02:00
|
|
|
if (file->system != dir)
|
2009-08-31 10:49:41 +02:00
|
|
|
continue;
|
2013-10-24 15:34:17 +02:00
|
|
|
__remove_filter(file);
|
2009-08-31 10:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
2009-03-22 09:31:04 +01:00
|
|
|
|
2015-05-05 16:09:53 +02:00
|
|
|
static inline void __free_subsystem_filter(struct trace_event_file *file)
|
2009-03-22 09:31:17 +01:00
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = file->event_call;
|
2013-10-24 15:34:17 +02:00
|
|
|
|
|
|
|
if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER) {
|
|
|
|
__free_filter(call->filter);
|
|
|
|
call->filter = NULL;
|
|
|
|
} else {
|
|
|
|
__free_filter(file->filter);
|
|
|
|
file->filter = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-13 20:59:40 +02:00
|
|
|
static void filter_free_subsystem_filters(struct trace_subsystem_dir *dir,
|
2013-10-24 15:34:17 +02:00
|
|
|
struct trace_array *tr)
|
|
|
|
{
|
2015-05-05 16:09:53 +02:00
|
|
|
struct trace_event_file *file;
|
2009-03-22 09:31:17 +01:00
|
|
|
|
2013-10-24 15:34:17 +02:00
|
|
|
list_for_each_entry(file, &tr->events, list) {
|
2014-07-15 20:48:29 +02:00
|
|
|
if (file->system != dir)
|
2009-08-31 10:49:41 +02:00
|
|
|
continue;
|
2013-10-24 15:34:17 +02:00
|
|
|
__free_subsystem_filter(file);
|
2009-03-22 09:31:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-11 16:25:46 +02:00
|
|
|
static int filter_add_pred(struct filter_parse_state *ps,
|
|
|
|
struct event_filter *filter,
|
|
|
|
struct filter_pred *pred,
|
|
|
|
struct pred_stack *stack)
|
2009-03-22 09:31:04 +01:00
|
|
|
{
|
2011-08-11 16:25:47 +02:00
|
|
|
int err;
|
2009-03-22 09:31:04 +01:00
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
if (WARN_ON(filter->n_preds == filter->a_preds)) {
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
parse_error(ps, FILT_ERR_TOO_MANY_PREDS, 0);
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
return -ENOSPC;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
}
|
2009-03-22 09:31:04 +01:00
|
|
|
|
2011-08-11 16:25:47 +02:00
|
|
|
err = filter_set_pred(filter, filter->n_preds, stack, pred);
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2009-04-28 10:04:47 +02:00
|
|
|
filter->n_preds++;
|
2009-03-22 09:31:04 +01:00
|
|
|
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
return 0;
|
2009-03-22 09:31:04 +01:00
|
|
|
}
|
|
|
|
|
2009-08-07 04:33:02 +02:00
|
|
|
int filter_assign_type(const char *type)
|
2009-03-22 09:31:04 +01:00
|
|
|
{
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 09:35:46 +02:00
|
|
|
if (strstr(type, "__data_loc") && strstr(type, "char"))
|
|
|
|
return FILTER_DYN_STRING;
|
|
|
|
|
2009-03-22 09:31:04 +01:00
|
|
|
if (strchr(type, '[') && strstr(type, "char"))
|
2009-05-03 02:48:52 +02:00
|
|
|
return FILTER_STATIC_STRING;
|
|
|
|
|
2009-08-07 04:33:02 +02:00
|
|
|
return FILTER_OTHER;
|
|
|
|
}
|
|
|
|
|
2012-02-15 15:51:53 +01:00
|
|
|
static bool is_function_field(struct ftrace_event_field *field)
|
|
|
|
{
|
|
|
|
return field->filter_type == FILTER_TRACE_FN;
|
|
|
|
}
|
|
|
|
|
2009-08-07 04:33:02 +02:00
|
|
|
static bool is_string_field(struct ftrace_event_field *field)
|
|
|
|
{
|
|
|
|
return field->filter_type == FILTER_DYN_STRING ||
|
2009-08-07 04:33:43 +02:00
|
|
|
field->filter_type == FILTER_STATIC_STRING ||
|
|
|
|
field->filter_type == FILTER_PTR_STRING;
|
2009-03-22 09:31:04 +01:00
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
static int is_legal_op(struct ftrace_event_field *field, int op)
|
|
|
|
{
|
2009-10-15 05:21:12 +02:00
|
|
|
if (is_string_field(field) &&
|
|
|
|
(op != OP_EQ && op != OP_NE && op != OP_GLOB))
|
|
|
|
return 0;
|
|
|
|
if (!is_string_field(field) && op == OP_GLOB)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static filter_pred_fn_t select_comparison_fn(int op, int field_size,
|
|
|
|
int field_is_signed)
|
|
|
|
{
|
|
|
|
filter_pred_fn_t fn = NULL;
|
|
|
|
|
|
|
|
switch (field_size) {
|
|
|
|
case 8:
|
|
|
|
if (op == OP_EQ || op == OP_NE)
|
|
|
|
fn = filter_pred_64;
|
|
|
|
else if (field_is_signed)
|
|
|
|
fn = filter_pred_s64;
|
|
|
|
else
|
|
|
|
fn = filter_pred_u64;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (op == OP_EQ || op == OP_NE)
|
|
|
|
fn = filter_pred_32;
|
|
|
|
else if (field_is_signed)
|
|
|
|
fn = filter_pred_s32;
|
|
|
|
else
|
|
|
|
fn = filter_pred_u32;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (op == OP_EQ || op == OP_NE)
|
|
|
|
fn = filter_pred_16;
|
|
|
|
else if (field_is_signed)
|
|
|
|
fn = filter_pred_s16;
|
|
|
|
else
|
|
|
|
fn = filter_pred_u16;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (op == OP_EQ || op == OP_NE)
|
|
|
|
fn = filter_pred_8;
|
|
|
|
else if (field_is_signed)
|
|
|
|
fn = filter_pred_s8;
|
|
|
|
else
|
|
|
|
fn = filter_pred_u8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
2011-08-11 16:25:46 +02:00
|
|
|
static int init_pred(struct filter_parse_state *ps,
|
2011-08-11 16:25:47 +02:00
|
|
|
struct ftrace_event_field *field,
|
2011-08-11 16:25:46 +02:00
|
|
|
struct filter_pred *pred)
|
|
|
|
|
2009-03-22 09:31:04 +01:00
|
|
|
{
|
2011-08-11 16:25:46 +02:00
|
|
|
filter_pred_fn_t fn = filter_pred_none;
|
2009-04-21 11:12:11 +02:00
|
|
|
unsigned long long val;
|
2009-06-15 04:58:39 +02:00
|
|
|
int ret;
|
2009-03-22 09:31:04 +01:00
|
|
|
|
|
|
|
pred->offset = field->offset;
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
if (!is_legal_op(field, pred->op)) {
|
|
|
|
parse_error(ps, FILT_ERR_ILLEGAL_FIELD_OP, 0);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-08-07 04:33:02 +02:00
|
|
|
if (is_string_field(field)) {
|
2009-10-15 05:21:12 +02:00
|
|
|
filter_build_regex(pred);
|
2009-08-07 04:33:43 +02:00
|
|
|
|
2009-09-24 21:10:44 +02:00
|
|
|
if (field->filter_type == FILTER_STATIC_STRING) {
|
2009-05-03 02:48:52 +02:00
|
|
|
fn = filter_pred_string;
|
2009-09-24 21:10:44 +02:00
|
|
|
pred->regex.field_len = field->size;
|
|
|
|
} else if (field->filter_type == FILTER_DYN_STRING)
|
2009-10-15 05:21:12 +02:00
|
|
|
fn = filter_pred_strloc;
|
2010-01-14 03:54:27 +01:00
|
|
|
else
|
2009-08-07 04:33:43 +02:00
|
|
|
fn = filter_pred_pchar;
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 15:51:54 +01:00
|
|
|
} else if (is_function_field(field)) {
|
|
|
|
if (strcmp(field->name, "ip")) {
|
|
|
|
parse_error(ps, FILT_ERR_IP_FIELD_ONLY, 0);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
} else {
|
2009-06-15 04:58:39 +02:00
|
|
|
if (field->is_signed)
|
2012-09-26 22:08:38 +02:00
|
|
|
ret = kstrtoll(pred->regex.pattern, 0, &val);
|
2009-06-15 04:58:39 +02:00
|
|
|
else
|
2012-09-26 22:08:38 +02:00
|
|
|
ret = kstrtoull(pred->regex.pattern, 0, &val);
|
2009-06-15 04:58:39 +02:00
|
|
|
if (ret) {
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
parse_error(ps, FILT_ERR_ILLEGAL_INTVAL, 0);
|
2009-03-24 08:14:42 +01:00
|
|
|
return -EINVAL;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
}
|
2009-04-21 11:12:11 +02:00
|
|
|
pred->val = val;
|
2009-03-22 09:31:04 +01:00
|
|
|
|
2009-07-20 04:20:53 +02:00
|
|
|
fn = select_comparison_fn(pred->op, field->size,
|
|
|
|
field->is_signed);
|
|
|
|
if (!fn) {
|
|
|
|
parse_error(ps, FILT_ERR_INVALID_OP, 0);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2009-03-22 09:31:04 +01:00
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
if (pred->op == OP_NE)
|
2014-12-02 17:55:36 +01:00
|
|
|
pred->not ^= 1;
|
2009-04-17 07:27:08 +02:00
|
|
|
|
2011-08-11 16:25:46 +02:00
|
|
|
pred->fn = fn;
|
2009-07-20 04:20:53 +02:00
|
|
|
return 0;
|
2009-03-22 09:31:17 +01:00
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
static void parse_init(struct filter_parse_state *ps,
|
|
|
|
struct filter_op *ops,
|
|
|
|
char *infix_string)
|
|
|
|
{
|
|
|
|
memset(ps, '\0', sizeof(*ps));
|
|
|
|
|
|
|
|
ps->infix.string = infix_string;
|
|
|
|
ps->infix.cnt = strlen(infix_string);
|
|
|
|
ps->ops = ops;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&ps->opstack);
|
|
|
|
INIT_LIST_HEAD(&ps->postfix);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char infix_next(struct filter_parse_state *ps)
|
|
|
|
{
|
2015-06-26 00:10:09 +02:00
|
|
|
if (!ps->infix.cnt)
|
|
|
|
return 0;
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
ps->infix.cnt--;
|
|
|
|
|
|
|
|
return ps->infix.string[ps->infix.tail++];
|
|
|
|
}
|
|
|
|
|
|
|
|
static char infix_peek(struct filter_parse_state *ps)
|
|
|
|
{
|
|
|
|
if (ps->infix.tail == strlen(ps->infix.string))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ps->infix.string[ps->infix.tail];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void infix_advance(struct filter_parse_state *ps)
|
|
|
|
{
|
2015-06-26 00:10:09 +02:00
|
|
|
if (!ps->infix.cnt)
|
|
|
|
return;
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
ps->infix.cnt--;
|
|
|
|
ps->infix.tail++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_precedence_lower(struct filter_parse_state *ps,
|
|
|
|
int a, int b)
|
|
|
|
{
|
|
|
|
return ps->ops[a].precedence < ps->ops[b].precedence;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_op_char(struct filter_parse_state *ps, char c)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; strcmp(ps->ops[i].string, "OP_NONE"); i++) {
|
|
|
|
if (ps->ops[i].string[0] == c)
|
|
|
|
return 1;
|
|
|
|
}
|
2009-03-23 09:26:48 +01:00
|
|
|
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 10:17:50 +02:00
|
|
|
return 0;
|
2009-03-22 09:31:17 +01:00
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
static int infix_get_op(struct filter_parse_state *ps, char firstc)
|
|
|
|
{
|
|
|
|
char nextc = infix_peek(ps);
|
|
|
|
char opstr[3];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
opstr[0] = firstc;
|
|
|
|
opstr[1] = nextc;
|
|
|
|
opstr[2] = '\0';
|
|
|
|
|
|
|
|
for (i = 0; strcmp(ps->ops[i].string, "OP_NONE"); i++) {
|
|
|
|
if (!strcmp(opstr, ps->ops[i].string)) {
|
|
|
|
infix_advance(ps);
|
|
|
|
return ps->ops[i].id;
|
2009-03-22 09:31:04 +01:00
|
|
|
}
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
opstr[1] = '\0';
|
|
|
|
|
|
|
|
for (i = 0; strcmp(ps->ops[i].string, "OP_NONE"); i++) {
|
|
|
|
if (!strcmp(opstr, ps->ops[i].string))
|
|
|
|
return ps->ops[i].id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OP_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void clear_operand_string(struct filter_parse_state *ps)
|
|
|
|
{
|
|
|
|
memset(ps->operand.string, '\0', MAX_FILTER_STR_VAL);
|
|
|
|
ps->operand.tail = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int append_operand_char(struct filter_parse_state *ps, char c)
|
|
|
|
{
|
2009-05-15 05:07:56 +02:00
|
|
|
if (ps->operand.tail == MAX_FILTER_STR_VAL - 1)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ps->operand.string[ps->operand.tail++] = c;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int filter_opstack_push(struct filter_parse_state *ps, int op)
|
|
|
|
{
|
|
|
|
struct opstack_op *opstack_op;
|
|
|
|
|
|
|
|
opstack_op = kmalloc(sizeof(*opstack_op), GFP_KERNEL);
|
|
|
|
if (!opstack_op)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
opstack_op->op = op;
|
|
|
|
list_add(&opstack_op->list, &ps->opstack);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int filter_opstack_empty(struct filter_parse_state *ps)
|
|
|
|
{
|
|
|
|
return list_empty(&ps->opstack);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int filter_opstack_top(struct filter_parse_state *ps)
|
|
|
|
{
|
|
|
|
struct opstack_op *opstack_op;
|
|
|
|
|
|
|
|
if (filter_opstack_empty(ps))
|
|
|
|
return OP_NONE;
|
|
|
|
|
|
|
|
opstack_op = list_first_entry(&ps->opstack, struct opstack_op, list);
|
|
|
|
|
|
|
|
return opstack_op->op;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int filter_opstack_pop(struct filter_parse_state *ps)
|
|
|
|
{
|
|
|
|
struct opstack_op *opstack_op;
|
|
|
|
int op;
|
|
|
|
|
|
|
|
if (filter_opstack_empty(ps))
|
|
|
|
return OP_NONE;
|
|
|
|
|
|
|
|
opstack_op = list_first_entry(&ps->opstack, struct opstack_op, list);
|
|
|
|
op = opstack_op->op;
|
|
|
|
list_del(&opstack_op->list);
|
|
|
|
|
|
|
|
kfree(opstack_op);
|
|
|
|
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void filter_opstack_clear(struct filter_parse_state *ps)
|
|
|
|
{
|
|
|
|
while (!filter_opstack_empty(ps))
|
|
|
|
filter_opstack_pop(ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *curr_operand(struct filter_parse_state *ps)
|
|
|
|
{
|
|
|
|
return ps->operand.string;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int postfix_append_operand(struct filter_parse_state *ps, char *operand)
|
|
|
|
{
|
|
|
|
struct postfix_elt *elt;
|
|
|
|
|
|
|
|
elt = kmalloc(sizeof(*elt), GFP_KERNEL);
|
|
|
|
if (!elt)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
elt->op = OP_NONE;
|
|
|
|
elt->operand = kstrdup(operand, GFP_KERNEL);
|
|
|
|
if (!elt->operand) {
|
|
|
|
kfree(elt);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&elt->list, &ps->postfix);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int postfix_append_op(struct filter_parse_state *ps, int op)
|
|
|
|
{
|
|
|
|
struct postfix_elt *elt;
|
|
|
|
|
|
|
|
elt = kmalloc(sizeof(*elt), GFP_KERNEL);
|
|
|
|
if (!elt)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
elt->op = op;
|
|
|
|
elt->operand = NULL;
|
|
|
|
|
|
|
|
list_add_tail(&elt->list, &ps->postfix);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void postfix_clear(struct filter_parse_state *ps)
|
|
|
|
{
|
|
|
|
struct postfix_elt *elt;
|
|
|
|
|
|
|
|
while (!list_empty(&ps->postfix)) {
|
|
|
|
elt = list_first_entry(&ps->postfix, struct postfix_elt, list);
|
|
|
|
list_del(&elt->list);
|
2009-10-13 03:28:57 +02:00
|
|
|
kfree(elt->operand);
|
|
|
|
kfree(elt);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int filter_parse(struct filter_parse_state *ps)
|
|
|
|
{
|
2009-05-03 03:03:57 +02:00
|
|
|
int in_string = 0;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
int op, top_op;
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
while ((ch = infix_next(ps))) {
|
2009-05-03 03:03:57 +02:00
|
|
|
if (ch == '"') {
|
|
|
|
in_string ^= 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_string)
|
|
|
|
goto parse_operand;
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
if (isspace(ch))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (is_op_char(ps, ch)) {
|
|
|
|
op = infix_get_op(ps, ch);
|
|
|
|
if (op == OP_NONE) {
|
|
|
|
parse_error(ps, FILT_ERR_INVALID_OP, 0);
|
2009-03-22 09:31:04 +01:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
|
|
|
if (strlen(curr_operand(ps))) {
|
|
|
|
postfix_append_operand(ps, curr_operand(ps));
|
|
|
|
clear_operand_string(ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!filter_opstack_empty(ps)) {
|
|
|
|
top_op = filter_opstack_top(ps);
|
|
|
|
if (!is_precedence_lower(ps, top_op, op)) {
|
|
|
|
top_op = filter_opstack_pop(ps);
|
|
|
|
postfix_append_op(ps, top_op);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
filter_opstack_push(ps, op);
|
2009-03-22 09:31:04 +01:00
|
|
|
continue;
|
|
|
|
}
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
|
|
|
if (ch == '(') {
|
|
|
|
filter_opstack_push(ps, OP_OPEN_PAREN);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch == ')') {
|
|
|
|
if (strlen(curr_operand(ps))) {
|
|
|
|
postfix_append_operand(ps, curr_operand(ps));
|
|
|
|
clear_operand_string(ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
top_op = filter_opstack_pop(ps);
|
|
|
|
while (top_op != OP_NONE) {
|
|
|
|
if (top_op == OP_OPEN_PAREN)
|
|
|
|
break;
|
|
|
|
postfix_append_op(ps, top_op);
|
|
|
|
top_op = filter_opstack_pop(ps);
|
|
|
|
}
|
|
|
|
if (top_op == OP_NONE) {
|
|
|
|
parse_error(ps, FILT_ERR_UNBALANCED_PAREN, 0);
|
|
|
|
return -EINVAL;
|
2009-03-22 09:31:04 +01:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2009-05-03 03:03:57 +02:00
|
|
|
parse_operand:
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
if (append_operand_char(ps, ch)) {
|
|
|
|
parse_error(ps, FILT_ERR_OPERAND_TOO_LONG, 0);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(curr_operand(ps)))
|
|
|
|
postfix_append_operand(ps, curr_operand(ps));
|
|
|
|
|
|
|
|
while (!filter_opstack_empty(ps)) {
|
|
|
|
top_op = filter_opstack_pop(ps);
|
|
|
|
if (top_op == OP_NONE)
|
|
|
|
break;
|
|
|
|
if (top_op == OP_OPEN_PAREN) {
|
|
|
|
parse_error(ps, FILT_ERR_UNBALANCED_PAREN, 0);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
postfix_append_op(ps, top_op);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-11 16:25:45 +02:00
|
|
|
static struct filter_pred *create_pred(struct filter_parse_state *ps,
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call,
|
2011-08-11 16:25:45 +02:00
|
|
|
int op, char *operand1, char *operand2)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
{
|
2011-08-11 16:25:47 +02:00
|
|
|
struct ftrace_event_field *field;
|
2011-08-11 16:25:45 +02:00
|
|
|
static struct filter_pred pred;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
2011-08-11 16:25:45 +02:00
|
|
|
memset(&pred, 0, sizeof(pred));
|
|
|
|
pred.op = op;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
2011-08-11 16:25:45 +02:00
|
|
|
if (op == OP_AND || op == OP_OR)
|
|
|
|
return &pred;
|
|
|
|
|
|
|
|
if (!operand1 || !operand2) {
|
|
|
|
parse_error(ps, FILT_ERR_MISSING_FIELD, 0);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-11 08:13:42 +01:00
|
|
|
field = trace_find_event_field(call, operand1);
|
2011-08-11 16:25:47 +02:00
|
|
|
if (!field) {
|
|
|
|
parse_error(ps, FILT_ERR_FIELD_NOT_FOUND, 0);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
return NULL;
|
2011-08-11 16:25:47 +02:00
|
|
|
}
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
2011-08-11 16:25:45 +02:00
|
|
|
strcpy(pred.regex.pattern, operand2);
|
|
|
|
pred.regex.len = strlen(pred.regex.pattern);
|
2011-08-11 16:25:54 +02:00
|
|
|
pred.field = field;
|
2011-08-11 16:25:47 +02:00
|
|
|
return init_pred(ps, field, &pred) ? NULL : &pred;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int check_preds(struct filter_parse_state *ps)
|
|
|
|
{
|
|
|
|
int n_normal_preds = 0, n_logical_preds = 0;
|
|
|
|
struct postfix_elt *elt;
|
2015-06-15 23:50:25 +02:00
|
|
|
int cnt = 0;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
|
|
|
list_for_each_entry(elt, &ps->postfix, list) {
|
2015-06-15 23:50:25 +02:00
|
|
|
if (elt->op == OP_NONE) {
|
|
|
|
cnt++;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
continue;
|
2015-06-15 23:50:25 +02:00
|
|
|
}
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
|
|
|
if (elt->op == OP_AND || elt->op == OP_OR) {
|
|
|
|
n_logical_preds++;
|
2015-06-15 23:50:25 +02:00
|
|
|
cnt--;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
continue;
|
2009-03-22 09:31:04 +01:00
|
|
|
}
|
2015-06-15 23:50:25 +02:00
|
|
|
if (elt->op != OP_NOT)
|
|
|
|
cnt--;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
n_normal_preds++;
|
2015-06-26 00:02:29 +02:00
|
|
|
/* all ops should have operands */
|
|
|
|
if (cnt < 0)
|
|
|
|
break;
|
2009-03-22 09:31:04 +01:00
|
|
|
}
|
|
|
|
|
2015-06-15 23:50:25 +02:00
|
|
|
if (cnt != 1 || !n_normal_preds || n_logical_preds >= n_normal_preds) {
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
parse_error(ps, FILT_ERR_INVALID_FILTER, 0);
|
2009-04-11 09:52:35 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2009-04-21 11:12:11 +02:00
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
static int count_preds(struct filter_parse_state *ps)
|
|
|
|
{
|
|
|
|
struct postfix_elt *elt;
|
|
|
|
int n_preds = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(elt, &ps->postfix, list) {
|
|
|
|
if (elt->op == OP_NONE)
|
|
|
|
continue;
|
|
|
|
n_preds++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_preds;
|
|
|
|
}
|
|
|
|
|
2011-08-11 16:25:49 +02:00
|
|
|
struct check_pred_data {
|
|
|
|
int count;
|
|
|
|
int max;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int check_pred_tree_cb(enum move_type move, struct filter_pred *pred,
|
|
|
|
int *err, void *data)
|
|
|
|
{
|
|
|
|
struct check_pred_data *d = data;
|
|
|
|
|
|
|
|
if (WARN_ON(d->count++ > d->max)) {
|
|
|
|
*err = -EINVAL;
|
|
|
|
return WALK_PRED_ABORT;
|
|
|
|
}
|
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2011-01-28 05:14:25 +01:00
|
|
|
/*
|
|
|
|
* The tree is walked at filtering of an event. If the tree is not correctly
|
|
|
|
* built, it may cause an infinite loop. Check here that the tree does
|
|
|
|
* indeed terminate.
|
|
|
|
*/
|
|
|
|
static int check_pred_tree(struct event_filter *filter,
|
|
|
|
struct filter_pred *root)
|
|
|
|
{
|
2011-08-11 16:25:49 +02:00
|
|
|
struct check_pred_data data = {
|
|
|
|
/*
|
|
|
|
* The max that we can hit a node is three times.
|
|
|
|
* Once going down, once coming up from left, and
|
|
|
|
* once coming up from right. This is more than enough
|
|
|
|
* since leafs are only hit a single time.
|
|
|
|
*/
|
|
|
|
.max = 3 * filter->n_preds,
|
|
|
|
.count = 0,
|
|
|
|
};
|
2011-01-28 05:14:25 +01:00
|
|
|
|
2011-08-11 16:25:49 +02:00
|
|
|
return walk_pred_tree(filter->preds, root,
|
|
|
|
check_pred_tree_cb, &data);
|
2011-01-28 05:14:25 +01:00
|
|
|
}
|
|
|
|
|
2011-08-11 16:25:50 +02:00
|
|
|
static int count_leafs_cb(enum move_type move, struct filter_pred *pred,
|
|
|
|
int *err, void *data)
|
2011-01-28 05:16:51 +01:00
|
|
|
{
|
2011-08-11 16:25:50 +02:00
|
|
|
int *count = data;
|
2011-01-28 05:16:51 +01:00
|
|
|
|
2011-08-11 16:25:50 +02:00
|
|
|
if ((move == MOVE_DOWN) &&
|
|
|
|
(pred->left == FILTER_PRED_INVALID))
|
|
|
|
(*count)++;
|
2011-01-28 05:16:51 +01:00
|
|
|
|
2011-08-11 16:25:50 +02:00
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int count_leafs(struct filter_pred *preds, struct filter_pred *root)
|
|
|
|
{
|
|
|
|
int count = 0, ret;
|
2011-01-28 05:16:51 +01:00
|
|
|
|
2011-08-11 16:25:50 +02:00
|
|
|
ret = walk_pred_tree(preds, root, count_leafs_cb, &count);
|
|
|
|
WARN_ON(ret);
|
2011-01-28 05:16:51 +01:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2011-08-11 16:25:52 +02:00
|
|
|
struct fold_pred_data {
|
|
|
|
struct filter_pred *root;
|
|
|
|
int count;
|
|
|
|
int children;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int fold_pred_cb(enum move_type move, struct filter_pred *pred,
|
|
|
|
int *err, void *data)
|
|
|
|
{
|
|
|
|
struct fold_pred_data *d = data;
|
|
|
|
struct filter_pred *root = d->root;
|
|
|
|
|
|
|
|
if (move != MOVE_DOWN)
|
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
if (pred->left != FILTER_PRED_INVALID)
|
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
|
|
|
|
if (WARN_ON(d->count == d->children)) {
|
|
|
|
*err = -EINVAL;
|
|
|
|
return WALK_PRED_ABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
pred->index &= ~FILTER_PRED_FOLD;
|
|
|
|
root->ops[d->count++] = pred->index;
|
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2011-01-28 05:16:51 +01:00
|
|
|
static int fold_pred(struct filter_pred *preds, struct filter_pred *root)
|
|
|
|
{
|
2011-08-11 16:25:52 +02:00
|
|
|
struct fold_pred_data data = {
|
|
|
|
.root = root,
|
|
|
|
.count = 0,
|
|
|
|
};
|
2011-01-28 05:16:51 +01:00
|
|
|
int children;
|
|
|
|
|
|
|
|
/* No need to keep the fold flag */
|
|
|
|
root->index &= ~FILTER_PRED_FOLD;
|
|
|
|
|
|
|
|
/* If the root is a leaf then do nothing */
|
|
|
|
if (root->left == FILTER_PRED_INVALID)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* count the children */
|
|
|
|
children = count_leafs(preds, &preds[root->left]);
|
|
|
|
children += count_leafs(preds, &preds[root->right]);
|
|
|
|
|
2011-11-29 22:08:00 +01:00
|
|
|
root->ops = kcalloc(children, sizeof(*root->ops), GFP_KERNEL);
|
2011-01-28 05:16:51 +01:00
|
|
|
if (!root->ops)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
root->val = children;
|
2011-08-11 16:25:52 +02:00
|
|
|
data.children = children;
|
|
|
|
return walk_pred_tree(preds, root, fold_pred_cb, &data);
|
2011-01-28 05:16:51 +01:00
|
|
|
}
|
|
|
|
|
2011-08-11 16:25:51 +02:00
|
|
|
static int fold_pred_tree_cb(enum move_type move, struct filter_pred *pred,
|
|
|
|
int *err, void *data)
|
|
|
|
{
|
|
|
|
struct filter_pred *preds = data;
|
|
|
|
|
|
|
|
if (move != MOVE_DOWN)
|
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
if (!(pred->index & FILTER_PRED_FOLD))
|
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
|
|
|
|
*err = fold_pred(preds, pred);
|
|
|
|
if (*err)
|
|
|
|
return WALK_PRED_ABORT;
|
|
|
|
|
|
|
|
/* eveyrhing below is folded, continue with parent */
|
|
|
|
return WALK_PRED_PARENT;
|
|
|
|
}
|
|
|
|
|
2011-01-28 05:16:51 +01:00
|
|
|
/*
|
|
|
|
* To optimize the processing of the ops, if we have several "ors" or
|
|
|
|
* "ands" together, we can put them in an array and process them all
|
|
|
|
* together speeding up the filter logic.
|
|
|
|
*/
|
|
|
|
static int fold_pred_tree(struct event_filter *filter,
|
|
|
|
struct filter_pred *root)
|
|
|
|
{
|
2011-08-11 16:25:51 +02:00
|
|
|
return walk_pred_tree(filter->preds, root, fold_pred_tree_cb,
|
|
|
|
filter->preds);
|
2011-01-28 05:16:51 +01:00
|
|
|
}
|
|
|
|
|
2015-05-05 17:45:27 +02:00
|
|
|
static int replace_preds(struct trace_event_call *call,
|
2009-10-15 05:21:42 +02:00
|
|
|
struct event_filter *filter,
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
struct filter_parse_state *ps,
|
2009-07-20 04:20:53 +02:00
|
|
|
bool dry_run)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
{
|
|
|
|
char *operand1 = NULL, *operand2 = NULL;
|
|
|
|
struct filter_pred *pred;
|
2011-01-28 05:14:25 +01:00
|
|
|
struct filter_pred *root;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
struct postfix_elt *elt;
|
2011-01-28 04:54:33 +01:00
|
|
|
struct pred_stack stack = { }; /* init to NULL */
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
int err;
|
2009-07-20 04:20:53 +02:00
|
|
|
int n_preds = 0;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
n_preds = count_preds(ps);
|
|
|
|
if (n_preds >= MAX_FILTER_PRED) {
|
|
|
|
parse_error(ps, FILT_ERR_TOO_MANY_PREDS, 0);
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
err = check_preds(ps);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
if (!dry_run) {
|
2011-01-28 04:54:33 +01:00
|
|
|
err = __alloc_pred_stack(&stack, n_preds);
|
2011-01-28 04:42:43 +01:00
|
|
|
if (err)
|
|
|
|
return err;
|
2011-01-28 04:54:33 +01:00
|
|
|
err = __alloc_preds(filter, n_preds);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
2011-01-28 04:42:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
n_preds = 0;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
list_for_each_entry(elt, &ps->postfix, list) {
|
|
|
|
if (elt->op == OP_NONE) {
|
|
|
|
if (!operand1)
|
|
|
|
operand1 = elt->operand;
|
|
|
|
else if (!operand2)
|
|
|
|
operand2 = elt->operand;
|
|
|
|
else {
|
|
|
|
parse_error(ps, FILT_ERR_TOO_MANY_OPERANDS, 0);
|
2011-01-28 04:54:33 +01:00
|
|
|
err = -EINVAL;
|
|
|
|
goto fail;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-12-02 17:55:36 +01:00
|
|
|
if (elt->op == OP_NOT) {
|
|
|
|
if (!n_preds || operand1 || operand2) {
|
|
|
|
parse_error(ps, FILT_ERR_ILLEGAL_NOT_OP, 0);
|
|
|
|
err = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (!dry_run)
|
|
|
|
filter->preds[n_preds - 1].not ^= 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-01-28 04:42:43 +01:00
|
|
|
if (WARN_ON(n_preds++ == MAX_FILTER_PRED)) {
|
2009-07-20 04:20:53 +02:00
|
|
|
parse_error(ps, FILT_ERR_TOO_MANY_PREDS, 0);
|
2011-01-28 04:54:33 +01:00
|
|
|
err = -ENOSPC;
|
|
|
|
goto fail;
|
2009-07-20 04:20:53 +02:00
|
|
|
}
|
|
|
|
|
2011-08-11 16:25:46 +02:00
|
|
|
pred = create_pred(ps, call, elt->op, operand1, operand2);
|
2011-01-28 04:54:33 +01:00
|
|
|
if (!pred) {
|
2011-08-11 16:25:47 +02:00
|
|
|
err = -EINVAL;
|
2011-01-28 04:54:33 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2011-08-11 16:25:47 +02:00
|
|
|
|
2011-08-11 16:25:46 +02:00
|
|
|
if (!dry_run) {
|
|
|
|
err = filter_add_pred(ps, filter, pred, &stack);
|
2011-08-11 16:25:47 +02:00
|
|
|
if (err)
|
2011-08-11 16:25:46 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
|
|
|
operand1 = operand2 = NULL;
|
|
|
|
}
|
2009-03-22 09:31:04 +01:00
|
|
|
|
2011-01-28 04:54:33 +01:00
|
|
|
if (!dry_run) {
|
|
|
|
/* We should have one item left on the stack */
|
|
|
|
pred = __pop_pred_stack(&stack);
|
|
|
|
if (!pred)
|
|
|
|
return -EINVAL;
|
|
|
|
/* This item is where we start from in matching */
|
2011-01-28 05:14:25 +01:00
|
|
|
root = pred;
|
2011-01-28 04:54:33 +01:00
|
|
|
/* Make sure the stack is empty */
|
|
|
|
pred = __pop_pred_stack(&stack);
|
|
|
|
if (WARN_ON(pred)) {
|
|
|
|
err = -EINVAL;
|
|
|
|
filter->root = NULL;
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-01-28 05:14:25 +01:00
|
|
|
err = check_pred_tree(filter, root);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
2011-01-28 05:16:51 +01:00
|
|
|
/* Optimize the tree */
|
|
|
|
err = fold_pred_tree(filter, root);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
2011-01-28 05:14:25 +01:00
|
|
|
/* We don't set root until we know it works */
|
|
|
|
barrier();
|
|
|
|
filter->root = root;
|
2011-01-28 04:54:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
fail:
|
|
|
|
__free_pred_stack(&stack);
|
|
|
|
return err;
|
2009-03-22 09:31:04 +01:00
|
|
|
}
|
|
|
|
|
2015-05-05 16:09:53 +02:00
|
|
|
static inline void event_set_filtered_flag(struct trace_event_file *file)
|
2013-10-24 15:34:17 +02:00
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = file->event_call;
|
2013-10-24 15:34:17 +02:00
|
|
|
|
|
|
|
if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
|
|
|
|
call->flags |= TRACE_EVENT_FL_FILTERED;
|
|
|
|
else
|
2015-05-13 21:12:33 +02:00
|
|
|
file->flags |= EVENT_FILE_FL_FILTERED;
|
2013-10-24 15:34:17 +02:00
|
|
|
}
|
|
|
|
|
2015-05-05 16:09:53 +02:00
|
|
|
static inline void event_set_filter(struct trace_event_file *file,
|
2013-10-24 15:34:17 +02:00
|
|
|
struct event_filter *filter)
|
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = file->event_call;
|
2013-10-24 15:34:17 +02:00
|
|
|
|
|
|
|
if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
|
|
|
|
rcu_assign_pointer(call->filter, filter);
|
|
|
|
else
|
|
|
|
rcu_assign_pointer(file->filter, filter);
|
|
|
|
}
|
|
|
|
|
2015-05-05 16:09:53 +02:00
|
|
|
static inline void event_clear_filter(struct trace_event_file *file)
|
2013-10-24 15:34:17 +02:00
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = file->event_call;
|
2013-10-24 15:34:17 +02:00
|
|
|
|
|
|
|
if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
|
|
|
|
RCU_INIT_POINTER(call->filter, NULL);
|
|
|
|
else
|
|
|
|
RCU_INIT_POINTER(file->filter, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2015-05-05 16:09:53 +02:00
|
|
|
event_set_no_set_filter_flag(struct trace_event_file *file)
|
2013-10-24 15:34:17 +02:00
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = file->event_call;
|
2013-10-24 15:34:17 +02:00
|
|
|
|
|
|
|
if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
|
|
|
|
call->flags |= TRACE_EVENT_FL_NO_SET_FILTER;
|
|
|
|
else
|
2015-05-13 21:12:33 +02:00
|
|
|
file->flags |= EVENT_FILE_FL_NO_SET_FILTER;
|
2013-10-24 15:34:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2015-05-05 16:09:53 +02:00
|
|
|
event_clear_no_set_filter_flag(struct trace_event_file *file)
|
2013-10-24 15:34:17 +02:00
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = file->event_call;
|
2013-10-24 15:34:17 +02:00
|
|
|
|
|
|
|
if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
|
|
|
|
call->flags &= ~TRACE_EVENT_FL_NO_SET_FILTER;
|
|
|
|
else
|
2015-05-13 21:12:33 +02:00
|
|
|
file->flags &= ~EVENT_FILE_FL_NO_SET_FILTER;
|
2013-10-24 15:34:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
2015-05-05 16:09:53 +02:00
|
|
|
event_no_set_filter_flag(struct trace_event_file *file)
|
2013-10-24 15:34:17 +02:00
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = file->event_call;
|
2013-10-24 15:34:17 +02:00
|
|
|
|
2015-05-13 21:12:33 +02:00
|
|
|
if (file->flags & EVENT_FILE_FL_NO_SET_FILTER)
|
2013-10-24 15:34:17 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if ((call->flags & TRACE_EVENT_FL_USE_CALL_FILTER) &&
|
|
|
|
(call->flags & TRACE_EVENT_FL_NO_SET_FILTER))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-04 05:25:46 +01:00
|
|
|
struct filter_list {
|
|
|
|
struct list_head list;
|
|
|
|
struct event_filter *filter;
|
|
|
|
};
|
|
|
|
|
2015-05-13 20:59:40 +02:00
|
|
|
static int replace_system_preds(struct trace_subsystem_dir *dir,
|
2013-10-24 15:34:17 +02:00
|
|
|
struct trace_array *tr,
|
2009-10-15 05:20:34 +02:00
|
|
|
struct filter_parse_state *ps,
|
|
|
|
char *filter_string)
|
|
|
|
{
|
2015-05-05 16:09:53 +02:00
|
|
|
struct trace_event_file *file;
|
2011-02-04 05:25:46 +01:00
|
|
|
struct filter_list *filter_item;
|
|
|
|
struct filter_list *tmp;
|
|
|
|
LIST_HEAD(filter_list);
|
2009-10-15 05:20:34 +02:00
|
|
|
bool fail = true;
|
2009-10-15 12:24:04 +02:00
|
|
|
int err;
|
2009-10-15 05:20:34 +02:00
|
|
|
|
2013-10-24 15:34:17 +02:00
|
|
|
list_for_each_entry(file, &tr->events, list) {
|
2014-07-15 20:48:29 +02:00
|
|
|
if (file->system != dir)
|
2009-10-15 05:20:34 +02:00
|
|
|
continue;
|
|
|
|
|
2011-02-04 05:25:46 +01:00
|
|
|
/*
|
|
|
|
* Try to see if the filter can be applied
|
|
|
|
* (filter arg is ignored on dry_run)
|
|
|
|
*/
|
2014-07-15 20:48:32 +02:00
|
|
|
err = replace_preds(file->event_call, NULL, ps, true);
|
2009-10-15 05:20:34 +02:00
|
|
|
if (err)
|
2013-10-24 15:34:17 +02:00
|
|
|
event_set_no_set_filter_flag(file);
|
2011-11-01 02:09:35 +01:00
|
|
|
else
|
2013-10-24 15:34:17 +02:00
|
|
|
event_clear_no_set_filter_flag(file);
|
2011-01-28 04:46:46 +01:00
|
|
|
}
|
|
|
|
|
2013-10-24 15:34:17 +02:00
|
|
|
list_for_each_entry(file, &tr->events, list) {
|
2011-02-04 05:25:46 +01:00
|
|
|
struct event_filter *filter;
|
2011-01-28 04:46:46 +01:00
|
|
|
|
2014-07-15 20:48:29 +02:00
|
|
|
if (file->system != dir)
|
2011-01-28 04:46:46 +01:00
|
|
|
continue;
|
|
|
|
|
2013-10-24 15:34:17 +02:00
|
|
|
if (event_no_set_filter_flag(file))
|
2011-11-01 02:09:35 +01:00
|
|
|
continue;
|
|
|
|
|
2011-02-04 05:25:46 +01:00
|
|
|
filter_item = kzalloc(sizeof(*filter_item), GFP_KERNEL);
|
|
|
|
if (!filter_item)
|
|
|
|
goto fail_mem;
|
2011-01-28 04:46:46 +01:00
|
|
|
|
2011-02-04 05:25:46 +01:00
|
|
|
list_add_tail(&filter_item->list, &filter_list);
|
2011-01-28 04:46:46 +01:00
|
|
|
|
2011-02-04 05:25:46 +01:00
|
|
|
filter_item->filter = __alloc_filter();
|
|
|
|
if (!filter_item->filter)
|
|
|
|
goto fail_mem;
|
|
|
|
filter = filter_item->filter;
|
2011-01-28 04:46:46 +01:00
|
|
|
|
2011-02-04 05:25:46 +01:00
|
|
|
/* Can only fail on no memory */
|
|
|
|
err = replace_filter_string(filter, filter_string);
|
|
|
|
if (err)
|
|
|
|
goto fail_mem;
|
2009-10-15 05:20:34 +02:00
|
|
|
|
2014-07-15 20:48:32 +02:00
|
|
|
err = replace_preds(file->event_call, filter, ps, false);
|
2011-02-04 05:25:46 +01:00
|
|
|
if (err) {
|
2013-10-24 15:34:17 +02:00
|
|
|
filter_disable(file);
|
2011-02-04 05:25:46 +01:00
|
|
|
parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0);
|
|
|
|
append_filter_err(ps, filter);
|
|
|
|
} else
|
2013-10-24 15:34:17 +02:00
|
|
|
event_set_filtered_flag(file);
|
2011-02-04 05:25:46 +01:00
|
|
|
/*
|
|
|
|
* Regardless of if this returned an error, we still
|
|
|
|
* replace the filter for the call.
|
|
|
|
*/
|
2013-10-24 15:34:17 +02:00
|
|
|
filter = event_filter(file);
|
|
|
|
event_set_filter(file, filter_item->filter);
|
2011-02-04 05:25:46 +01:00
|
|
|
filter_item->filter = filter;
|
|
|
|
|
2009-10-15 05:20:34 +02:00
|
|
|
fail = false;
|
|
|
|
}
|
|
|
|
|
2011-01-28 04:46:46 +01:00
|
|
|
if (fail)
|
|
|
|
goto fail;
|
|
|
|
|
2011-02-04 05:25:46 +01:00
|
|
|
/*
|
|
|
|
* The calls can still be using the old filters.
|
|
|
|
* Do a synchronize_sched() to ensure all calls are
|
|
|
|
* done with them before we free them.
|
|
|
|
*/
|
|
|
|
synchronize_sched();
|
|
|
|
list_for_each_entry_safe(filter_item, tmp, &filter_list, list) {
|
|
|
|
__free_filter(filter_item->filter);
|
|
|
|
list_del(&filter_item->list);
|
|
|
|
kfree(filter_item);
|
|
|
|
}
|
2009-10-15 05:20:34 +02:00
|
|
|
return 0;
|
2011-01-28 04:46:46 +01:00
|
|
|
fail:
|
2011-02-04 05:25:46 +01:00
|
|
|
/* No call succeeded */
|
|
|
|
list_for_each_entry_safe(filter_item, tmp, &filter_list, list) {
|
|
|
|
list_del(&filter_item->list);
|
|
|
|
kfree(filter_item);
|
|
|
|
}
|
2011-01-28 04:46:46 +01:00
|
|
|
parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0);
|
|
|
|
return -EINVAL;
|
2011-02-04 05:25:46 +01:00
|
|
|
fail_mem:
|
|
|
|
/* If any call succeeded, we still need to sync */
|
|
|
|
if (!fail)
|
|
|
|
synchronize_sched();
|
|
|
|
list_for_each_entry_safe(filter_item, tmp, &filter_list, list) {
|
|
|
|
__free_filter(filter_item->filter);
|
|
|
|
list_del(&filter_item->list);
|
|
|
|
kfree(filter_item);
|
|
|
|
}
|
|
|
|
return -ENOMEM;
|
2009-10-15 05:20:34 +02:00
|
|
|
}
|
|
|
|
|
2011-12-15 23:31:35 +01:00
|
|
|
static int create_filter_start(char *filter_str, bool set_str,
|
|
|
|
struct filter_parse_state **psp,
|
|
|
|
struct event_filter **filterp)
|
|
|
|
{
|
|
|
|
struct event_filter *filter;
|
|
|
|
struct filter_parse_state *ps = NULL;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
WARN_ON_ONCE(*psp || *filterp);
|
|
|
|
|
|
|
|
/* allocate everything, and if any fails, free all and fail */
|
|
|
|
filter = __alloc_filter();
|
|
|
|
if (filter && set_str)
|
|
|
|
err = replace_filter_string(filter, filter_str);
|
|
|
|
|
|
|
|
ps = kzalloc(sizeof(*ps), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!filter || !ps || err) {
|
|
|
|
kfree(ps);
|
|
|
|
__free_filter(filter);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we're committed to creating a new filter */
|
|
|
|
*filterp = filter;
|
|
|
|
*psp = ps;
|
|
|
|
|
|
|
|
parse_init(ps, filter_ops, filter_str);
|
|
|
|
err = filter_parse(ps);
|
|
|
|
if (err && set_str)
|
|
|
|
append_filter_err(ps, filter);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_filter_finish(struct filter_parse_state *ps)
|
|
|
|
{
|
|
|
|
if (ps) {
|
|
|
|
filter_opstack_clear(ps);
|
|
|
|
postfix_clear(ps);
|
|
|
|
kfree(ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-05 17:45:27 +02:00
|
|
|
* create_filter - create a filter for a trace_event_call
|
|
|
|
* @call: trace_event_call to create a filter for
|
2011-12-15 23:31:35 +01:00
|
|
|
* @filter_str: filter string
|
|
|
|
* @set_str: remember @filter_str and enable detailed error in filter
|
|
|
|
* @filterp: out param for created filter (always updated on return)
|
|
|
|
*
|
|
|
|
* Creates a filter for @call with @filter_str. If @set_str is %true,
|
|
|
|
* @filter_str is copied and recorded in the new filter.
|
|
|
|
*
|
|
|
|
* On success, returns 0 and *@filterp points to the new filter. On
|
|
|
|
* failure, returns -errno and *@filterp may point to %NULL or to a new
|
|
|
|
* filter. In the latter case, the returned filter contains error
|
|
|
|
* information if @set_str is %true and the caller is responsible for
|
|
|
|
* freeing it.
|
|
|
|
*/
|
2015-05-05 17:45:27 +02:00
|
|
|
static int create_filter(struct trace_event_call *call,
|
2011-12-15 23:31:35 +01:00
|
|
|
char *filter_str, bool set_str,
|
|
|
|
struct event_filter **filterp)
|
|
|
|
{
|
|
|
|
struct event_filter *filter = NULL;
|
|
|
|
struct filter_parse_state *ps = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = create_filter_start(filter_str, set_str, &ps, &filter);
|
|
|
|
if (!err) {
|
2014-07-15 20:48:32 +02:00
|
|
|
err = replace_preds(call, filter, ps, false);
|
2011-12-15 23:31:35 +01:00
|
|
|
if (err && set_str)
|
|
|
|
append_filter_err(ps, filter);
|
|
|
|
}
|
|
|
|
create_filter_finish(ps);
|
|
|
|
|
|
|
|
*filterp = filter;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-05-05 17:45:27 +02:00
|
|
|
int create_event_filter(struct trace_event_call *call,
|
tracing: Add and use generic set_trigger_filter() implementation
Add a generic event_command.set_trigger_filter() op implementation and
have the current set of trigger commands use it - this essentially
gives them all support for filters.
Syntactically, filters are supported by adding 'if <filter>' just
after the command, in which case only events matching the filter will
invoke the trigger. For example, to add a filter to an
enable/disable_event command:
echo 'enable_event:system:event if common_pid == 999' > \
.../othersys/otherevent/trigger
The above command will only enable the system:event event if the
common_pid field in the othersys:otherevent event is 999.
As another example, to add a filter to a stacktrace command:
echo 'stacktrace if common_pid == 999' > \
.../somesys/someevent/trigger
The above command will only trigger a stacktrace if the common_pid
field in the event is 999.
The filter syntax is the same as that described in the 'Event
filtering' section of Documentation/trace/events.txt.
Because triggers can now use filters, the trigger-invoking logic needs
to be moved in those cases - e.g. for ftrace_raw_event_calls, if a
trigger has a filter associated with it, the trigger invocation now
needs to happen after the { assign; } part of the call, in order for
the trigger condition to be tested.
There's still a SOFT_DISABLED-only check at the top of e.g. the
ftrace_raw_events function, so when an event is soft disabled but not
because of the presence of a trigger, the original SOFT_DISABLED
behavior remains unchanged.
There's also a bit of trickiness in that some triggers need to avoid
being invoked while an event is currently in the process of being
logged, since the trigger may itself log data into the trace buffer.
Thus we make sure the current event is committed before invoking those
triggers. To do that, we split the trigger invocation in two - the
first part (event_triggers_call()) checks the filter using the current
trace record; if a command has the post_trigger flag set, it sets a
bit for itself in the return value, otherwise it directly invoks the
trigger. Once all commands have been either invoked or set their
return flag, event_triggers_call() returns. The current record is
then either committed or discarded; if any commands have deferred
their triggers, those commands are finally invoked following the close
of the current event by event_triggers_post_call().
To simplify the above and make it more efficient, the TRIGGER_COND bit
is introduced, which is set only if a soft-disabled trigger needs to
use the log record for filter testing or needs to wait until the
current log record is closed.
The syscall event invocation code is also changed in analogous ways.
Because event triggers need to be able to create and free filters,
this also adds a couple external wrappers for the existing
create_filter and free_filter functions, which are too generic to be
made extern functions themselves.
Link: http://lkml.kernel.org/r/7164930759d8719ef460357f143d995406e4eead.1382622043.git.tom.zanussi@linux.intel.com
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-10-24 15:59:29 +02:00
|
|
|
char *filter_str, bool set_str,
|
|
|
|
struct event_filter **filterp)
|
|
|
|
{
|
|
|
|
return create_filter(call, filter_str, set_str, filterp);
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:31:35 +01:00
|
|
|
/**
|
|
|
|
* create_system_filter - create a filter for an event_subsystem
|
|
|
|
* @system: event_subsystem to create a filter for
|
|
|
|
* @filter_str: filter string
|
|
|
|
* @filterp: out param for created filter (always updated on return)
|
|
|
|
*
|
|
|
|
* Identical to create_filter() except that it creates a subsystem filter
|
|
|
|
* and always remembers @filter_str.
|
|
|
|
*/
|
2015-05-13 20:59:40 +02:00
|
|
|
static int create_system_filter(struct trace_subsystem_dir *dir,
|
2013-10-24 15:34:17 +02:00
|
|
|
struct trace_array *tr,
|
2011-12-15 23:31:35 +01:00
|
|
|
char *filter_str, struct event_filter **filterp)
|
|
|
|
{
|
|
|
|
struct event_filter *filter = NULL;
|
|
|
|
struct filter_parse_state *ps = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = create_filter_start(filter_str, true, &ps, &filter);
|
|
|
|
if (!err) {
|
2014-07-15 20:48:29 +02:00
|
|
|
err = replace_system_preds(dir, tr, ps, filter_str);
|
2011-12-15 23:31:35 +01:00
|
|
|
if (!err) {
|
|
|
|
/* System filters just show a default message */
|
|
|
|
kfree(filter->filter_string);
|
|
|
|
filter->filter_string = NULL;
|
|
|
|
} else {
|
|
|
|
append_filter_err(ps, filter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
create_filter_finish(ps);
|
|
|
|
|
|
|
|
*filterp = filter;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-07-26 19:25:40 +02:00
|
|
|
/* caller must hold event_mutex */
|
2015-05-05 16:09:53 +02:00
|
|
|
int apply_event_filter(struct trace_event_file *file, char *filter_string)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = file->event_call;
|
2011-02-04 05:25:46 +01:00
|
|
|
struct event_filter *filter;
|
2013-07-26 19:25:40 +02:00
|
|
|
int err;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
|
|
|
if (!strcmp(strstrip(filter_string), "0")) {
|
2013-10-24 15:34:17 +02:00
|
|
|
filter_disable(file);
|
|
|
|
filter = event_filter(file);
|
|
|
|
|
2011-02-04 05:25:46 +01:00
|
|
|
if (!filter)
|
2013-07-26 19:25:40 +02:00
|
|
|
return 0;
|
2013-10-24 15:34:17 +02:00
|
|
|
|
|
|
|
event_clear_filter(file);
|
|
|
|
|
2011-01-28 04:53:06 +01:00
|
|
|
/* Make sure the filter is not being used */
|
|
|
|
synchronize_sched();
|
2011-02-04 05:25:46 +01:00
|
|
|
__free_filter(filter);
|
2013-10-24 15:34:17 +02:00
|
|
|
|
2013-07-26 19:25:40 +02:00
|
|
|
return 0;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
}
|
|
|
|
|
2011-12-15 23:31:35 +01:00
|
|
|
err = create_filter(call, filter_string, true, &filter);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
2011-02-04 05:25:46 +01:00
|
|
|
/*
|
|
|
|
* Always swap the call filter with the new filter
|
|
|
|
* even if there was an error. If there was an error
|
|
|
|
* in the filter, we disable the filter and show the error
|
|
|
|
* string
|
|
|
|
*/
|
2011-12-15 23:31:35 +01:00
|
|
|
if (filter) {
|
2013-10-24 15:34:17 +02:00
|
|
|
struct event_filter *tmp;
|
2011-12-15 23:31:35 +01:00
|
|
|
|
2013-10-24 15:34:17 +02:00
|
|
|
tmp = event_filter(file);
|
2011-12-15 23:31:35 +01:00
|
|
|
if (!err)
|
2013-10-24 15:34:17 +02:00
|
|
|
event_set_filtered_flag(file);
|
2011-12-15 23:31:35 +01:00
|
|
|
else
|
2013-10-24 15:34:17 +02:00
|
|
|
filter_disable(file);
|
2011-12-15 23:31:35 +01:00
|
|
|
|
2013-10-24 15:34:17 +02:00
|
|
|
event_set_filter(file, filter);
|
2011-12-15 23:31:35 +01:00
|
|
|
|
|
|
|
if (tmp) {
|
|
|
|
/* Make sure the call is done with the filter */
|
|
|
|
synchronize_sched();
|
|
|
|
__free_filter(tmp);
|
|
|
|
}
|
2011-02-04 05:25:46 +01:00
|
|
|
}
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-05-13 20:59:40 +02:00
|
|
|
int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
char *filter_string)
|
|
|
|
{
|
2012-05-04 05:09:03 +02:00
|
|
|
struct event_subsystem *system = dir->subsystem;
|
2013-10-24 15:34:17 +02:00
|
|
|
struct trace_array *tr = dir->tr;
|
2011-02-04 05:25:46 +01:00
|
|
|
struct event_filter *filter;
|
|
|
|
int err = 0;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
2009-06-16 10:39:41 +02:00
|
|
|
mutex_lock(&event_mutex);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
2011-07-05 17:36:06 +02:00
|
|
|
/* Make sure the system still has events */
|
2012-05-04 05:09:03 +02:00
|
|
|
if (!dir->nr_events) {
|
2011-07-05 17:36:06 +02:00
|
|
|
err = -ENODEV;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
if (!strcmp(strstrip(filter_string), "0")) {
|
2014-07-15 20:48:29 +02:00
|
|
|
filter_free_subsystem_preds(dir, tr);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
remove_filter_string(system->filter);
|
2011-02-04 05:25:46 +01:00
|
|
|
filter = system->filter;
|
|
|
|
system->filter = NULL;
|
|
|
|
/* Ensure all filters are no longer used */
|
|
|
|
synchronize_sched();
|
2014-07-15 20:48:29 +02:00
|
|
|
filter_free_subsystem_filters(dir, tr);
|
2011-02-04 05:25:46 +01:00
|
|
|
__free_filter(filter);
|
2009-10-15 12:24:04 +02:00
|
|
|
goto out_unlock;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
}
|
|
|
|
|
2014-07-15 20:48:29 +02:00
|
|
|
err = create_system_filter(dir, tr, filter_string, &filter);
|
2011-12-15 23:31:35 +01:00
|
|
|
if (filter) {
|
|
|
|
/*
|
|
|
|
* No event actually uses the system filter
|
|
|
|
* we can free it without synchronize_sched().
|
|
|
|
*/
|
|
|
|
__free_filter(system->filter);
|
|
|
|
system->filter = filter;
|
|
|
|
}
|
2009-05-15 05:07:27 +02:00
|
|
|
out_unlock:
|
2009-06-16 10:39:41 +02:00
|
|
|
mutex_unlock(&event_mutex);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 10:04:59 +02:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2009-03-22 09:31:04 +01:00
|
|
|
|
2009-12-21 07:27:35 +01:00
|
|
|
#ifdef CONFIG_PERF_EVENTS
|
2009-10-15 05:21:42 +02:00
|
|
|
|
|
|
|
void ftrace_profile_free_filter(struct perf_event *event)
|
|
|
|
{
|
|
|
|
struct event_filter *filter = event->filter;
|
|
|
|
|
|
|
|
event->filter = NULL;
|
2011-01-28 04:42:43 +01:00
|
|
|
__free_filter(filter);
|
2009-10-15 05:21:42 +02:00
|
|
|
}
|
|
|
|
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 15:51:54 +01:00
|
|
|
struct function_filter_data {
|
|
|
|
struct ftrace_ops *ops;
|
|
|
|
int first_filter;
|
|
|
|
int first_notrace;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_FUNCTION_TRACER
|
|
|
|
static char **
|
|
|
|
ftrace_function_filter_re(char *buf, int len, int *count)
|
|
|
|
{
|
2015-06-26 00:02:25 +02:00
|
|
|
char *str, **re;
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 15:51:54 +01:00
|
|
|
|
|
|
|
str = kstrndup(buf, len, GFP_KERNEL);
|
|
|
|
if (!str)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The argv_split function takes white space
|
|
|
|
* as a separator, so convert ',' into spaces.
|
|
|
|
*/
|
2015-06-26 00:02:25 +02:00
|
|
|
strreplace(str, ',', ' ');
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 15:51:54 +01:00
|
|
|
|
|
|
|
re = argv_split(GFP_KERNEL, str, count);
|
|
|
|
kfree(str);
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ftrace_function_set_regexp(struct ftrace_ops *ops, int filter,
|
|
|
|
int reset, char *re, int len)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (filter)
|
|
|
|
ret = ftrace_set_filter(ops, re, len, reset);
|
|
|
|
else
|
|
|
|
ret = ftrace_set_notrace(ops, re, len, reset);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __ftrace_function_set_filter(int filter, char *buf, int len,
|
|
|
|
struct function_filter_data *data)
|
|
|
|
{
|
2012-06-19 17:47:52 +02:00
|
|
|
int i, re_cnt, ret = -EINVAL;
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 15:51:54 +01:00
|
|
|
int *reset;
|
|
|
|
char **re;
|
|
|
|
|
|
|
|
reset = filter ? &data->first_filter : &data->first_notrace;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The 'ip' field could have multiple filters set, separated
|
|
|
|
* either by space or comma. We first cut the filter and apply
|
|
|
|
* all pieces separatelly.
|
|
|
|
*/
|
|
|
|
re = ftrace_function_filter_re(buf, len, &re_cnt);
|
|
|
|
if (!re)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (i = 0; i < re_cnt; i++) {
|
|
|
|
ret = ftrace_function_set_regexp(data->ops, filter, *reset,
|
|
|
|
re[i], strlen(re[i]));
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (*reset)
|
|
|
|
*reset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
argv_free(re);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ftrace_function_check_pred(struct filter_pred *pred, int leaf)
|
|
|
|
{
|
|
|
|
struct ftrace_event_field *field = pred->field;
|
|
|
|
|
|
|
|
if (leaf) {
|
|
|
|
/*
|
|
|
|
* Check the leaf predicate for function trace, verify:
|
|
|
|
* - only '==' and '!=' is used
|
|
|
|
* - the 'ip' field is used
|
|
|
|
*/
|
|
|
|
if ((pred->op != OP_EQ) && (pred->op != OP_NE))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (strcmp(field->name, "ip"))
|
|
|
|
return -EINVAL;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Check the non leaf predicate for function trace, verify:
|
|
|
|
* - only '||' is used
|
|
|
|
*/
|
|
|
|
if (pred->op != OP_OR)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ftrace_function_set_filter_cb(enum move_type move,
|
|
|
|
struct filter_pred *pred,
|
|
|
|
int *err, void *data)
|
|
|
|
{
|
|
|
|
/* Checking the node is valid for function trace. */
|
|
|
|
if ((move != MOVE_DOWN) ||
|
|
|
|
(pred->left != FILTER_PRED_INVALID)) {
|
|
|
|
*err = ftrace_function_check_pred(pred, 0);
|
|
|
|
} else {
|
|
|
|
*err = ftrace_function_check_pred(pred, 1);
|
|
|
|
if (*err)
|
|
|
|
return WALK_PRED_ABORT;
|
|
|
|
|
|
|
|
*err = __ftrace_function_set_filter(pred->op == OP_EQ,
|
|
|
|
pred->regex.pattern,
|
|
|
|
pred->regex.len,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (*err) ? WALK_PRED_ABORT : WALK_PRED_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ftrace_function_set_filter(struct perf_event *event,
|
|
|
|
struct event_filter *filter)
|
|
|
|
{
|
|
|
|
struct function_filter_data data = {
|
|
|
|
.first_filter = 1,
|
|
|
|
.first_notrace = 1,
|
|
|
|
.ops = &event->ftrace_ops,
|
|
|
|
};
|
|
|
|
|
|
|
|
return walk_pred_tree(filter->preds, filter->root,
|
|
|
|
ftrace_function_set_filter_cb, &data);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int ftrace_function_set_filter(struct perf_event *event,
|
|
|
|
struct event_filter *filter)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FUNCTION_TRACER */
|
|
|
|
|
2009-10-15 05:21:42 +02:00
|
|
|
int ftrace_profile_set_filter(struct perf_event *event, int event_id,
|
|
|
|
char *filter_str)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct event_filter *filter;
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call;
|
2009-10-15 05:21:42 +02:00
|
|
|
|
|
|
|
mutex_lock(&event_mutex);
|
|
|
|
|
2011-08-11 16:25:48 +02:00
|
|
|
call = event->tp_event;
|
2009-10-15 12:24:04 +02:00
|
|
|
|
|
|
|
err = -EINVAL;
|
2011-08-11 16:25:48 +02:00
|
|
|
if (!call)
|
2009-10-15 12:24:04 +02:00
|
|
|
goto out_unlock;
|
2009-10-15 05:21:42 +02:00
|
|
|
|
2009-10-15 12:24:04 +02:00
|
|
|
err = -EEXIST;
|
2009-10-15 05:21:42 +02:00
|
|
|
if (event->filter)
|
2009-10-15 12:24:04 +02:00
|
|
|
goto out_unlock;
|
2009-10-15 05:21:42 +02:00
|
|
|
|
2011-12-15 23:31:35 +01:00
|
|
|
err = create_filter(call, filter_str, false, &filter);
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 15:51:54 +01:00
|
|
|
if (err)
|
|
|
|
goto free_filter;
|
|
|
|
|
|
|
|
if (ftrace_event_is_function(call))
|
|
|
|
err = ftrace_function_set_filter(event, filter);
|
2011-12-15 23:31:35 +01:00
|
|
|
else
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 15:51:54 +01:00
|
|
|
event->filter = filter;
|
|
|
|
|
|
|
|
free_filter:
|
|
|
|
if (err || ftrace_event_is_function(call))
|
2011-01-28 04:42:43 +01:00
|
|
|
__free_filter(filter);
|
2009-10-15 05:21:42 +02:00
|
|
|
|
2009-10-15 12:24:04 +02:00
|
|
|
out_unlock:
|
2009-10-15 05:21:42 +02:00
|
|
|
mutex_unlock(&event_mutex);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2009-12-21 07:27:35 +01:00
|
|
|
#endif /* CONFIG_PERF_EVENTS */
|
2009-10-15 05:21:42 +02:00
|
|
|
|
2011-08-11 16:25:54 +02:00
|
|
|
#ifdef CONFIG_FTRACE_STARTUP_TEST
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/tracepoint.h>
|
|
|
|
|
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include "trace_events_filter_test.h"
|
|
|
|
|
|
|
|
#define DATA_REC(m, va, vb, vc, vd, ve, vf, vg, vh, nvisit) \
|
|
|
|
{ \
|
|
|
|
.filter = FILTER, \
|
|
|
|
.rec = { .a = va, .b = vb, .c = vc, .d = vd, \
|
|
|
|
.e = ve, .f = vf, .g = vg, .h = vh }, \
|
|
|
|
.match = m, \
|
|
|
|
.not_visited = nvisit, \
|
|
|
|
}
|
|
|
|
#define YES 1
|
|
|
|
#define NO 0
|
|
|
|
|
|
|
|
static struct test_filter_data_t {
|
|
|
|
char *filter;
|
2015-05-13 21:27:47 +02:00
|
|
|
struct trace_event_raw_ftrace_test_filter rec;
|
2011-08-11 16:25:54 +02:00
|
|
|
int match;
|
|
|
|
char *not_visited;
|
|
|
|
} test_filter_data[] = {
|
|
|
|
#define FILTER "a == 1 && b == 1 && c == 1 && d == 1 && " \
|
|
|
|
"e == 1 && f == 1 && g == 1 && h == 1"
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 1, 1, 1, ""),
|
|
|
|
DATA_REC(NO, 0, 1, 1, 1, 1, 1, 1, 1, "bcdefgh"),
|
|
|
|
DATA_REC(NO, 1, 1, 1, 1, 1, 1, 1, 0, ""),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "a == 1 || b == 1 || c == 1 || d == 1 || " \
|
|
|
|
"e == 1 || f == 1 || g == 1 || h == 1"
|
|
|
|
DATA_REC(NO, 0, 0, 0, 0, 0, 0, 0, 0, ""),
|
|
|
|
DATA_REC(YES, 0, 0, 0, 0, 0, 0, 0, 1, ""),
|
|
|
|
DATA_REC(YES, 1, 0, 0, 0, 0, 0, 0, 0, "bcdefgh"),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "(a == 1 || b == 1) && (c == 1 || d == 1) && " \
|
|
|
|
"(e == 1 || f == 1) && (g == 1 || h == 1)"
|
|
|
|
DATA_REC(NO, 0, 0, 1, 1, 1, 1, 1, 1, "dfh"),
|
|
|
|
DATA_REC(YES, 0, 1, 0, 1, 0, 1, 0, 1, ""),
|
|
|
|
DATA_REC(YES, 1, 0, 1, 0, 0, 1, 0, 1, "bd"),
|
|
|
|
DATA_REC(NO, 1, 0, 1, 0, 0, 1, 0, 0, "bd"),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "(a == 1 && b == 1) || (c == 1 && d == 1) || " \
|
|
|
|
"(e == 1 && f == 1) || (g == 1 && h == 1)"
|
|
|
|
DATA_REC(YES, 1, 0, 1, 1, 1, 1, 1, 1, "efgh"),
|
|
|
|
DATA_REC(YES, 0, 0, 0, 0, 0, 0, 1, 1, ""),
|
|
|
|
DATA_REC(NO, 0, 0, 0, 0, 0, 0, 0, 1, ""),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "(a == 1 && b == 1) && (c == 1 && d == 1) && " \
|
|
|
|
"(e == 1 && f == 1) || (g == 1 && h == 1)"
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 1, 0, 0, "gh"),
|
|
|
|
DATA_REC(NO, 0, 0, 0, 0, 0, 0, 0, 1, ""),
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 0, 1, 1, ""),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "((a == 1 || b == 1) || (c == 1 || d == 1) || " \
|
|
|
|
"(e == 1 || f == 1)) && (g == 1 || h == 1)"
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 1, 0, 1, "bcdef"),
|
|
|
|
DATA_REC(NO, 0, 0, 0, 0, 0, 0, 0, 0, ""),
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 0, 1, 1, "h"),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "((((((((a == 1) && (b == 1)) || (c == 1)) && (d == 1)) || " \
|
|
|
|
"(e == 1)) && (f == 1)) || (g == 1)) && (h == 1))"
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 1, 1, 1, "ceg"),
|
|
|
|
DATA_REC(NO, 0, 1, 0, 1, 0, 1, 0, 1, ""),
|
|
|
|
DATA_REC(NO, 1, 0, 1, 0, 1, 0, 1, 0, ""),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "((((((((a == 1) || (b == 1)) && (c == 1)) || (d == 1)) && " \
|
|
|
|
"(e == 1)) || (f == 1)) && (g == 1)) || (h == 1))"
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 1, 1, 1, "bdfh"),
|
|
|
|
DATA_REC(YES, 0, 1, 0, 1, 0, 1, 0, 1, ""),
|
|
|
|
DATA_REC(YES, 1, 0, 1, 0, 1, 0, 1, 0, "bdfh"),
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef DATA_REC
|
|
|
|
#undef FILTER
|
|
|
|
#undef YES
|
|
|
|
#undef NO
|
|
|
|
|
|
|
|
#define DATA_CNT (sizeof(test_filter_data)/sizeof(struct test_filter_data_t))
|
|
|
|
|
|
|
|
static int test_pred_visited;
|
|
|
|
|
|
|
|
static int test_pred_visited_fn(struct filter_pred *pred, void *event)
|
|
|
|
{
|
|
|
|
struct ftrace_event_field *field = pred->field;
|
|
|
|
|
|
|
|
test_pred_visited = 1;
|
|
|
|
printk(KERN_INFO "\npred visited %s\n", field->name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_walk_pred_cb(enum move_type move, struct filter_pred *pred,
|
|
|
|
int *err, void *data)
|
|
|
|
{
|
|
|
|
char *fields = data;
|
|
|
|
|
|
|
|
if ((move == MOVE_DOWN) &&
|
|
|
|
(pred->left == FILTER_PRED_INVALID)) {
|
|
|
|
struct ftrace_event_field *field = pred->field;
|
|
|
|
|
|
|
|
if (!field) {
|
|
|
|
WARN(1, "all leafs should have field defined");
|
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
}
|
|
|
|
if (!strchr(fields, *field->name))
|
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
|
|
|
|
WARN_ON(!pred->fn);
|
|
|
|
pred->fn = test_pred_visited_fn;
|
|
|
|
}
|
|
|
|
return WALK_PRED_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __init int ftrace_test_event_filter(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printk(KERN_INFO "Testing ftrace filter: ");
|
|
|
|
|
|
|
|
for (i = 0; i < DATA_CNT; i++) {
|
|
|
|
struct event_filter *filter = NULL;
|
|
|
|
struct test_filter_data_t *d = &test_filter_data[i];
|
|
|
|
int err;
|
|
|
|
|
2011-12-15 23:31:35 +01:00
|
|
|
err = create_filter(&event_ftrace_test_filter, d->filter,
|
|
|
|
false, &filter);
|
2011-08-11 16:25:54 +02:00
|
|
|
if (err) {
|
|
|
|
printk(KERN_INFO
|
|
|
|
"Failed to get filter for '%s', err %d\n",
|
|
|
|
d->filter, err);
|
2011-12-15 23:31:35 +01:00
|
|
|
__free_filter(filter);
|
2011-08-11 16:25:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-22 15:41:46 +02:00
|
|
|
/*
|
|
|
|
* The preemption disabling is not really needed for self
|
|
|
|
* tests, but the rcu dereference will complain without it.
|
|
|
|
*/
|
|
|
|
preempt_disable();
|
2011-08-11 16:25:54 +02:00
|
|
|
if (*d->not_visited)
|
|
|
|
walk_pred_tree(filter->preds, filter->root,
|
|
|
|
test_walk_pred_cb,
|
|
|
|
d->not_visited);
|
|
|
|
|
|
|
|
test_pred_visited = 0;
|
|
|
|
err = filter_match_preds(filter, &d->rec);
|
2011-08-22 15:41:46 +02:00
|
|
|
preempt_enable();
|
2011-08-11 16:25:54 +02:00
|
|
|
|
|
|
|
__free_filter(filter);
|
|
|
|
|
|
|
|
if (test_pred_visited) {
|
|
|
|
printk(KERN_INFO
|
|
|
|
"Failed, unwanted pred visited for filter %s\n",
|
|
|
|
d->filter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != d->match) {
|
|
|
|
printk(KERN_INFO
|
|
|
|
"Failed to match filter '%s', expected %d\n",
|
|
|
|
d->filter, d->match);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == DATA_CNT)
|
|
|
|
printk(KERN_CONT "OK\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
late_initcall(ftrace_test_event_filter);
|
|
|
|
|
|
|
|
#endif /* CONFIG_FTRACE_STARTUP_TEST */
|