mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: rostedt@goodmis.org, fweisbec@gmail.com, a.p.zijlstra@chello.nl
Cc: linux-kernel@vger.kernel.org
Subject: [RFC 2/4] perf, ftrace: Add filter support for ftrace:function tracepoint
Date: Mon, 11 Jul 2011 15:22:54 +0200	[thread overview]
Message-ID: <1310390576-8289-3-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1310390576-8289-1-git-send-email-jolsa@redhat.com>

Add support to specify perf filter for function trace.

Standard perf filter could be now used for ftrace:function tracepoint like:

 # ./perf stat -e ftrace:function --filter "ip == sys_open || ip == sys_close" sleep 1

 Performance counter stats for 'sleep 1':

                 9 ftrace:function                                             

       1.003097430 seconds time elapsed

Details:
- the value for ip and parent_ip fields gets translated to the
  function value (mcount return IP). The ip and parent_ip are then
  processed as integer values.

---
 include/linux/ftrace.h             |    2 ++
 kernel/trace/ftrace.c              |   23 +++++++++++++++++++++++
 kernel/trace/trace_events_filter.c |   32 ++++++++++++++++++++++++++------
 3 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index ed0eb52..f858e97 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -157,6 +157,8 @@ extern void
 unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
 extern void unregister_ftrace_function_probe_all(char *glob);
 
+extern int ftrace_function_rec_ip(char *func, unsigned long long *ip);
+
 extern int ftrace_text_reserved(void *start, void *end);
 
 enum {
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 6d6e0d0..7325ae4 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2599,6 +2599,29 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
 	return count;
 }
 
+int ftrace_function_rec_ip(char *func, unsigned long long *ip)
+{
+	struct ftrace_page *pg;
+	struct dyn_ftrace *rec;
+	int len = strlen(func);
+	int found = 0;
+
+	mutex_lock(&ftrace_lock);
+
+	do_for_each_ftrace_rec(pg, rec) {
+		if (!ftrace_match_record(rec, NULL, func, len, MATCH_FULL))
+			continue;
+
+		*ip = rec->ip;
+		found = 1;
+		break;
+	} while_for_each_ftrace_rec();
+
+	mutex_unlock(&ftrace_lock);
+
+	return found ? 0 : -EINVAL;
+}
+
 enum {
 	PROBE_TEST_FUNC		= 1,
 	PROBE_TEST_DATA		= 2
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 256764e..dd5c648 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -883,8 +883,12 @@ static bool is_string_field(struct ftrace_event_field *field)
 	       field->filter_type == FILTER_PTR_STRING;
 }
 
-static int is_legal_op(struct ftrace_event_field *field, int op)
+static int is_legal_op(struct ftrace_event_call *call,
+		       struct ftrace_event_field *field, int op)
 {
+	if ((call->event.type == TRACE_FN) &&
+	    (op != OP_EQ && op != OP_NE))
+		return 0;
 	if (is_string_field(field) &&
 	    (op != OP_EQ && op != OP_NE && op != OP_GLOB))
 		return 0;
@@ -937,6 +941,24 @@ static filter_pred_fn_t select_comparison_fn(int op, int field_size,
 	return fn;
 }
 
+static int pred_get_val(struct ftrace_event_call *call,
+			struct filter_pred *pred,
+			struct ftrace_event_field *field,
+			unsigned long long *val)
+{
+	int ret;
+
+	if (call->event.type == TRACE_FN)
+		return ftrace_function_rec_ip(pred->regex.pattern, val);
+
+	if (field->is_signed)
+		ret = strict_strtoll(pred->regex.pattern, 0, val);
+	else
+		ret = strict_strtoull(pred->regex.pattern, 0, val);
+
+	return ret;
+}
+
 static int filter_add_pred(struct filter_parse_state *ps,
 			   struct ftrace_event_call *call,
 			   struct event_filter *filter,
@@ -964,7 +986,7 @@ static int filter_add_pred(struct filter_parse_state *ps,
 
 	pred->offset = field->offset;
 
-	if (!is_legal_op(field, pred->op)) {
+	if (!is_legal_op(call, field, pred->op)) {
 		parse_error(ps, FILT_ERR_ILLEGAL_FIELD_OP, 0);
 		return -EINVAL;
 	}
@@ -980,14 +1002,12 @@ static int filter_add_pred(struct filter_parse_state *ps,
 		else
 			fn = filter_pred_pchar;
 	} else {
-		if (field->is_signed)
-			ret = strict_strtoll(pred->regex.pattern, 0, &val);
-		else
-			ret = strict_strtoull(pred->regex.pattern, 0, &val);
+		ret = pred_get_val(call, pred, field, &val);
 		if (ret) {
 			parse_error(ps, FILT_ERR_ILLEGAL_INTVAL, 0);
 			return -EINVAL;
 		}
+
 		pred->val = val;
 
 		fn = select_comparison_fn(pred->op, field->size,
-- 
1.7.1


  parent reply	other threads:[~2011-07-11 13:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-11 13:22 [RFC 0/4] trace,perf: Enabling ftrace:function tracepoint for perf Jiri Olsa
2011-07-11 13:22 ` [RFC 1/4] perf, ftrace: Add perf support to use function tracepoint Jiri Olsa
2011-07-11 13:22 ` Jiri Olsa [this message]
2011-08-10 19:34   ` [RFC 2/4] perf, ftrace: Add filter support for ftrace:function tracepoint Steven Rostedt
2011-07-11 13:22 ` [RFC 3/4] perf, ftrace: Add new perf ioctl for function trace filter Jiri Olsa
2011-07-18 15:12   ` Frederic Weisbecker
2011-07-19  9:57     ` Jiri Olsa
2011-07-26 13:43       ` Frederic Weisbecker
2011-07-27 12:17         ` Jiri Olsa
2011-08-10 20:25           ` Steven Rostedt
2011-07-11 13:22 ` [RFC 4/4] perf, ftrace: Add ftrace option for perf stat command Jiri Olsa

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=1310390576-8289-3-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®