lkml.org 
[lkml]   [2019]   [Aug]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 3/9] perf tools: Basic support for CGROUP event
Em Wed, Aug 28, 2019 at 04:31:24PM +0900, Namhyung Kim escreveu:
> 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.
>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/include/uapi/linux/perf_event.h | 17 +++++++++++++++--

Try to have the synchronization of tools/include/ with the kernel to be
done in a separate patch, please, there is a number of projects such as
libbpf and in time libperf that will have a mirror repo outside the
kernel tree and that will get just the needed csets.

- Arnaldo

> tools/perf/builtin-diff.c | 1 +
> tools/perf/builtin-report.c | 1 +
> tools/perf/lib/include/perf/event.h | 7 +++++++
> tools/perf/util/event.c | 18 ++++++++++++++++++
> tools/perf/util/event.h | 7 +++++++
> tools/perf/util/evsel.c | 7 +++++++
> tools/perf/util/machine.c | 12 ++++++++++++
> tools/perf/util/machine.h | 3 +++
> tools/perf/util/session.c | 4 ++++
> tools/perf/util/tool.h | 1 +
> 11 files changed, 76 insertions(+), 2 deletions(-)
>
> diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
> index bb7b271397a6..91a552bf9611 100644
> --- a/tools/include/uapi/linux/perf_event.h
> +++ b/tools/include/uapi/linux/perf_event.h
> @@ -141,8 +141,9 @@ enum perf_event_sample_format {
> PERF_SAMPLE_TRANSACTION = 1U << 17,
> PERF_SAMPLE_REGS_INTR = 1U << 18,
> PERF_SAMPLE_PHYS_ADDR = 1U << 19,
> + PERF_SAMPLE_CGROUP = 1U << 20,
>
> - PERF_SAMPLE_MAX = 1U << 20, /* non-ABI */
> + PERF_SAMPLE_MAX = 1U << 21, /* non-ABI */
>
> __PERF_SAMPLE_CALLCHAIN_EARLY = 1ULL << 63, /* non-ABI; internal use */
> };
> @@ -375,7 +376,8 @@ struct perf_event_attr {
> ksymbol : 1, /* include ksymbol events */
> bpf_event : 1, /* include bpf events */
> aux_output : 1, /* generate AUX records instead of events */
> - __reserved_1 : 32;
> + cgroup : 1, /* include cgroup events */
> + __reserved_1 : 31;
>
> union {
> __u32 wakeup_events; /* wakeup every n events */
> @@ -1000,6 +1002,17 @@ enum perf_event_type {
> */
> PERF_RECORD_BPF_EVENT = 18,
>
> + /*
> + * struct {
> + * struct perf_event_header header;
> + * u64 ino;
> + * u64 path_len;
> + * char path[];
> + * struct sample_id sample_id;
> + * };
> + */
> + PERF_RECORD_CGROUP = 19,
> +
> PERF_RECORD_MAX, /* non-ABI */
> };
>
> diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
> index 51c37e53b3d8..ec639340bb65 100644
> --- a/tools/perf/builtin-diff.c
> +++ b/tools/perf/builtin-diff.c
> @@ -445,6 +445,7 @@ static struct perf_diff pdiff = {
> .fork = perf_event__process_fork,
> .lost = perf_event__process_lost,
> .namespaces = perf_event__process_namespaces,
> + .cgroup = perf_event__process_cgroup,
> .ordered_events = true,
> .ordering_requires_timestamps = true,
> },
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> index 318b0b95c14c..c65a59fd2a94 100644
> --- a/tools/perf/builtin-report.c
> +++ b/tools/perf/builtin-report.c
> @@ -1033,6 +1033,7 @@ int cmd_report(int argc, const char **argv)
> .mmap2 = perf_event__process_mmap2,
> .comm = perf_event__process_comm,
> .namespaces = perf_event__process_namespaces,
> + .cgroup = perf_event__process_cgroup,
> .exit = perf_event__process_exit,
> .fork = perf_event__process_fork,
> .lost = perf_event__process_lost,
> diff --git a/tools/perf/lib/include/perf/event.h b/tools/perf/lib/include/perf/event.h
> index 36ad3a4a79e6..ec112ad640a1 100644
> --- a/tools/perf/lib/include/perf/event.h
> +++ b/tools/perf/lib/include/perf/event.h
> @@ -104,6 +104,13 @@ struct perf_record_bpf_event {
> __u8 tag[BPF_TAG_SIZE]; // prog tag
> };
>
> +struct perf_record_cgroup {
> + struct perf_event_header header;
> + __u64 ino;
> + __u64 path_len;
> + char path[PATH_MAX];
> +};
> +
> struct perf_record_sample {
> struct perf_event_header header;
> __u64 array[];
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> index 33616ea62a47..c19b00c1fc26 100644
> --- a/tools/perf/util/event.c
> +++ b/tools/perf/util/event.c
> @@ -52,6 +52,7 @@ static const char *perf_event__names[] = {
> [PERF_RECORD_NAMESPACES] = "NAMESPACES",
> [PERF_RECORD_KSYMBOL] = "KSYMBOL",
> [PERF_RECORD_BPF_EVENT] = "BPF_EVENT",
> + [PERF_RECORD_CGROUP] = "CGROUP",
> [PERF_RECORD_HEADER_ATTR] = "ATTR",
> [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE",
> [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA",
> @@ -1279,6 +1280,12 @@ size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp)
> return ret;
> }
>
> +size_t perf_event__fprintf_cgroup(union perf_event *event, FILE *fp)
> +{
> + return fprintf(fp, " cgroup: %" PRI_lu64 " %s\n",
> + event->cgroup.ino, event->cgroup.path);
> +}
> +
> int perf_event__process_comm(struct perf_tool *tool __maybe_unused,
> union perf_event *event,
> struct perf_sample *sample,
> @@ -1295,6 +1302,14 @@ int perf_event__process_namespaces(struct perf_tool *tool __maybe_unused,
> return machine__process_namespaces_event(machine, event, sample);
> }
>
> +int perf_event__process_cgroup(struct perf_tool *tool __maybe_unused,
> + union perf_event *event,
> + struct perf_sample *sample,
> + struct machine *machine)
> +{
> + return machine__process_cgroup_event(machine, event, sample);
> +}
> +
> int perf_event__process_lost(struct perf_tool *tool __maybe_unused,
> union perf_event *event,
> struct perf_sample *sample,
> @@ -1516,6 +1531,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)
> case PERF_RECORD_NAMESPACES:
> ret += perf_event__fprintf_namespaces(event, fp);
> break;
> + case PERF_RECORD_CGROUP:
> + ret += perf_event__fprintf_cgroup(event, fp);
> + break;
> case PERF_RECORD_MMAP2:
> ret += perf_event__fprintf_mmap2(event, fp);
> break;
> diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
> index 429a3fe52d6c..0170435fd1e8 100644
> --- a/tools/perf/util/event.h
> +++ b/tools/perf/util/event.h
> @@ -123,6 +123,7 @@ struct perf_sample {
> u32 raw_size;
> u64 data_src;
> u64 phys_addr;
> + u64 cgroup;
> u32 flags;
> u16 insn_len;
> u8 cpumode;
> @@ -554,6 +555,7 @@ union perf_event {
> struct perf_record_mmap2 mmap2;
> struct perf_record_comm comm;
> struct perf_record_namespaces namespaces;
> + struct perf_record_cgroup cgroup;
> struct perf_record_fork fork;
> struct perf_record_lost lost;
> struct perf_record_lost_samples lost_samples;
> @@ -663,6 +665,10 @@ int perf_event__process_namespaces(struct perf_tool *tool,
> union perf_event *event,
> struct perf_sample *sample,
> struct machine *machine);
> +int perf_event__process_cgroup(struct perf_tool *tool,
> + union perf_event *event,
> + struct perf_sample *sample,
> + struct machine *machine);
> int perf_event__process_mmap(struct perf_tool *tool,
> union perf_event *event,
> struct perf_sample *sample,
> @@ -750,6 +756,7 @@ size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp);
> size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
> size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp);
> size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp);
> +size_t perf_event__fprintf_cgroup(union perf_event *event, FILE *fp);
> size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp);
> size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp);
> size_t perf_event__fprintf(union perf_event *event, FILE *fp);
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index fa676355559e..86a38679cad1 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -1593,6 +1593,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
> PRINT_ATTRf(ksymbol, p_unsigned);
> PRINT_ATTRf(bpf_event, p_unsigned);
> PRINT_ATTRf(aux_output, p_unsigned);
> + PRINT_ATTRf(cgroup, p_unsigned);
>
> PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned);
> PRINT_ATTRf(bp_type, p_unsigned);
> @@ -2369,6 +2370,12 @@ int perf_evsel__parse_sample(struct evsel *evsel, union perf_event *event,
> array++;
> }
>
> + data->cgroup = 0;
> + if (type & PERF_SAMPLE_CGROUP) {
> + data->cgroup = *array;
> + array++;
> + }
> +
> return 0;
> }
>
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index 93483f1764d3..61c35eef616b 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -642,6 +642,16 @@ int machine__process_namespaces_event(struct machine *machine __maybe_unused,
> return err;
> }
>
> +int machine__process_cgroup_event(struct machine *machine __maybe_unused,
> + union perf_event *event,
> + struct perf_sample *sample __maybe_unused)
> +{
> + if (dump_trace)
> + perf_event__fprintf_cgroup(event, stdout);
> +
> + return 0;
> +}
> +
> int machine__process_lost_event(struct machine *machine __maybe_unused,
> union perf_event *event, struct perf_sample *sample __maybe_unused)
> {
> @@ -1902,6 +1912,8 @@ int machine__process_event(struct machine *machine, union perf_event *event,
> ret = machine__process_mmap_event(machine, event, sample); break;
> case PERF_RECORD_NAMESPACES:
> ret = machine__process_namespaces_event(machine, event, sample); break;
> + case PERF_RECORD_CGROUP:
> + ret = machine__process_cgroup_event(machine, event, sample); break;
> case PERF_RECORD_MMAP2:
> ret = machine__process_mmap2_event(machine, event, sample); break;
> case PERF_RECORD_FORK:
> diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
> index 7d69119d0b5d..608813ced0cd 100644
> --- a/tools/perf/util/machine.h
> +++ b/tools/perf/util/machine.h
> @@ -127,6 +127,9 @@ int machine__process_switch_event(struct machine *machine,
> int machine__process_namespaces_event(struct machine *machine,
> union perf_event *event,
> struct perf_sample *sample);
> +int machine__process_cgroup_event(struct machine *machine,
> + union perf_event *event,
> + struct perf_sample *sample);
> int machine__process_mmap_event(struct machine *machine, union perf_event *event,
> struct perf_sample *sample);
> int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index 5786e9c807c5..2cdce7ee228c 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -457,6 +457,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
> tool->comm = process_event_stub;
> if (tool->namespaces == NULL)
> tool->namespaces = process_event_stub;
> + if (tool->cgroup == NULL)
> + tool->cgroup = process_event_stub;
> if (tool->fork == NULL)
> tool->fork = process_event_stub;
> if (tool->exit == NULL)
> @@ -1417,6 +1419,8 @@ static int machines__deliver_event(struct machines *machines,
> return tool->comm(tool, event, sample, machine);
> case PERF_RECORD_NAMESPACES:
> return tool->namespaces(tool, event, sample, machine);
> + case PERF_RECORD_CGROUP:
> + return tool->cgroup(tool, event, sample, machine);
> case PERF_RECORD_FORK:
> return tool->fork(tool, event, sample, machine);
> case PERF_RECORD_EXIT:
> diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
> index 2abbf668b8de..472ef5eb4068 100644
> --- a/tools/perf/util/tool.h
> +++ b/tools/perf/util/tool.h
> @@ -46,6 +46,7 @@ struct perf_tool {
> mmap2,
> comm,
> namespaces,
> + cgroup,
> fork,
> exit,
> lost,
> --
> 2.23.0.187.g17f5b7556c-goog

--

- Arnaldo

\
 
 \ /
  Last update: 2019-08-30 14:56    [W:0.217 / U:2.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site