ftrace: enable filtering only when a function is filtered on
authorSteven Rostedt <srostedt@redhat.com>
Sat, 14 Feb 2009 01:53:42 +0000 (20:53 -0500)
committerSteven Rostedt <srostedt@redhat.com>
Mon, 16 Feb 2009 22:03:49 +0000 (17:03 -0500)
Impact: fix to prevent empty set_ftrace_filter and no ftrace output

The function filter is used to only trace a given set of functions.
The filter is enabled when a function name is echoed into the
set_ftrace_filter file. But if the name has a typo and the function
is not found, the filter is enabled, but no function is listed.

This makes a confusing situation where set_ftrace_filter is empty
but no functions ever get enabled for tracing.

For example:

 # cat /debug/tracing/set_ftrace_filter

  #### all functions enabled ####

 # echo bad_name > set_ftrace_filter
 # cat /debug/tracing/set_ftrace_filter

 # echo function > current_tracer
 # cat trace

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

This patch changes that to only enable filtering if a function
is set to be filtered on. Now, the filter is not enabled if
a bad name is echoed into set_ftrace_filter.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
kernel/trace/ftrace.c

index 9e60ae423af9d27068d027cfbbe63ad1721fef54..340f88b68d9ef07b2c392c44c98ef7df7b488745 100644 (file)
@@ -1153,8 +1153,6 @@ static void ftrace_match_records(char *buff, int len, int enable)
 
        /* should not be called from interrupt context */
        spin_lock(&ftrace_lock);
-       if (enable)
-               ftrace_filtered = 1;
        do_for_each_ftrace_rec(pg, rec) {
 
                if (rec->flags & FTRACE_FL_FAILED)
@@ -1166,7 +1164,12 @@ static void ftrace_match_records(char *buff, int len, int enable)
                        else
                                rec->flags |= flag;
                }
-
+               /*
+                * Only enable filtering if we have a function that
+                * is filtered on.
+                */
+               if (enable && (rec->flags & FTRACE_FL_FILTER))
+                       ftrace_filtered = 1;
        } while_for_each_ftrace_rec();
        spin_unlock(&ftrace_lock);
 }
@@ -1217,9 +1220,6 @@ static void ftrace_match_module_records(char *buff, char *mod, int enable)
 
        /* should not be called from interrupt context */
        spin_lock(&ftrace_lock);
-       if (enable)
-               ftrace_filtered = 1;
-
        do_for_each_ftrace_rec(pg, rec) {
 
                if (rec->flags & FTRACE_FL_FAILED)
@@ -1232,6 +1232,8 @@ static void ftrace_match_module_records(char *buff, char *mod, int enable)
                        else
                                rec->flags |= flag;
                }
+               if (enable && (rec->flags & FTRACE_FL_FILTER))
+                       ftrace_filtered = 1;
 
        } while_for_each_ftrace_rec();
        spin_unlock(&ftrace_lock);