Skip to contentSkip to conversation

perf record: Synthesize cgroup events only if needed

PATCH In review Namhyung Kim 3 participants 5 messages Nov 27, 2020 – Nov 30, 2020 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf record: Synthesize cgroup events only if needed

It didn't check the tool->cgroup_events bit which is set when the --all-cgroups option is given. Without it, samples will not have cgroup info so no reason to synthesize.

We can check the PERF_RECORD_CGROUP records after running perf record *WITHOUT* the --all-cgroups option:

Before:

  $ perf report -D | grep CGROUP
  0 0 0x8430 [0x38]: PERF_RECORD_CGROUP cgroup: 1 /
          CGROUP events:          1
          CGROUP events:          0
          CGROUP events:          0

After:

  $ perf report -D | grep CGROUP
          CGROUP events:          0
          CGROUP events:          0
          CGROUP events:          0
Fixes 8fb4b67939e16 ("perf record: Add --all-cgroups option")
---
 tools/perf/util/synthetic-events.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/synthetic-events.c +3 -0
index 8a23391558cf..d9c624377da7 100644
@@ -563,6 +563,9 @@ int perf_event__synthesize_cgroups(struct perf_tool *tool,
 	char cgrp_root[PATH_MAX];
 	size_t mount_len;  /* length of mount point in the path */
 
+	if (!tool || !tool->cgroup_events)
+		return 0;
+
 	if (cgroupfs_find_mountpoint(cgrp_root, PATH_MAX, "perf_event") < 0) {
 		pr_debug("cannot find cgroup mount point\n");
 		return -1;
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 31 lines · Namhyung Kim

It didn't check the tool->cgroup_events bit which is set when the --all-cgroups option is given. Without it, samples will not have cgroup info so no reason to synthesize.

We can check the PERF_RECORD_CGROUP records after running perf record *WITHOUT* the --all-cgroups option:

Before:

  $ perf report -D | grep CGROUP
  0 0 0x8430 [0x38]: PERF_RECORD_CGROUP cgroup: 1 /
          CGROUP events:          1
          CGROUP events:          0
          CGROUP events:          0

After:

  $ perf report -D | grep CGROUP
          CGROUP events:          0
          CGROUP events:          0
          CGROUP events:          0
Fixes 8fb4b67939e16 ("perf record: Add --all-cgroups option")
---
 tools/perf/util/synthetic-events.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/synthetic-events.c +0 -0
index 8a23391558cf..d9c624377da7 100644

tools/perf/util/synthetic-events.c int perf_event__synthesize_cgroups(struct perf_tool *tool, · line 567

Quoted 5 lines
tools/perf/util/synthetic-events.c +2 -0
@@ -563,6 +563,9 @@ int perf_event__synthesize_cgroups(struct perf_tool *tool,
 	char cgrp_root[PATH_MAX];
 	size_t mount_len;  /* length of mount point in the path */
 
+	if (!tool || !tool->cgroup_events)
+		return 0;

can !tool actually happen here? or it's just being extra cautious

thanks,
jirka

Quoted 7 lines
tools/perf/util/synthetic-events.c +1 -0
+
 	if (cgroupfs_find_mountpoint(cgrp_root, PATH_MAX, "perf_event") < 0) {
 		pr_debug("cannot find cgroup mount point\n");
 		return -1;
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
#2 lore raw

Em Fri, Nov 27, 2020 at 04:45:57PM +0100, Jiri Olsa escreveu:

Quoted 35 lines · Namhyung Kim
Quoted 34 lines

It didn't check the tool->cgroup_events bit which is set when the --all-cgroups option is given. Without it, samples will not have cgroup info so no reason to synthesize.

We can check the PERF_RECORD_CGROUP records after running perf record *WITHOUT* the --all-cgroups option:

Before:

  $ perf report -D | grep CGROUP
  0 0 0x8430 [0x38]: PERF_RECORD_CGROUP cgroup: 1 /
          CGROUP events:          1
          CGROUP events:          0
          CGROUP events:          0

After:

  $ perf report -D | grep CGROUP
          CGROUP events:          0
          CGROUP events:          0
          CGROUP events:          0
Fixes 8fb4b67939e16 ("perf record: Add --all-cgroups option")
---
 tools/perf/util/synthetic-events.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/synthetic-events.c +0 -0
index 8a23391558cf..d9c624377da7 100644
@@ -563,6 +563,9 @@ int perf_event__synthesize_cgroups(struct perf_tool *tool,
 	char cgrp_root[PATH_MAX];
 	size_t mount_len;  /* length of mount point in the path */
 
Quoted 6 lines

tools/perf/util/synthetic-events.c int perf_event__synthesize_cgroups(struct perf_tool *tool, · line 567

Quoted 2 lines
tools/perf/util/synthetic-events.c +2 -0
+	if (!tool || !tool->cgroup_events)
+		return 0;

can !tool actually happen here? or it's just being extra cautious

Thanks, tested with/without --all-cgroups and applied.

- Arnaldo

author maintainer
#3 lore raw

Hi Arnaldo,

Quoted 37 lines · Arnaldo Carvalho de Melo

Em Fri, Nov 27, 2020 at 04:45:57PM +0100, Jiri Olsa escreveu:

Quoted 35 lines · Namhyung Kim
Quoted 34 lines

It didn't check the tool->cgroup_events bit which is set when the --all-cgroups option is given. Without it, samples will not have cgroup info so no reason to synthesize.

We can check the PERF_RECORD_CGROUP records after running perf record *WITHOUT* the --all-cgroups option:

Before:

  $ perf report -D | grep CGROUP
  0 0 0x8430 [0x38]: PERF_RECORD_CGROUP cgroup: 1 /
          CGROUP events:          1
          CGROUP events:          0
          CGROUP events:          0

After:

  $ perf report -D | grep CGROUP
          CGROUP events:          0
          CGROUP events:          0
          CGROUP events:          0
Fixes 8fb4b67939e16 ("perf record: Add --all-cgroups option")
---
 tools/perf/util/synthetic-events.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/synthetic-events.c +0 -0
index 8a23391558cf..d9c624377da7 100644
@@ -563,6 +563,9 @@ int perf_event__synthesize_cgroups(struct perf_tool *tool,
    char cgrp_root[PATH_MAX];
    size_t mount_len;  /* length of mount point in the path */
 
Quoted 8 lines
Quoted 6 lines

tools/perf/util/synthetic-events.c int perf_event__synthesize_cgroups(struct perf_tool *tool, · line 567

Quoted 2 lines
tools/perf/util/synthetic-events.c +2 -0
+   if (!tool || !tool->cgroup_events)
+           return 0;

can !tool actually happen here? or it's just being extra cautious

Thanks, tested with/without --all-cgroups and applied.

Thanks for doing that!

Namhyung

author maintainer
#4 lore raw
In reply to Jiri Olsa

Hi Jiri,

Quoted 36 lines · Jiri Olsa
Quoted 34 lines · Namhyung Kim

It didn't check the tool->cgroup_events bit which is set when the --all-cgroups option is given. Without it, samples will not have cgroup info so no reason to synthesize.

We can check the PERF_RECORD_CGROUP records after running perf record *WITHOUT* the --all-cgroups option:

Before:

  $ perf report -D | grep CGROUP
  0 0 0x8430 [0x38]: PERF_RECORD_CGROUP cgroup: 1 /
          CGROUP events:          1
          CGROUP events:          0
          CGROUP events:          0

After:

  $ perf report -D | grep CGROUP
          CGROUP events:          0
          CGROUP events:          0
          CGROUP events:          0
Fixes 8fb4b67939e16 ("perf record: Add --all-cgroups option")
---
 tools/perf/util/synthetic-events.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/synthetic-events.c +0 -0
index 8a23391558cf..d9c624377da7 100644
@@ -563,6 +563,9 @@ int perf_event__synthesize_cgroups(struct perf_tool *tool,
      char cgrp_root[PATH_MAX];
      size_t mount_len;  /* length of mount point in the path */
 
Quoted 4 lines

tools/perf/util/synthetic-events.c int perf_event__synthesize_cgroups(struct perf_tool *tool, · line 567

Quoted 2 lines
tools/perf/util/synthetic-events.c +2 -0
+     if (!tool || !tool->cgroup_events)
+             return 0;

can !tool actually happen here? or it's just being extra cautious

Actually I just copied the namespace code. :).
It's only called from perf record and top, and neither of them pass NULL.

Quoted 2 lines

Thanks,
Namhyung