Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 339027
b: refs/heads/master
c: 774cb49
h: refs/heads/master
i:
  339025: 8bb56b1
  339023: fe72095
v: v3
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Nov 14, 2012
1 parent 61c5f38 commit 48640aa
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cac21425578abddc4e9f529845832a57ba27ce0f
refs/heads/master: 774cb499ca9ab0e5950a149d1fe102b125da1cee
15 changes: 13 additions & 2 deletions trunk/tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions trunk/tools/perf/tests/attr/test-record-group
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ sample_type=327
mmap=0
comm=0
enable_on_exec=0
disabled=0
1 change: 1 addition & 0 deletions trunk/tools/perf/tests/attr/test-record-group1
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ sample_type=327
mmap=0
comm=0
enable_on_exec=0
disabled=0
42 changes: 41 additions & 1 deletion trunk/tools/perf/util/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 48640aa

Please sign in to comment.