diff options
Diffstat (limited to 'tools/perf/util/evsel.c')
-rw-r--r-- | tools/perf/util/evsel.c | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d144d464ce39..1b16dd1edc8e 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) | |||
404 | return evsel->name ?: "unknown"; | 404 | return evsel->name ?: "unknown"; |
405 | } | 405 | } |
406 | 406 | ||
407 | void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, | 407 | /* |
408 | struct perf_evsel *first) | 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 | */ | ||
435 | void perf_evsel__config(struct perf_evsel *evsel, | ||
436 | struct perf_record_opts *opts) | ||
409 | { | 437 | { |
410 | struct perf_event_attr *attr = &evsel->attr; | 438 | struct perf_event_attr *attr = &evsel->attr; |
411 | int track = !evsel->idx; /* only the first counter needs these */ | 439 | int track = !evsel->idx; /* only the first counter needs these */ |
412 | 440 | ||
413 | attr->disabled = 1; | ||
414 | attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1; | 441 | attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1; |
415 | attr->inherit = !opts->no_inherit; | 442 | attr->inherit = !opts->no_inherit; |
416 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | | 443 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | |
@@ -486,10 +513,21 @@ void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, | |||
486 | attr->mmap = track; | 513 | attr->mmap = track; |
487 | attr->comm = track; | 514 | attr->comm = track; |
488 | 515 | ||
489 | if (perf_target__none(&opts->target) && | 516 | /* |
490 | (!opts->group || evsel == first)) { | 517 | * XXX see the function comment above |
518 | * | ||
519 | * Disabling only independent events or group leaders, | ||
520 | * keeping group members enabled. | ||
521 | */ | ||
522 | if (!perf_evsel__is_group_member(evsel)) | ||
523 | attr->disabled = 1; | ||
524 | |||
525 | /* | ||
526 | * Setting enable_on_exec for independent events and | ||
527 | * group leaders for traced executed by perf. | ||
528 | */ | ||
529 | if (perf_target__none(&opts->target) && !perf_evsel__is_group_member(evsel)) | ||
491 | attr->enable_on_exec = 1; | 530 | attr->enable_on_exec = 1; |
492 | } | ||
493 | } | 531 | } |
494 | 532 | ||
495 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads) | 533 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads) |
@@ -669,7 +707,7 @@ static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread) | |||
669 | struct perf_evsel *leader = evsel->leader; | 707 | struct perf_evsel *leader = evsel->leader; |
670 | int fd; | 708 | int fd; |
671 | 709 | ||
672 | if (!leader) | 710 | if (!perf_evsel__is_group_member(evsel)) |
673 | return -1; | 711 | return -1; |
674 | 712 | ||
675 | /* | 713 | /* |