All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Andy Whitcroft <apw@canonical.com>, Ingo Molnar <mingo@elte.hu>,
	Steven Rostedt <rostedt@goodmis.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing/function-graph-tracer: make set_graph_function file support ftrace regex
Date: Fri, 20 Feb 2009 17:58:48 +0100	[thread overview]
Message-ID: <20090220165847.GF5732@nowhere> (raw)
In-Reply-To: <499dc97d.257d420a.0f93.1be5@mx.google.com>

On Thu, Feb 19, 2009 at 09:13:12PM +0100, Frederic Weisbecker wrote:
> Impact: trace only functions matching a pattern
> 
> The set_graph_function file let one to trace only one or several
> chosen functions and follow all their code flow.
> 
> Currently, only a constant function name is allowed so this patch
> allows the ftrace_regex functions:
> 
> _ matches all functions that end with "name":
>   echo *name > set_graph_function
> 
> _ matches all functions that begin with "name":
>   echo name* > set_graph_function
> 
> _ matches all functions that contains "name":
>   echo *name* > set_graph_function
> 
> Example:
> 
> echo mutex* > set_graph_function
> 
>  0)               |  mutex_lock_nested() {
>  0)   0.563 us    |    __might_sleep();
>  0)   2.072 us    |  }
>  0)               |  mutex_unlock() {
>  0)   1.036 us    |    __mutex_unlock_slowpath();
>  0)   2.433 us    |  }
>  0)               |  mutex_unlock() {
>  0)   0.691 us    |    __mutex_unlock_slowpath();
>  0)   1.787 us    |  }
>  0)               |  mutex_lock_interruptible_nested() {
>  0)   0.548 us    |    __might_sleep();
>  0)   1.945 us    |  }
> 
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
> ---
>  kernel/trace/ftrace.c |   56 +++++++++++++++++++++++++++++++++---------------
>  1 files changed, 38 insertions(+), 18 deletions(-)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 7dd5a2b..cf59f4c 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -1895,6 +1895,10 @@ static void *g_start(struct seq_file *m, loff_t *pos)
>  
>  	mutex_lock(&graph_lock);
>  
> +	/* Nothing, tell g_show to print all functions are enabled */
> +	if (!ftrace_graph_count && !*pos)
> +		return (void *)1;
> +
>  	p = g_next(m, p, pos);
>  
>  	return p;
> @@ -1913,6 +1917,11 @@ static int g_show(struct seq_file *m, void *v)
>  	if (!ptr)
>  		return 0;
>  
> +	if (ptr == (unsigned long *)1) {
> +		seq_printf(m, "#### all functions enabled ####\n");
> +		return 0;
> +	}
> +
>  	kallsyms_lookup(*ptr, NULL, NULL, NULL, str);
>  
>  	seq_printf(m, "%s\n", str);
> @@ -1966,38 +1975,51 @@ ftrace_graph_read(struct file *file, char __user *ubuf,
>  }
>  
>  static int
> -ftrace_set_func(unsigned long *array, int idx, char *buffer)
> +ftrace_set_func(unsigned long *array, int *idx, char *buffer)
>  {
> -	char str[KSYM_SYMBOL_LEN];
>  	struct dyn_ftrace *rec;
>  	struct ftrace_page *pg;
> +	int search_len;
>  	int found = 0;
> -	int j;
> +	int type, not;
> +	char *search;
> +	bool exists;
> +	int i;
>  
>  	if (ftrace_disabled)
>  		return -ENODEV;
>  
> +	/* decode regex */
> +	type = ftrace_setup_glob(buffer, strlen(buffer), &search, &not);
> +	if (not)
> +		return -EINVAL;
> +
> +	search_len = strlen(search);
> +
>  	mutex_lock(&ftrace_lock);
>  	do_for_each_ftrace_rec(pg, rec) {
>  
> +		if (*idx >= FTRACE_GRAPH_MAX_FUNCS)
> +			break;
> +
>  		if (rec->flags & (FTRACE_FL_FAILED | FTRACE_FL_FREE))
>  			continue;
>  
> -		kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
> -		if (strcmp(str, buffer) == 0) {
> -			/* Return 1 if we add it to the array */
> -			found = 1;
> -			for (j = 0; j < idx; j++)
> -				if (array[j] == rec->ip) {
> -					found = 0;
> +		if (ftrace_match_record(rec, search, search_len, type)) {
> +			/* ensure it is not already in the array */
> +			exists = false;
> +			for (i = 0; i < *idx; i++)
> +				if (array[i] == rec->ip) {
> +					exists = true;
>  					break;
>  				}
> -			if (found)
> -				array[idx] = rec->ip;
> -			goto out;
> +			if (!exists) {
> +				array[(*idx)++] = rec->ip;
> +				found = 1;
> +			}
>  		}
>  	} while_for_each_ftrace_rec();
> - out:
> +
>  	mutex_unlock(&ftrace_lock);
>  
>  	return found ? 0 : -EINVAL;
> @@ -2066,13 +2088,11 @@ ftrace_graph_write(struct file *file, const char __user *ubuf,
>  	}
>  	buffer[index] = 0;
>  
> -	/* we allow only one at a time */
> -	ret = ftrace_set_func(array, ftrace_graph_count, buffer);
> +	/* we allow only one expression at a time */
> +	ret = ftrace_set_func(array, &ftrace_graph_count, buffer);
>  	if (ret)
>  		goto out;
>  
> -	ftrace_graph_count++;
> -
>  	file->f_pos += read;
>  
>  	ret = read;
> -- 
> 1.6.1
> 
> 

BTW, I got something that looked like a false positive with checkpatch.pl on this patch:

ERROR: return is not a function, parentheses are not required
#56: FILE: kernel/trace/ftrace.c:1900:
+		return (void *)1;

total: 1 errors, 0 warnings, 101 lines checked

0001-tracing-function-graph-tracer-make-set_graph_functi.patch has style problems, please review.  If any of these 
errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.


It is confusing a cast with a function call.


      parent reply	other threads:[~2009-02-20 16:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-19 20:13 [PATCH] tracing/function-graph-tracer: make set_graph_function file support ftrace regex Frederic Weisbecker
2009-02-20 10:40 ` Ingo Molnar
2009-02-20 14:42   ` Frederic Weisbecker
2009-02-20 16:58 ` Frederic Weisbecker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090220165847.GF5732@nowhere \
    --to=fweisbec@gmail.com \
    --cc=acme@redhat.com \
    --cc=apw@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.