Skip to content

Commit 774cb49

Browse files
Jiri Olsaacmel
authored andcommitted
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>
1 parent cac2142 commit 774cb49

4 files changed

Lines changed: 56 additions & 3 deletions

File tree

‎tools/perf/builtin-record.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,13 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
701701
}
702702
}
703703

704-
perf_evlist__enable(evsel_list);
704+
/*
705+
* When perf is starting the traced process, all the events
706+
* (apart from group members) have enable_on_exec=1 set,
707+
* so don't spoil it by prematurely enabling them.
708+
*/
709+
if (!perf_target__none(&opts->target))
710+
perf_evlist__enable(evsel_list);
705711

706712
/*
707713
* Let the child rip
@@ -724,7 +730,12 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
724730
waking++;
725731
}
726732

727-
if (done)
733+
/*
734+
* When perf is starting the traced process, at the end events
735+
* die with the process and we wait for that. Thus no need to
736+
* disable events in this case.
737+
*/
738+
if (done && !perf_target__none(&opts->target))
728739
perf_evlist__disable(evsel_list);
729740
}
730741

‎tools/perf/tests/attr/test-record-group‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ sample_type=327
1515
mmap=0
1616
comm=0
1717
enable_on_exec=0
18+
disabled=0

‎tools/perf/tests/attr/test-record-group1‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ sample_type=327
1616
mmap=0
1717
comm=0
1818
enable_on_exec=0
19+
disabled=0

‎tools/perf/util/evsel.c‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,40 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
404404
return evsel->name ?: "unknown";
405405
}
406406

407+
/*
408+
* The enable_on_exec/disabled value strategy:
409+
*
410+
* 1) For any type of traced program:
411+
* - all independent events and group leaders are disabled
412+
* - all group members are enabled
413+
*
414+
* Group members are ruled by group leaders. They need to
415+
* be enabled, because the group scheduling relies on that.
416+
*
417+
* 2) For traced programs executed by perf:
418+
* - all independent events and group leaders have
419+
* enable_on_exec set
420+
* - we don't specifically enable or disable any event during
421+
* the record command
422+
*
423+
* Independent events and group leaders are initially disabled
424+
* and get enabled by exec. Group members are ruled by group
425+
* leaders as stated in 1).
426+
*
427+
* 3) For traced programs attached by perf (pid/tid):
428+
* - we specifically enable or disable all events during
429+
* the record command
430+
*
431+
* When attaching events to already running traced we
432+
* enable/disable events specifically, as there's no
433+
* initial traced exec call.
434+
*/
407435
void perf_evsel__config(struct perf_evsel *evsel,
408436
struct perf_record_opts *opts)
409437
{
410438
struct perf_event_attr *attr = &evsel->attr;
411439
int track = !evsel->idx; /* only the first counter needs these */
412440

413-
attr->disabled = 1;
414441
attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1;
415442
attr->inherit = !opts->no_inherit;
416443
attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
@@ -486,6 +513,19 @@ void perf_evsel__config(struct perf_evsel *evsel,
486513
attr->mmap = track;
487514
attr->comm = track;
488515

516+
/*
517+
* XXX see the function comment above
518+
*
519+
* Disabling only independent events or group leaders,
520+
* keeping group members enabled.
521+
*/
522+
if (!evsel->leader)
523+
attr->disabled = 1;
524+
525+
/*
526+
* Setting enable_on_exec for independent events and
527+
* group leaders for traced executed by perf.
528+
*/
489529
if (perf_target__none(&opts->target) && (!evsel->leader))
490530
attr->enable_on_exec = 1;
491531
}

0 commit comments

Comments
 (0)