Skip to contentSkip to conversation

tracing/filters: a better event parser

PATCH In review Tom Zanussi 1 participant 3 messages Apr 28, 2009 – Apr 29, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 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.

---
 include/linux/ftrace_event.h       |    2 +-
 kernel/trace/trace.h               |   66 ++-
 kernel/trace/trace_events.c        |   86 ++--
 kernel/trace/trace_events_filter.c | 1020 ++++++++++++++++++++++++++++--------
 4 files changed, 884 insertions(+), 290 deletions(-)
include/linux/ftrace_event.h +1 -1
index 51bff2e..5b20fb2 100644
@@ -112,7 +112,7 @@ struct ftrace_event_call {
 #endif
 };
 
-#define MAX_FILTER_PRED		8
+#define MAX_FILTER_PRED		16
 #define MAX_FILTER_STR_VAL	128
 
 extern int init_preds(struct ftrace_event_call *call);
kernel/trace/trace.h +52 -14

94 lines not on this page · raw message

kernel/trace/trace_events.c +35 -51

138 lines not on this page · raw message

kernel/trace/trace_events_filter.c +796 -224

1,194 lines not on this page · raw message

Signature · 1 line
1.5.6.3
#1 lore raw
Commit-ID:  820001a6dfa57700956c3d5627be7e28c12d12e5
Gitweb:     http://git.kernel.org/tip/820001a6dfa57700956c3d5627be7e28c12d12e5
Author:     Tom Zanussi <[email protected]>
AuthorDate: Tue, 28 Apr 2009 03:04:59 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 29 Apr 2009 12:37:55 +0200

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 ]

LKML-Reference: <1240905899.6416.121.camel@tropicana>

---
 include/linux/ftrace_event.h       |    2 +-
 kernel/trace/trace.h               |   66 ++-
 kernel/trace/trace_events.c        |   86 ++--
 kernel/trace/trace_events_filter.c | 1020 ++++++++++++++++++++++++++++--------
 4 files changed, 884 insertions(+), 290 deletions(-)
include/linux/ftrace_event.h +1 -1
index e61a740..5fff40c 100644
@@ -112,7 +112,7 @@ struct ftrace_event_call {
 #endif
 };
 
-#define MAX_FILTER_PRED		8
+#define MAX_FILTER_PRED		32
 #define MAX_FILTER_STR_VAL	128
 
 extern int init_preds(struct ftrace_event_call *call);
kernel/trace/trace.h +52 -14

94 lines not on this page · raw message

kernel/trace/trace_events.c +35 -51

138 lines not on this page · raw message

kernel/trace/trace_events_filter.c +796 -224

1,194 lines not on this page · raw message

#2 lore raw
In reply to Tom Zanussi
Commit-ID:  8b3725621074040d380664964ffbc40610aef8c6
Gitweb:     http://git.kernel.org/tip/8b3725621074040d380664964ffbc40610aef8c6
Author:     Tom Zanussi <[email protected]>
AuthorDate: Tue, 28 Apr 2009 03:04:59 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 29 Apr 2009 14:06:11 +0200

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 ]

LKML-Reference: <1240905899.6416.121.camel@tropicana>

---
 include/linux/ftrace_event.h       |    2 +-
 kernel/trace/trace.h               |   66 ++-
 kernel/trace/trace_events.c        |   86 ++--
 kernel/trace/trace_events_filter.c | 1020 ++++++++++++++++++++++++++++--------
 4 files changed, 884 insertions(+), 290 deletions(-)
include/linux/ftrace_event.h +1 -1
index e61a740..5fff40c 100644
@@ -112,7 +112,7 @@ struct ftrace_event_call {
 #endif
 };
 
-#define MAX_FILTER_PRED		8
+#define MAX_FILTER_PRED		32
 #define MAX_FILTER_STR_VAL	128
 
 extern int init_preds(struct ftrace_event_call *call);
kernel/trace/trace.h +52 -14

94 lines not on this page · raw message

kernel/trace/trace_events.c +35 -51

138 lines not on this page · raw message

kernel/trace/trace_events_filter.c +796 -224

1,194 lines not on this page · raw message