Skip to contentSkip to conversation

tracing/filters: adjustements for strings

GIT PULL New Frederic Weisbecker 4 participants 7 messages May 3, 2009 – May 5, 2009 Tracing

lore
Share & tools
lore
#0 lore raw

Hi,

The following patchset includes two little peas of features for tracing filters, making them able to filter every kind of strings.

Now I can do this:

cd /debug/tracing
echo > trace
echo stacktrace > trace_options

cd events/lockdep
echo 'name == "&REISERFS_SB(s)->lock" && wait_usec > 0' > lock_acquired/filter

echo 1 > lock_acquired/enable
sleep 1
echo 0 > lock_acquired/enable

cat trace

# tracer: nop
#
# TASK-PID CPU# TIMESTAMP FUNCTION
# | | | | |

           <...>-6464  [000]   327.448232: lock_acquired: &REISERFS_SB(s)->lock (25058.984 us)
           <...>-6464  [000]   327.448233: 
 <= reiserfs_get_block
 <= __block_prepare_write
 <= block_write_begin
 <= reiserfs_write_begin
 <= generic_file_buffered_write
 <= __generic_file_aio_write_nolock
 <= generic_file_aio_write
           <...>-6470  [000]   327.448422: lock_acquired: &REISERFS_SB(s)->lock (25112.702 us)
           <...>-6470  [000]   327.448425: 

<= reiserfs_update_sd_size
<= reiserfs_write_end
<= generic_file_buffered_write
<= __generic_file_aio_write_nolock
<= generic_file_aio_write
<= do_sync_write
<= reiserfs_file_write

Tom, your filter framework is awesome and very useful! Thanks :-)

Frederic.
---

The following changes since commit a0e39ed378fb6ba916522764cd508fa7d42ad495:
Heiko Carstens (1):
tracing: fix build failure on s390

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git tracing/filters

Frederic Weisbecker (2):
tracing/filters: support for filters of dynamic sized arrays tracing/filters: support for operator reserved characters in strings

 kernel/trace/trace_events_filter.c |   54 ++++++++++++++++++++++++++++++++++--
 1 files changed, 51 insertions(+), 3 deletions(-)
#1 lore raw

PATCH 1/2 tracing/filters: support for filters of dynamic sized arrays

Currently the filtering infrastructure supports well the numeric types and fixed sized array types.

But the recently added __string() field uses a specific indirect offset mechanism which requires a specific predicate. Until now it wasn't supported.

This patch adds this support and implies very few changes, only a new predicate is needed, the management of this specific field can be done through the usual string helpers in the filtering infrastructure.

[ Impact: support all kinds of strings in the tracing filters ]

Cc Tom Zanussi <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Li Zefan <[email protected]>
Cc Zhaolei <[email protected]>
---
 kernel/trace/trace_events_filter.c |   44 +++++++++++++++++++++++++++++++++--
 1 files changed, 41 insertions(+), 3 deletions(-)
kernel/trace/trace_events_filter.c +41 -3
index f494866..4f0a128 100644
@@ -151,6 +151,7 @@ static int filter_pred_or(struct filter_pred *pred __attribute((unused)),
 	return val1 || val2;
 }
 
