Commit f9349a8f authored by Frederic Weisbecker's avatar Frederic Weisbecker Committed by Ingo Molnar

tracing/function-graph-tracer: make set_graph_function file support ftrace regex

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: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 64b36ca7
...@@ -1895,6 +1895,10 @@ static void *g_start(struct seq_file *m, loff_t *pos) ...@@ -1895,6 +1895,10 @@ static void *g_start(struct seq_file *m, loff_t *pos)
mutex_lock(&graph_lock); 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); p = g_next(m, p, pos);
return p; return p;
...@@ -1913,6 +1917,11 @@ static int g_show(struct seq_file *m, void *v) ...@@ -1913,6 +1917,11 @@ static int g_show(struct seq_file *m, void *v)
if (!ptr) if (!ptr)
return 0; return 0;
if (ptr == (unsigned long *)1) {
seq_printf(m, "#### all functions enabled ####\n");
return 0;
}
kallsyms_lookup(*ptr, NULL, NULL, NULL, str); kallsyms_lookup(*ptr, NULL, NULL, NULL, str);
seq_printf(m, "%s\n", str); seq_printf(m, "%s\n", str);
...@@ -1966,38 +1975,51 @@ ftrace_graph_read(struct file *file, char __user *ubuf, ...@@ -1966,38 +1975,51 @@ ftrace_graph_read(struct file *file, char __user *ubuf,
} }
static int 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 dyn_ftrace *rec;
struct ftrace_page *pg; struct ftrace_page *pg;
int search_len;
int found = 0; int found = 0;
int j; int type, not;
char *search;
bool exists;
int i;
if (ftrace_disabled) if (ftrace_disabled)
return -ENODEV; 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); mutex_lock(&ftrace_lock);
do_for_each_ftrace_rec(pg, rec) { do_for_each_ftrace_rec(pg, rec) {
if (*idx >= FTRACE_GRAPH_MAX_FUNCS)
break;
if (rec->flags & (FTRACE_FL_FAILED | FTRACE_FL_FREE)) if (rec->flags & (FTRACE_FL_FAILED | FTRACE_FL_FREE))
continue; continue;
kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); if (ftrace_match_record(rec, search, search_len, type)) {
if (strcmp(str, buffer) == 0) { /* ensure it is not already in the array */
/* Return 1 if we add it to the array */ exists = false;
found = 1; for (i = 0; i < *idx; i++)
for (j = 0; j < idx; j++) if (array[i] == rec->ip) {
if (array[j] == rec->ip) { exists = true;
found = 0;
break; break;
} }
if (found) if (!exists) {
array[idx] = rec->ip; array[(*idx)++] = rec->ip;
goto out; found = 1;
}
} }
} while_for_each_ftrace_rec(); } while_for_each_ftrace_rec();
out:
mutex_unlock(&ftrace_lock); mutex_unlock(&ftrace_lock);
return found ? 0 : -EINVAL; return found ? 0 : -EINVAL;
...@@ -2066,13 +2088,11 @@ ftrace_graph_write(struct file *file, const char __user *ubuf, ...@@ -2066,13 +2088,11 @@ ftrace_graph_write(struct file *file, const char __user *ubuf,
} }
buffer[index] = 0; buffer[index] = 0;
/* we allow only one at a time */ /* we allow only one expression at a time */
ret = ftrace_set_func(array, ftrace_graph_count, buffer); ret = ftrace_set_func(array, &ftrace_graph_count, buffer);
if (ret) if (ret)
goto out; goto out;
ftrace_graph_count++;
file->f_pos += read; file->f_pos += read;
ret = read; ret = read;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment