Skip to content

Commit ba78c1c

Browse files
namhyungacmel
authored andcommitted
perf tools: Basic support for CGROUP event
Implement basic functionality to support cgroup tracking. Each cgroup can be identified by inode number which can be read from userspace too. The actual cgroup processing will come in the later patch. Reported-by: kernel test robot <[email protected]> Signed-off-by: Namhyung Kim <[email protected]> Cc: Adrian Hunter <[email protected]> [ fix perf test failure on sampling parsing ] 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] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 49f550e commit ba78c1c

File tree

13 files changed

+74
-1
lines changed

13 files changed

+74
-1
lines changed

tools/lib/perf/include/perf/event.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ struct perf_record_bpf_event {
105105
__u8 tag[BPF_TAG_SIZE]; // prog tag
106106
};
107107

108+
struct perf_record_cgroup {
109+
struct perf_event_header header;
110+
__u64 id;
111+
char path[PATH_MAX];
112+
};
113+
108114
struct perf_record_sample {
109115
struct perf_event_header header;
110116
__u64 array[];
@@ -352,6 +358,7 @@ union perf_event {
352358
struct perf_record_mmap2 mmap2;
353359
struct perf_record_comm comm;
354360
struct perf_record_namespaces namespaces;
361+
struct perf_record_cgroup cgroup;
355362
struct perf_record_fork fork;
356363
struct perf_record_lost lost;
357364
struct perf_record_lost_samples lost_samples;

tools/perf/builtin-diff.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ static struct perf_diff pdiff = {
455455
.fork = perf_event__process_fork,
456456
.lost = perf_event__process_lost,
457457
.namespaces = perf_event__process_namespaces,
458+
.cgroup = perf_event__process_cgroup,
458459
.ordered_events = true,
459460
.ordering_requires_timestamps = true,
460461
},

tools/perf/builtin-report.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ int cmd_report(int argc, const char **argv)
11051105
.mmap2 = perf_event__process_mmap2,
11061106
.comm = perf_event__process_comm,
11071107
.namespaces = perf_event__process_namespaces,
1108+
.cgroup = perf_event__process_cgroup,
11081109
.exit = perf_event__process_exit,
11091110
.fork = perf_event__process_fork,
11101111
.lost = perf_event__process_lost,

tools/perf/tests/sample-parsing.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ static bool samples_same(const struct perf_sample *s1,
151151
if (type & PERF_SAMPLE_PHYS_ADDR)
152152
COMP(phys_addr);
153153

154+
if (type & PERF_SAMPLE_CGROUP)
155+
COMP(cgroup);
156+
154157
if (type & PERF_SAMPLE_AUX) {
155158
COMP(aux_sample.size);
156159
if (memcmp(s1->aux_sample.data, s2->aux_sample.data,
@@ -230,6 +233,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)
230233
.regs = regs,
231234
},
232235
.phys_addr = 113,
236+
.cgroup = 114,
233237
.aux_sample = {
234238
.size = sizeof(aux_data),
235239
.data = (void *)aux_data,
@@ -336,7 +340,7 @@ int test__sample_parsing(struct test *test __maybe_unused, int subtest __maybe_u
336340
* were added. Please actually update the test rather than just change
337341
* the condition below.
338342
*/
339-
if (PERF_SAMPLE_MAX > PERF_SAMPLE_AUX << 1) {
343+
if (PERF_SAMPLE_MAX > PERF_SAMPLE_CGROUP << 1) {
340344
pr_debug("sample format has changed, some new PERF_SAMPLE_ bit was introduced - test needs updating\n");
341345
return -1;
342346
}

tools/perf/util/event.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static const char *perf_event__names[] = {
5454
[PERF_RECORD_NAMESPACES] = "NAMESPACES",
5555
[PERF_RECORD_KSYMBOL] = "KSYMBOL",
5656
[PERF_RECORD_BPF_EVENT] = "BPF_EVENT",
57+
[PERF_RECORD_CGROUP] = "CGROUP",
5758
[PERF_RECORD_HEADER_ATTR] = "ATTR",
5859
[PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE",
5960
[PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA",
@@ -180,6 +181,12 @@ size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp)
180181
return ret;
181182
}
182183

184+
size_t perf_event__fprintf_cgroup(union perf_event *event, FILE *fp)
185+
{
186+
return fprintf(fp, " cgroup: %" PRI_lu64 " %s\n",
187+
event->cgroup.id, event->cgroup.path);
188+
}
189+
183190
int perf_event__process_comm(struct perf_tool *tool __maybe_unused,
184191
union perf_event *event,
185192
struct perf_sample *sample,
@@ -196,6 +203,14 @@ int perf_event__process_namespaces(struct perf_tool *tool __maybe_unused,
196203
return machine__process_namespaces_event(machine, event, sample);
197204
}
198205

206+
int perf_event__process_cgroup(struct perf_tool *tool __maybe_unused,
207+
union perf_event *event,
208+
struct perf_sample *sample,
209+
struct machine *machine)
210+
{
211+
return machine__process_cgroup_event(machine, event, sample);
212+
}
213+
199214
int perf_event__process_lost(struct perf_tool *tool __maybe_unused,
200215
union perf_event *event,
201216
struct perf_sample *sample,
@@ -417,6 +432,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)
417432
case PERF_RECORD_NAMESPACES:
418433
ret += perf_event__fprintf_namespaces(event, fp);
419434
break;
435+
case PERF_RECORD_CGROUP:
436+
ret += perf_event__fprintf_cgroup(event, fp);
437+
break;
420438
case PERF_RECORD_MMAP2:
421439
ret += perf_event__fprintf_mmap2(event, fp);
422440
break;

tools/perf/util/event.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct perf_sample {
135135
u32 raw_size;
136136
u64 data_src;
137137
u64 phys_addr;
138+
u64 cgroup;
138139
u32 flags;
139140
u16 insn_len;
140141
u8 cpumode;
@@ -322,6 +323,10 @@ int perf_event__process_namespaces(struct perf_tool *tool,
322323
union perf_event *event,
323324
struct perf_sample *sample,
324325
struct machine *machine);
326+
int perf_event__process_cgroup(struct perf_tool *tool,
327+
union perf_event *event,
328+
struct perf_sample *sample,
329+
struct machine *machine);
325330
int perf_event__process_mmap(struct perf_tool *tool,
326331
union perf_event *event,
327332
struct perf_sample *sample,
@@ -377,6 +382,7 @@ size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp);
377382
size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
378383
size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp);
379384
size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp);
385+
size_t perf_event__fprintf_cgroup(union perf_event *event, FILE *fp);
380386
size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp);
381387
size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp);
382388
size_t perf_event__fprintf(union perf_event *event, FILE *fp);

tools/perf/util/evsel.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,6 +2267,12 @@ int perf_evsel__parse_sample(struct evsel *evsel, union perf_event *event,
22672267
array++;
22682268
}
22692269

2270+
data->cgroup = 0;
2271+
if (type & PERF_SAMPLE_CGROUP) {
2272+
data->cgroup = *array;
2273+
array++;
2274+
}
2275+
22702276
if (type & PERF_SAMPLE_AUX) {
22712277
OVERFLOW_CHECK_u64(array);
22722278
sz = *array++;

tools/perf/util/machine.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,16 @@ int machine__process_namespaces_event(struct machine *machine __maybe_unused,
654654
return err;
655655
}
656656

657+
int machine__process_cgroup_event(struct machine *machine __maybe_unused,
658+
union perf_event *event,
659+
struct perf_sample *sample __maybe_unused)
660+
{
661+
if (dump_trace)
662+
perf_event__fprintf_cgroup(event, stdout);
663+
664+
return 0;
665+
}
666+
657667
int machine__process_lost_event(struct machine *machine __maybe_unused,
658668
union perf_event *event, struct perf_sample *sample __maybe_unused)
659669
{
@@ -1878,6 +1888,8 @@ int machine__process_event(struct machine *machine, union perf_event *event,
18781888
ret = machine__process_mmap_event(machine, event, sample); break;
18791889
case PERF_RECORD_NAMESPACES:
18801890
ret = machine__process_namespaces_event(machine, event, sample); break;
1891+
case PERF_RECORD_CGROUP:
1892+
ret = machine__process_cgroup_event(machine, event, sample); break;
18811893
case PERF_RECORD_MMAP2:
18821894
ret = machine__process_mmap2_event(machine, event, sample); break;
18831895
case PERF_RECORD_FORK:

tools/perf/util/machine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ int machine__process_switch_event(struct machine *machine,
128128
int machine__process_namespaces_event(struct machine *machine,
129129
union perf_event *event,
130130
struct perf_sample *sample);
131+
int machine__process_cgroup_event(struct machine *machine,
132+
union perf_event *event,
133+
struct perf_sample *sample);
131134
int machine__process_mmap_event(struct machine *machine, union perf_event *event,
132135
struct perf_sample *sample);
133136
int machine__process_mmap2_event(struct machine *machine, union perf_event *event,

tools/perf/util/perf_event_attr_fprintf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static void __p_sample_type(char *buf, size_t size, u64 value)
3535
bit_name(BRANCH_STACK), bit_name(REGS_USER), bit_name(STACK_USER),
3636
bit_name(IDENTIFIER), bit_name(REGS_INTR), bit_name(DATA_SRC),
3737
bit_name(WEIGHT), bit_name(PHYS_ADDR), bit_name(AUX),
38+
bit_name(CGROUP),
3839
{ .name = NULL, }
3940
};
4041
#undef bit_name
@@ -132,6 +133,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
132133
PRINT_ATTRf(ksymbol, p_unsigned);
133134
PRINT_ATTRf(bpf_event, p_unsigned);
134135
PRINT_ATTRf(aux_output, p_unsigned);
136+
PRINT_ATTRf(cgroup, p_unsigned);
135137

136138
PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned);
137139
PRINT_ATTRf(bp_type, p_unsigned);

0 commit comments

Comments
 (0)