Skip to content

Commit 8fb4b67

Browse files
namhyungacmel
authored andcommitted
perf record: Add --all-cgroups option
The --all-cgroups option is to enable cgroup profiling support. It tells kernel to record CGROUP events in the ring buffer so that perf report can identify task/cgroup association later. [root@seventh ~]# perf record --all-cgroups --namespaces /wb/cgtest [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.042 MB perf.data (558 samples) ] [root@seventh ~]# perf report --stdio -s cgroup_id,cgroup,pid # To display the perf.data header info, please use --header/--header-only options. # # # Total Lost Samples: 0 # # Samples: 558 of event 'cycles' # Event count (approx.): 458017341 # # Overhead cgroup id (dev/inode) Cgroup Pid:Command # ........ ..................... .......... ............... # 33.15% 4/0xeffffffb /sub 9615:looper0 32.83% 4/0xf00002f5 /sub/cgrp2 9620:looper2 32.79% 4/0xf00002f4 /sub/cgrp1 9619:looper1 0.35% 4/0xf00002f5 /sub/cgrp2 9618:cgtest 0.34% 4/0xf00002f4 /sub/cgrp1 9617:cgtest 0.32% 4/0xeffffffb / 9615:looper0 0.11% 4/0xeffffffb /sub 9617:cgtest 0.10% 4/0xeffffffb /sub 9618:cgtest # # (Tip: Sample related events with: perf record -e '{cycles,instructions}:S') # [root@seventh ~]# Signed-off-by: Namhyung Kim <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Link: http://lore.kernel.org/lkml/[email protected] [ Extracted the HAVE_FILE_HANDLE from the followup patch ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent ab64069 commit 8fb4b67

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

tools/perf/Documentation/perf-record.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,10 @@ displayed with the weight and local_weight sort keys. This currently works for
391391
abort events and some memory events in precise mode on modern Intel CPUs.
392392

393393
--namespaces::
394-
Record events of type PERF_RECORD_NAMESPACES.
394+
Record events of type PERF_RECORD_NAMESPACES. This enables 'cgroup_id' sort key.
395+
396+
--all-cgroups::
397+
Record events of type PERF_RECORD_CGROUP. This enables 'cgroup' sort key.
395398

396399
--transaction::
397400
Record transaction flags for transaction related events.

tools/perf/builtin-record.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,15 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
14331433
if (rec->opts.record_namespaces)
14341434
tool->namespace_events = true;
14351435

1436+
if (rec->opts.record_cgroup) {
1437+
#ifdef HAVE_FILE_HANDLE
1438+
tool->cgroup_events = true;
1439+
#else
1440+
pr_err("cgroup tracking is not supported\n");
1441+
return -1;
1442+
#endif
1443+
}
1444+
14361445
if (rec->opts.auxtrace_snapshot_mode || rec->switch_output.enabled) {
14371446
signal(SIGUSR2, snapshot_sig_handler);
14381447
if (rec->opts.auxtrace_snapshot_mode)
@@ -2363,6 +2372,8 @@ static struct option __record_options[] = {
23632372
"per thread proc mmap processing timeout in ms"),
23642373
OPT_BOOLEAN(0, "namespaces", &record.opts.record_namespaces,
23652374
"Record namespaces events"),
2375+
OPT_BOOLEAN(0, "all-cgroups", &record.opts.record_cgroup,
2376+
"Record cgroup events"),
23662377
OPT_BOOLEAN(0, "switch-events", &record.opts.record_switch_events,
23672378
"Record context switch events"),
23682379
OPT_BOOLEAN_FLAG(0, "all-kernel", &record.opts.all_kernel,

tools/perf/util/evsel.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,11 @@ void perf_evsel__config(struct evsel *evsel, struct record_opts *opts,
11041104
if (opts->record_namespaces)
11051105
attr->namespaces = track;
11061106

1107+
if (opts->record_cgroup) {
1108+
attr->cgroup = track && !perf_missing_features.cgroup;
1109+
perf_evsel__set_sample_bit(evsel, CGROUP);
1110+
}
1111+
11071112
if (opts->record_switch_events)
11081113
attr->context_switch = track;
11091114

@@ -1789,7 +1794,11 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
17891794
* Must probe features in the order they were added to the
17901795
* perf_event_attr interface.
17911796
*/
1792-
if (!perf_missing_features.branch_hw_idx &&
1797+
if (!perf_missing_features.cgroup && evsel->core.attr.cgroup) {
1798+
perf_missing_features.cgroup = true;
1799+
pr_debug2_peo("Kernel has no cgroup sampling support, bailing out\n");
1800+
goto out_close;
1801+
} else if (!perf_missing_features.branch_hw_idx &&
17931802
(evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_HW_INDEX)) {
17941803
perf_missing_features.branch_hw_idx = true;
17951804
pr_debug2("switching off branch HW index support\n");

tools/perf/util/evsel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct perf_missing_features {
120120
bool bpf;
121121
bool aux_output;
122122
bool branch_hw_idx;
123+
bool cgroup;
123124
};
124125

125126
extern struct perf_missing_features perf_missing_features;

tools/perf/util/record.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct record_opts {
3434
bool auxtrace_snapshot_on_exit;
3535
bool auxtrace_sample_mode;
3636
bool record_namespaces;
37+
bool record_cgroup;
3738
bool record_switch_events;
3839
bool all_kernel;
3940
bool all_user;

0 commit comments

Comments
 (0)