[01/11] perf stat: Fix crash with --per-node --metric-only in CSV mode

Message ID 20221112032244.1077370-2-namhyung@kernel.org
State New
Headers
Series perf stat: Cleanup perf stat output display (v2) |

Commit Message

Namhyung Kim Nov. 12, 2022, 3:22 a.m. UTC
  The following command will get segfault due to missing aggr_header_csv
for AGGR_NODE:

  $ sudo perf stat -a --per-node -x, --metric-only true

Fixes: 86895b480a2f ("perf stat: Add --per-node agregation support")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/stat-display.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Ian Rogers Nov. 14, 2022, 6:17 p.m. UTC | #1
On Fri, Nov 11, 2022 at 7:22 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> The following command will get segfault due to missing aggr_header_csv
> for AGGR_NODE:
>
>   $ sudo perf stat -a --per-node -x, --metric-only true
>
> Fixes: 86895b480a2f ("perf stat: Add --per-node agregation support")
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/util/stat-display.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
> index 657434cd29ee..ea41e6308c50 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
> @@ -534,7 +534,7 @@ static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int
>                         [AGGR_CORE] = 2,
>                         [AGGR_THREAD] = 1,
>                         [AGGR_UNSET] = 0,
> -                       [AGGR_NODE] = 0,
> +                       [AGGR_NODE] = 1,
>                 };
>
>                 pm = config->metric_only ? print_metric_only_csv : print_metric_csv;
> @@ -819,6 +819,7 @@ static int aggr_header_lens[] = {
>         [AGGR_SOCKET] = 12,
>         [AGGR_NONE] = 6,
>         [AGGR_THREAD] = 24,
> +       [AGGR_NODE] = 6,
>         [AGGR_GLOBAL] = 0,
>  };
>
> @@ -828,6 +829,7 @@ static const char *aggr_header_csv[] = {
>         [AGGR_SOCKET]   =       "socket,cpus",
>         [AGGR_NONE]     =       "cpu,",
>         [AGGR_THREAD]   =       "comm-pid,",
> +       [AGGR_NODE]     =       "node,",
>         [AGGR_GLOBAL]   =       ""
>  };
>
> --
> 2.38.1.493.g58b659f92b-goog
>
  

Patch

diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index 657434cd29ee..ea41e6308c50 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -534,7 +534,7 @@  static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int
 			[AGGR_CORE] = 2,
 			[AGGR_THREAD] = 1,
 			[AGGR_UNSET] = 0,
-			[AGGR_NODE] = 0,
+			[AGGR_NODE] = 1,
 		};
 
 		pm = config->metric_only ? print_metric_only_csv : print_metric_csv;
@@ -819,6 +819,7 @@  static int aggr_header_lens[] = {
 	[AGGR_SOCKET] = 12,
 	[AGGR_NONE] = 6,
 	[AGGR_THREAD] = 24,
+	[AGGR_NODE] = 6,
 	[AGGR_GLOBAL] = 0,
 };
 
@@ -828,6 +829,7 @@  static const char *aggr_header_csv[] = {
 	[AGGR_SOCKET] 	= 	"socket,cpus",
 	[AGGR_NONE] 	= 	"cpu,",
 	[AGGR_THREAD] 	= 	"comm-pid,",
+	[AGGR_NODE] 	= 	"node,",
 	[AGGR_GLOBAL] 	=	""
 };