From: tip-bot for Jiri Olsa <jolsa@redhat.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, linux-kernel@vger.kernel.org, paulus@samba.org,
hpa@zytor.com, mingo@kernel.org, a.p.zijlstra@chello.nl,
namhyung@kernel.org, jolsa@redhat.com, fweisbec@gmail.com,
tglx@linutronix.de, cjashfor@linux.vnet.ibm.com, mingo@elte.hu
Subject: [tip:perf/core] perf tools: Fix 'disabled' attribute config for record command
Date: Sat, 8 Dec 2012 06:57:37 -0800 [thread overview]
Message-ID: <tip-774cb499ca9ab0e5950a149d1fe102b125da1cee@git.kernel.org> (raw)
In-Reply-To: <1352741644-16809-3-git-send-email-jolsa@redhat.com>
Commit-ID: 774cb499ca9ab0e5950a149d1fe102b125da1cee
Gitweb: http://git.kernel.org/tip/774cb499ca9ab0e5950a149d1fe102b125da1cee
Author: Jiri Olsa <jolsa@redhat.com>
AuthorDate: Mon, 12 Nov 2012 18:34:01 +0100
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 14 Nov 2012 16:52:03 -0300
perf tools: Fix 'disabled' attribute config for record command
Currently the record command sets all events initially as disabled.
There's non conditional perf_evlist__enable call, that enables all
events before we exec tracee program. That actually screws whole
enable_on_exec logic, because the event is enabled before the traced
program got executed.
What we actually want is:
1) For any type of traced program:
- all independent events and group leaders are disabled
- all group members are enabled
Group members are ruled by group leaders. They need to
be enabled, because the group scheduling relies on that.
2) For traced programs executed by perf:
- all independent events and group leaders have
enable_on_exec set
- we don't specifically enable or disable any event during
the record command
Independent events and group leaders are initially disabled
and get enabled by exec. Group members are ruled by group
leaders as stated in 1).
3) For traced programs attached by perf (pid/tid):
- we specifically enable or disable all events during
the record command
When attaching events to already running traced we
enable/disable events specifically, as there's no
initial traced exec call.
Fixing appropriate perf_event_attr test case to cover this change.
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1352741644-16809-3-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-record.c | 15 ++++++++++--
tools/perf/tests/attr/test-record-group | 1 +
tools/perf/tests/attr/test-record-group1 | 1 +
tools/perf/util/evsel.c | 42 +++++++++++++++++++++++++++++++-
4 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3717027..268b356 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -701,7 +701,13 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
}
}
- perf_evlist__enable(evsel_list);
+ /*
+ * When perf is starting the traced process, all the events
+ * (apart from group members) have enable_on_exec=1 set,
+ * so don't spoil it by prematurely enabling them.
+ */
+ if (!perf_target__none(&opts->target))
+ perf_evlist__enable(evsel_list);
/*
* Let the child rip
@@ -724,7 +730,12 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
waking++;
}
- if (done)
+ /*
+ * When perf is starting the traced process, at the end events
+ * die with the process and we wait for that. Thus no need to
+ * disable events in this case.
+ */
+ if (done && !perf_target__none(&opts->target))
perf_evlist__disable(evsel_list);
}
diff --git a/tools/perf/tests/attr/test-record-group b/tools/perf/tests/attr/test-record-group
index b945f77..a6599e9 100644
--- a/tools/perf/tests/attr/test-record-group
+++ b/tools/perf/tests/attr/test-record-group
@@ -15,3 +15,4 @@ sample_type=327
mmap=0
comm=0
enable_on_exec=0
+disabled=0
diff --git a/tools/perf/tests/attr/test-record-group1 b/tools/perf/tests/attr/test-record-group1
index 013572f..5a8359d 100644
--- a/tools/perf/tests/attr/test-record-group1
+++ b/tools/perf/tests/attr/test-record-group1
@@ -16,3 +16,4 @@ sample_type=327
mmap=0
comm=0
enable_on_exec=0
+disabled=0
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 6d4a5f6..fc4faaa 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -404,13 +404,40 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
return evsel->name ?: "unknown";
}
+/*
+ * The enable_on_exec/disabled value strategy:
+ *
+ * 1) For any type of traced program:
+ * - all independent events and group leaders are disabled
+ * - all group members are enabled
+ *
+ * Group members are ruled by group leaders. They need to
+ * be enabled, because the group scheduling relies on that.
+ *
+ * 2) For traced programs executed by perf:
+ * - all independent events and group leaders have
+ * enable_on_exec set
+ * - we don't specifically enable or disable any event during
+ * the record command
+ *
+ * Independent events and group leaders are initially disabled
+ * and get enabled by exec. Group members are ruled by group
+ * leaders as stated in 1).
+ *
+ * 3) For traced programs attached by perf (pid/tid):
+ * - we specifically enable or disable all events during
+ * the record command
+ *
+ * When attaching events to already running traced we
+ * enable/disable events specifically, as there's no
+ * initial traced exec call.
+ */
void perf_evsel__config(struct perf_evsel *evsel,
struct perf_record_opts *opts)
{
struct perf_event_attr *attr = &evsel->attr;
int track = !evsel->idx; /* only the first counter needs these */
- attr->disabled = 1;
attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1;
attr->inherit = !opts->no_inherit;
attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
@@ -486,6 +513,19 @@ void perf_evsel__config(struct perf_evsel *evsel,
attr->mmap = track;
attr->comm = track;
+ /*
+ * XXX see the function comment above
+ *
+ * Disabling only independent events or group leaders,
+ * keeping group members enabled.
+ */
+ if (!evsel->leader)
+ attr->disabled = 1;
+
+ /*
+ * Setting enable_on_exec for independent events and
+ * group leaders for traced executed by perf.
+ */
if (perf_target__none(&opts->target) && (!evsel->leader))
attr->enable_on_exec = 1;
}
next prev parent reply other threads:[~2012-12-08 14:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-12 17:33 [PATCH 0/5] perf tool: Fix enable/disable events logic for record command Jiri Olsa
2012-11-12 17:34 ` [PATCH 1/5] perf tool: Fix attributes for '{}' defined event groups Jiri Olsa
2012-12-08 14:56 ` [tip:perf/core] perf tools: " tip-bot for Jiri Olsa
2012-11-12 17:34 ` [PATCH 2/5] perf tool: Fix 'disabled' attribute config for record command Jiri Olsa
2012-12-08 14:57 ` tip-bot for Jiri Olsa [this message]
2012-11-12 17:34 ` [PATCH 3/5] perf tool: Ensure single disable call per event in record comand Jiri Olsa
2012-12-08 14:58 ` [tip:perf/core] perf tools: " tip-bot for Jiri Olsa
2012-11-12 17:34 ` [PATCH 4/5] perf tool: Omit group members from perf_evlist__disable/enable Jiri Olsa
2012-12-08 14:59 ` [tip:perf/core] perf tools: " tip-bot for Jiri Olsa
2012-11-12 17:34 ` [PATCH 5/5] perf tool: Add basic event modifier sanity check Jiri Olsa
2012-11-13 2:22 ` Namhyung Kim
2012-11-13 14:32 ` [PATCHv2 " Jiri Olsa
2012-12-08 15:00 ` [tip:perf/core] perf tools: " tip-bot for Jiri Olsa
2012-11-13 2:26 ` [PATCH 0/5] perf tool: Fix enable/disable events logic for record command Namhyung Kim
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=tip-774cb499ca9ab0e5950a149d1fe102b125da1cee@git.kernel.org \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=cjashfor@linux.vnet.ibm.com \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
--cc=tglx@linutronix.de \
/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.