+/* Filter predicate for fixed sized arrays of characters */
 static int filter_pred_string(struct filter_pred *pred, void *event,
 			      int val1, int val2)
 {
@@ -164,6 +165,30 @@ static int filter_pred_string(struct filter_pred *pred, void *event,
 	return match;
 }
 
+/*
+ * 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.
+ */
+static int filter_pred_strloc(struct filter_pred *pred, void *event,
+			      int val1, int val2)
+{
+	int str_loc = *(int *)(event + pred->offset);
+	char *addr = (char *)(event + str_loc);
+	int cmp, match;
+
+	cmp = strncmp(addr, pred->str_val, pred->str_len);
+
+	match = (!cmp) ^ pred->not;
+
+	return match;
+}
+
 static int filter_pred_none(struct filter_pred *pred, void *event,
 			    int val1, int val2)
 {
@@ -436,10 +461,18 @@ static int filter_add_pred_fn(struct filter_parse_state *ps,
 	return 0;
 }
 
+enum {
+	FILTER_STATIC_STRING = 1,
+	FILTER_DYN_STRING
+};
+
 static int is_string_field(const char *type)
 {
 	if (strchr(type, '[') && strstr(type, "char"))
-		return 1;
+		return FILTER_STATIC_STRING;
+
+	if (!strcmp(type, "__str_loc"))
+		return FILTER_DYN_STRING;
 
 	return 0;
 }
@@ -502,6 +535,7 @@ static int filter_add_pred(struct filter_parse_state *ps,
 	struct ftrace_event_field *field;
 	filter_pred_fn_t fn;
 	unsigned long long val;
+	int string_type;
 
 	pred->fn = filter_pred_none;
 
@@ -526,8 +560,12 @@ static int filter_add_pred(struct filter_parse_state *ps,
 		return -EINVAL;
 	}
 
-	if (is_string_field(field->type)) {
-		fn = filter_pred_string;
+	string_type = is_string_field(field->type);
+	if (string_type) {
+		if (string_type == FILTER_STATIC_STRING)
+			fn = filter_pred_string;
+		else
+			fn = filter_pred_strloc;
 		pred->str_len = field->size;
 		if (pred->op == OP_NE)
 			pred->not = 1;
Signature · 1 line
1.6.2.3
#2 lore raw

PATCH 2/2 tracing/filters: support for operator reserved characters in strings

In reply to Frederic Weisbecker

When we set a filter for an event, such as:

echo "name == my_lock_name" > \
/debug/tracing/events/lockdep/lock_acquired/filter

then the following order of token type is parsed:

- space
- operator
- parentheses
- operand

Because the operators and parentheses have a higher precedence than the operand characters, which is normal, then we can't use any string containing such special characters:

()=<>!&|

To get this support and also avoid ambiguous intepretation from the parser or the human, we can do it using double quotes so that we keep the usual languages habits.

Then after this patch you can still declare string condition like before:

echo name == myname

But if you want to compare against a string containing an operator character, you can use double quotes:

echo 'name == "&myname"'

Don't forget to include the whole expression into single quotes or the double ones will be eaten by echo.

[ Impact: support strings with special characters for tracing filters ]

Cc Tom Zanussi <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Li Zefan <[email protected]>
Cc Zhaolei <[email protected]>
---
 kernel/trace/trace_events_filter.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
kernel/trace/trace_events_filter.c +10 -0
index 4f0a128..ac30de3 100644
@@ -839,10 +839,19 @@ static void postfix_clear(struct filter_parse_state *ps)
 
 static int filter_parse(struct filter_parse_state *ps)
 {
+	int in_string = 0;
 	int op, top_op;
 	char ch;
 
 	while ((ch = infix_next(ps))) {
+		if (ch == '"') {
+			in_string ^= 1;
+			continue;
+		}
+
+		if (in_string)
+			goto parse_operand;
+
 		if (isspace(ch))
 			continue;
 
@@ -896,6 +905,7 @@ static int filter_parse(struct filter_parse_state *ps)
 			}
 			continue;
 		}
+parse_operand:
 		if (append_operand_char(ps, ch)) {
 			parse_error(ps, FILT_ERR_OPERAND_TOO_LONG, 0);
 			return -EINVAL;
Signature · 1 line
1.6.2.3
#3 lore raw
In reply to Frederic Weisbecker
Quoted 44 lines · Frederic Weisbecker

Hi,

The following patchset includes two little peas of features for tracing filters, making them able to filter every kind of strings.

Now I can do this:

cd /debug/tracing
echo > trace
echo stacktrace > trace_options

cd events/lockdep
echo 'name == "&REISERFS_SB(s)->lock" && wait_usec > 0' > lock_acquired/filter

echo 1 > lock_acquired/enable
sleep 1
echo 0 > lock_acquired/enable

cat trace

# tracer: nop
#
# TASK-PID CPU# TIMESTAMP FUNCTION
# | | | | |

           <...>-6464  [000]   327.448232: lock_acquired: &REISERFS_SB(s)->lock (25058.984 us)
           <...>-6464  [000]   327.448233: 
 <= reiserfs_get_block
 <= __block_prepare_write
 <= block_write_begin
 <= reiserfs_write_begin
 <= generic_file_buffered_write
 <= __generic_file_aio_write_nolock
 <= generic_file_aio_write
           <...>-6470  [000]   327.448422: lock_acquired: &REISERFS_SB(s)->lock (25112.702 us)
           <...>-6470  [000]   327.448425: 

<= reiserfs_update_sd_size
<= reiserfs_write_end
<= generic_file_buffered_write
<= __generic_file_aio_write_nolock
<= generic_file_aio_write
<= do_sync_write
<= reiserfs_file_write

Quoted 2 lines

Tom, your filter framework is awesome and very useful! Thanks :-)

Seconded :)

Quoted 10 lines

Frederic.
---

The following changes since commit a0e39ed378fb6ba916522764cd508fa7d42ad495:
Heiko Carstens (1):
tracing: fix build failure on s390

are available in the git repository at:

Quoted 8 lines

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git tracing/filters

Frederic Weisbecker (2):
tracing/filters: support for filters of dynamic sized arrays tracing/filters: support for operator reserved characters in strings

 kernel/trace/trace_events_filter.c |   54 ++++++++++++++++++++++++++++++++++--
 1 files changed, 51 insertions(+), 3 deletions(-)

Pulled, thanks Frederic!

Ingo

Acked-by
#4 lore raw
In reply to Frederic Weisbecker

Hi,

Quoted 44 lines · Frederic Weisbecker

Hi,

The following patchset includes two little peas of features for tracing filters, making them able to filter every kind of strings.

Now I can do this:

cd /debug/tracing
echo > trace
echo stacktrace > trace_options

cd events/lockdep
echo 'name == "&REISERFS_SB(s)->lock" && wait_usec > 0' > lock_acquired/filter

echo 1 > lock_acquired/enable
sleep 1
echo 0 > lock_acquired/enable

cat trace

# tracer: nop
#
# TASK-PID CPU# TIMESTAMP FUNCTION
# | | | | |

           <...>-6464  [000]   327.448232: lock_acquired: &REISERFS_SB(s)->lock (25058.984 us)
           <...>-6464  [000]   327.448233: 
 <= reiserfs_get_block
 <= __block_prepare_write
 <= block_write_begin
 <= reiserfs_write_begin
 <= generic_file_buffered_write
 <= __generic_file_aio_write_nolock
 <= generic_file_aio_write
           <...>-6470  [000]   327.448422: lock_acquired: &REISERFS_SB(s)->lock (25112.702 us)
           <...>-6470  [000]   327.448425: 

<= reiserfs_update_sd_size
<= reiserfs_write_end
<= generic_file_buffered_write
<= __generic_file_aio_write_nolock
<= generic_file_aio_write
<= do_sync_write
<= reiserfs_file_write

Quoted 2 lines

Tom, your filter framework is awesome and very useful! Thanks :-)

Thanks! And thanks for adding these new useful features, too - the patches look good to me...

Tom

Quoted 18 lines

Frederic.
---

The following changes since commit a0e39ed378fb6ba916522764cd508fa7d42ad495:
Heiko Carstens (1):
tracing: fix build failure on s390

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git tracing/filters

Frederic Weisbecker (2):
tracing/filters: support for filters of dynamic sized arrays tracing/filters: support for operator reserved characters in strings

 kernel/trace/trace_events_filter.c |   54 ++++++++++++++++++++++++++++++++++--
 1 files changed, 51 insertions(+), 3 deletions(-)
maintainer
#5 lore raw
In reply to Frederic Weisbecker
Quoted 44 lines · Frederic Weisbecker

Hi,

The following patchset includes two little peas of features for tracing filters, making them able to filter every kind of strings.

Now I can do this:

cd /debug/tracing
echo > trace
echo stacktrace > trace_options

cd events/lockdep
echo 'name == "&REISERFS_SB(s)->lock" && wait_usec > 0' > lock_acquired/filter

echo 1 > lock_acquired/enable
sleep 1
echo 0 > lock_acquired/enable

cat trace

# tracer: nop
#
# TASK-PID CPU# TIMESTAMP FUNCTION
# | | | | |

           <...>-6464  [000]   327.448232: lock_acquired: &REISERFS_SB(s)->lock (25058.984 us)
           <...>-6464  [000]   327.448233: 
 <= reiserfs_get_block
 <= __block_prepare_write
 <= block_write_begin
 <= reiserfs_write_begin
 <= generic_file_buffered_write
 <= __generic_file_aio_write_nolock
 <= generic_file_aio_write
           <...>-6470  [000]   327.448422: lock_acquired: &REISERFS_SB(s)->lock (25112.702 us)
           <...>-6470  [000]   327.448425: 

<= reiserfs_update_sd_size
<= reiserfs_write_end
<= generic_file_buffered_write
<= __generic_file_aio_write_nolock
<= generic_file_aio_write
<= do_sync_write
<= reiserfs_file_write

Quoted 2 lines

Tom, your filter framework is awesome and very useful! Thanks :-)

I totally agree, and also like Frederic's changes.

But...

This is all useless unless people know it exists and more importantly, how to use it.

Ted Tso already started a Documentation/trace/events.txt. We need to add documentation of this feature either in Doc../trace/events.txt or add a new file called Doc../trace/filters.txt. Probably would be better to add a separate file, and add a "See filters.txt" in events.txt.

Tom or Frederic, could either of you write something up? I could when I have time. The git logs seems to be pretty good at explaining it.

Thanks,

-- Steve

#6 lore raw

Hi,

Quoted 58 lines · Steven Rostedt
Quoted 44 lines · Frederic Weisbecker

Hi,

The following patchset includes two little peas of features for tracing filters, making them able to filter every kind of strings.

Now I can do this:

cd /debug/tracing
echo > trace
echo stacktrace > trace_options

cd events/lockdep
echo 'name == "&REISERFS_SB(s)->lock" && wait_usec > 0' > lock_acquired/filter

echo 1 > lock_acquired/enable
sleep 1
echo 0 > lock_acquired/enable

cat trace

# tracer: nop
#
# TASK-PID CPU# TIMESTAMP FUNCTION
# | | | | |

           <...>-6464  [000]   327.448232: lock_acquired: &REISERFS_SB(s)->lock (25058.984 us)
           <...>-6464  [000]   327.448233: 
 <= reiserfs_get_block
 <= __block_prepare_write
 <= block_write_begin
 <= reiserfs_write_begin
 <= generic_file_buffered_write
 <= __generic_file_aio_write_nolock
 <= generic_file_aio_write
           <...>-6470  [000]   327.448422: lock_acquired: &REISERFS_SB(s)->lock (25112.702 us)
           <...>-6470  [000]   327.448425: 

<= reiserfs_update_sd_size
<= reiserfs_write_end
<= generic_file_buffered_write
<= __generic_file_aio_write_nolock
<= generic_file_aio_write
<= do_sync_write
<= reiserfs_file_write

Quoted 2 lines

Tom, your filter framework is awesome and very useful! Thanks :-)

I totally agree, and also like Frederic's changes.

But...

This is all useless unless people know it exists and more importantly, how to use it.

Quoted 8 lines

Ted Tso already started a Documentation/trace/events.txt. We need to add documentation of this feature either in Doc../trace/events.txt or add a new file called Doc../trace/filters.txt. Probably would be better to add a separate file, and add a "See filters.txt" in events.txt.

Tom or Frederic, could either of you write something up? I could when I have time. The git logs seems to be pretty good at explaining it.

Sure, I'll write something up and put it in Doc../trace/filters.txt.

Tom

Quoted 4 lines

Thanks,

-- Steve