Skip to contentSkip to conversation

perf stat: Expand metric+unit buffer size

PATCH Applied Ian Rogers 3 participants 7 messages Nov 6, 2024 – Nov 8, 2024 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf stat: Expand metric+unit buffer size

Long metric names combined with units may exceed the metric_bf and lead to truncation. Double metric_bf in size to avoid this.

---
 tools/perf/util/stat-shadow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/stat-shadow.c +1 -1
index 8c9292aa61d3..6b531d4f58a3 100644
@@ -507,7 +507,7 @@ static void generic_metric(struct perf_stat_config *config,
 	if (!metric_events[i]) {
 		if (expr__parse(&ratio, pctx, metric_expr) == 0) {
 			char *unit;
-			char metric_bf[64];
+			char metric_bf[128];
 
 			if (metric_threshold &&
 			    expr__parse(&threshold, pctx, metric_threshold) == 0 &&
Signature · 1 line
2.47.0.199.ga7371fff76-goog
#1 lore raw
Quoted 13 lines · Ian Rogers

Long metric names combined with units may exceed the metric_bf and lead to truncation. Double metric_bf in size to avoid this.

---
 tools/perf/util/stat-shadow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/stat-shadow.c +0 -0
index 8c9292aa61d3..6b531d4f58a3 100644

tools/perf/util/stat-shadow.c static void generic_metric(struct perf_stat_config *config, · line 510

Quoted 5 lines
tools/perf/util/stat-shadow.c +1 -1
@@ -507,7 +507,7 @@ static void generic_metric(struct perf_stat_config *config,
 	if (!metric_events[i]) {
 		if (expr__parse(&ratio, pctx, metric_expr) == 0) {
 			char *unit;
-			char metric_bf[64];
+			char metric_bf[128];

I thin there is already a MAX_EVENT_NAME.
Can we similarly define a MAX_METRIC_NAME for it?

Thanks,
Kan

Quoted 3 lines
tools/perf/util/stat-shadow.c +0 -0
 			if (metric_threshold &&
 			    expr__parse(&threshold, pctx, metric_threshold) == 0 &&
author reviewer
#2 lore raw
Quoted 12 lines · Kan
Quoted 8 lines · Ian Rogers

Long metric names combined with units may exceed the metric_bf and lead to truncation. Double metric_bf in size to avoid this.

---
 tools/perf/util/stat-shadow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

tools/perf/util/stat-shadow.c static void generic_metric(struct perf_stat_config *config, · line 510

Quoted 10 lines
tools/perf/util/stat-shadow.c +1 -1
index 8c9292aa61d3..6b531d4f58a3 100644
@@ -507,7 +507,7 @@ static void generic_metric(struct perf_stat_config *config,
      if (!metric_events[i]) {
              if (expr__parse(&ratio, pctx, metric_expr) == 0) {
                      char *unit;
-                     char metric_bf[64];
+                     char metric_bf[128];

I thin there is already a MAX_EVENT_NAME.
Can we similarly define a MAX_METRIC_NAME for it?

So in this case the buffer needs to be big enough to hold the metric name, the unit from the scaleunit (e.g. the "%" from "100%"). I'd prefer we used dynamic memory allocation to having hard coded limits, just to avoid a "640K ought to be enough for anybody," moment. Although this change is implicitly a hard coded limit, sigh. There is also the metric only name length:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/builtin-stat.c?h=perf-tools-next#n160
That looked like it was planned to be dynamically computed but then the patch adding that never materialized - meaning "standard" metric-only output has its own cut-off rules at 20 characters. I'd rather wait on doing a larger cleanup and do this quick fix for now, mainly as I have enough to do.

While we're talking metrics, I'm still looking for feedback on the python generation of metrics. v1 was sent back in January, if v4 looks okay some acknowledgement would be nice:
https://lore.kernel.org/lkml/CAP-5=fVX5wypmAAhR8LsE4nSWp5BmN_qhGf9+WCh2bebNcGYTg@mail.gmail.com/
Leo sent some feedback to improve some of the ARM metrics, so I can resend the whole series. Would be nice to gather some acked-by or other tags.

Thanks,
Ian

#3 lore raw
Quoted 27 lines · Ian Rogers
Quoted 12 lines · Kan
Quoted 8 lines · Ian Rogers

Long metric names combined with units may exceed the metric_bf and lead to truncation. Double metric_bf in size to avoid this.

---
 tools/perf/util/stat-shadow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

tools/perf/util/stat-shadow.c static void generic_metric(struct perf_stat_config *config, · line 510

Quoted 10 lines
tools/perf/util/stat-shadow.c +1 -1
index 8c9292aa61d3..6b531d4f58a3 100644
@@ -507,7 +507,7 @@ static void generic_metric(struct perf_stat_config *config,
      if (!metric_events[i]) {
              if (expr__parse(&ratio, pctx, metric_expr) == 0) {
                      char *unit;
-                     char metric_bf[64];
+                     char metric_bf[128];

I thin there is already a MAX_EVENT_NAME.
Can we similarly define a MAX_METRIC_NAME for it?

Quoted 12 lines

So in this case the buffer needs to be big enough to hold the metric name, the unit from the scaleunit (e.g. the "%" from "100%"). I'd prefer we used dynamic memory allocation to having hard coded limits, just to avoid a "640K ought to be enough for anybody," moment. Although this change is implicitly a hard coded limit, sigh. There is also the metric only name length:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/builtin-stat.c?h=perf-tools-next#n160
That looked like it was planned to be dynamically computed but then the patch adding that never materialized - meaning "standard" metric-only output has its own cut-off rules at 20 characters. I'd rather wait on doing a larger cleanup and do this quick fix for now, mainly as I have enough to do.

OK

Quoted 9 lines

While we're talking metrics, I'm still looking for feedback on the python generation of metrics. v1 was sent back in January, if v4 looks okay some acknowledgement would be nice:
https://lore.kernel.org/lkml/CAP-5=fVX5wypmAAhR8LsE4nSWp5BmN_qhGf9+WCh2bebNcGYTg@mail.gmail.com/
Leo sent some feedback to improve some of the ARM metrics, so I can resend the whole series. Would be nice to gather some acked-by or other tags.

Somehow I missed your last reply. I will take a look.

Thanks,
Kan

maintainer
#4 lore raw

Hi Kan,

Quoted 43 lines · Kan
Quoted 27 lines · Ian Rogers
Quoted 12 lines · Kan
Quoted 8 lines · Ian Rogers

Long metric names combined with units may exceed the metric_bf and lead to truncation. Double metric_bf in size to avoid this.

---
 tools/perf/util/stat-shadow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

tools/perf/util/stat-shadow.c static void generic_metric(struct perf_stat_config *config, · line 510

Quoted 10 lines
tools/perf/util/stat-shadow.c +1 -1
index 8c9292aa61d3..6b531d4f58a3 100644
@@ -507,7 +507,7 @@ static void generic_metric(struct perf_stat_config *config,
      if (!metric_events[i]) {
              if (expr__parse(&ratio, pctx, metric_expr) == 0) {
                      char *unit;
-                     char metric_bf[64];
+                     char metric_bf[128];

I thin there is already a MAX_EVENT_NAME.
Can we similarly define a MAX_METRIC_NAME for it?

Quoted 12 lines

So in this case the buffer needs to be big enough to hold the metric name, the unit from the scaleunit (e.g. the "%" from "100%"). I'd prefer we used dynamic memory allocation to having hard coded limits, just to avoid a "640K ought to be enough for anybody," moment. Although this change is implicitly a hard coded limit, sigh. There is also the metric only name length:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/builtin-stat.c?h=perf-tools-next#n160
That looked like it was planned to be dynamically computed but then the patch adding that never materialized - meaning "standard" metric-only output has its own cut-off rules at 20 characters. I'd rather wait on doing a larger cleanup and do this quick fix for now, mainly as I have enough to do.

Quoted 1 line

OK

Can I assume it as Acked-by?

Thanks,
Namhyung

Acked-by
#5 lore raw
Quoted 46 lines · Namhyung Kim

Hi Kan,

Quoted 43 lines · Kan
Quoted 39 lines · Ian Rogers
Quoted 12 lines · Kan
Quoted 8 lines · Ian Rogers

Long metric names combined with units may exceed the metric_bf and lead to truncation. Double metric_bf in size to avoid this.

---
 tools/perf/util/stat-shadow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

tools/perf/util/stat-shadow.c static void generic_metric(struct perf_stat_config *config, · line 510

Quoted 10 lines
tools/perf/util/stat-shadow.c +1 -1
index 8c9292aa61d3..6b531d4f58a3 100644
@@ -507,7 +507,7 @@ static void generic_metric(struct perf_stat_config *config,
      if (!metric_events[i]) {
              if (expr__parse(&ratio, pctx, metric_expr) == 0) {
                      char *unit;
-                     char metric_bf[64];
+                     char metric_bf[128];

I thin there is already a MAX_EVENT_NAME.
Can we similarly define a MAX_METRIC_NAME for it?

So in this case the buffer needs to be big enough to hold the metric name, the unit from the scaleunit (e.g. the "%" from "100%"). I'd prefer we used dynamic memory allocation to having hard coded limits, just to avoid a "640K ought to be enough for anybody," moment. Although this change is implicitly a hard coded limit, sigh. There is also the metric only name length:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/builtin-stat.c?h=perf-tools-next#n160
That looked like it was planned to be dynamically computed but then the patch adding that never materialized - meaning "standard" metric-only output has its own cut-off rules at 20 characters. I'd rather wait on doing a larger cleanup and do this quick fix for now, mainly as I have enough to do.

Quoted 4 lines
Quoted 1 line

OK

Can I assume it as Acked-by?

Yes.

Thanks,
Kan

Quoted 3 lines

Thanks,
Namhyung

maintainer Applied
#6 lore raw
In reply to Ian Rogers
Quoted 4 lines · Ian Rogers

Long metric names combined with units may exceed the metric_bf and lead to truncation. Double metric_bf in size to avoid this.

Applied to perf-tools-next, thanks!

Best regards,
Namhyung