Skip to contentSkip to conversation

perf tools: Remove a trailing newline in the event terms

PATCH Applied Namhyung Kim 2 participants 3 messages Dec 2, 2025 – Dec 3, 2025 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf tools: Remove a trailing newline in the event terms

So that it can show the correct encoding info in the JSON output.

  $ perf list -j hw
  [
  {
          "Unit": "cpu",
          "Topic": "legacy hardware",
          "EventName": "branch-instructions",
          "EventType": "Kernel PMU event",
          "BriefDescription": "Retired branch instructions [This event is an alias of branches]",
          "Encoding": "cpu/event=0xc4/"
  },
  ...
---
 tools/perf/util/pmu.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/util/pmu.c +2 -0
index 1b7c712d8f9902bb..956ea273c2c7805c 100644
@@ -645,6 +645,8 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name,
 			pr_err("Failed to read alias %s\n", name);
 			return ret;
 		}
+		if (line_len >= 1 && alias->terms[line_len - 1] == '\n')
+			alias->terms[line_len - 1] = '\0';
 	}
 	alias->name = strdup(name);
 	alias->desc = desc ? strdup(desc) : NULL;
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Namhyung Kim

So that it can show the correct encoding info in the JSON output.

  $ perf list -j hw
  [
  {
          "Unit": "cpu",
          "Topic": "legacy hardware",
          "EventName": "branch-instructions",
          "EventType": "Kernel PMU event",
          "BriefDescription": "Retired branch instructions [This event is an alias of branches]",
          "Encoding": "cpu/event=0xc4/"
  },
  ...
Quoted 2 lines

Thanks!
Ian

Quoted 20 lines
---
 tools/perf/util/pmu.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/util/pmu.c +2 -1
index 1b7c712d8f9902bb..956ea273c2c7805c 100644
@@ -645,6 +645,8 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name,
                        pr_err("Failed to read alias %s\n", name);
                        return ret;
                }
+               if (line_len >= 1 && alias->terms[line_len - 1] == '\n')
+                       alias->terms[line_len - 1] = '\0';
        }
        alias->name = strdup(name);
        alias->desc = desc ? strdup(desc) : NULL;
--

2.52.0.158.g65b55ccf14-goog

author maintainer Applied
#2 lore raw
In reply to Namhyung Kim
Quoted 14 lines · Namhyung Kim

So that it can show the correct encoding info in the JSON output.

  $ perf list -j hw
  [
  {
          "Unit": "cpu",
          "Topic": "legacy hardware",
          "EventName": "branch-instructions",
          "EventType": "Kernel PMU event",
          "BriefDescription": "Retired branch instructions [This event is an alias of branches]",
          "Encoding": "cpu/event=0xc4/"
  },
  ...
Quoted 1 line

[...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung