Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2757071imj; Mon, 11 Feb 2019 08:02:38 -0800 (PST) X-Google-Smtp-Source: AHgI3IZTHzdzhPKvY4oJJW+s9Zfj1C3JOyDGe1yu7F5i9qhsYZGAZEi5++QDpVIeKLBZJlTHURWB X-Received: by 2002:a62:47d9:: with SMTP id p86mr36593242pfi.95.1549900958821; Mon, 11 Feb 2019 08:02:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549900958; cv=none; d=google.com; s=arc-20160816; b=SrEGyQARKMNsoPtJmUEJkSsdSMsrDWowCOpVSDlW7OIR3dtmKU/7TC6l/U3Xg751PP GVxasjmwBpSe2EeM+gufDKCAGyR24F7+KFihVUfRDMMOajaxBKMR4hHa/u6bPcAO0h0R 0JbcpgUh4RdhMZp6tNCLennC6Y+tTabaNa7468meBUBJz0Wkquc96TLPPqpFF9i8rK6E VqduI8n5BATrcOU+5lzYtM072ZXjrcscm+ySDvdf7BmeGMvecOlTqgULLOaU8aIM1WuS N6loW3hRG72MuZqv6NWiF29gs59HcjiNqBJsIo7yxu1pgwczkOrvIbeGlIntgIWFsXMZ evxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=K/AVL9b+sVFIjeuEezChZy6dBJWoRPxw9Na0HAc+bis=; b=pkV3Umm40G7rFxPDXKusnrCVOFi5Z5Q1+y/EdQDuQ28HlKgxS3/UabrHplU0lh24hF 89oV8xUX+Byjhu7wN+YALlhwgMQ65072/GROeTaEVhvO9CyKlBqsDOr/P5/J0JqGJq0f KOymiL92K8pslOzgUPtNlHVcmnytXth7/bgcrazcLSW7XnlokTnfRPG6c9BVdvYUcb/o 5x8Y4+NL1rJYlpT7tPxkkG82H0FiU+jFJllbCJ1yEYMmbDFX0o3dp/yfwvWO3JoeGsjW 2IGkSXPgqsDzApbLrIlUlcFxtvbsk9Jsp4mFpDybE9Gj5dB98MDuKh+ZFO0boWC/eGT6 s4fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ljJVCF7T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u17si10496504pfi.7.2019.02.11.08.02.19; Mon, 11 Feb 2019 08:02:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ljJVCF7T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730266AbfBKObR (ORCPT + 99 others); Mon, 11 Feb 2019 09:31:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:38000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730264AbfBKObO (ORCPT ); Mon, 11 Feb 2019 09:31:14 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E841620675; Mon, 11 Feb 2019 14:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895473; bh=dCPESDjZWOA6hnQ0Ai4567Y/M4VnAQS0tDUfPuk5Lzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ljJVCF7T9r38Ry3HCmGHGxCUo7eGpfco52h97hKAGmn7Pq73Ibjitz/fZXx+5Rzjr CVZGfDXh0oPRwPgRrIBGdVggosGkf0QCsCxbIDHlzi2oibVNH9JgjJASkDB99xmC/t +Uk8NUw4TZktpTFgiuqRlrXPjNtTzPWS6BT7pdGc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephane Eranian , Jiri Olsa , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.20 185/352] perf stat: Fix CSV mode column output for non-cgroup events Date: Mon, 11 Feb 2019 15:16:52 +0100 Message-Id: <20190211141858.884488697@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit bc4da38a4789e7819fca4c7723ded0b86aea27c0 ] When using the -x option, perf stat prints CSV-style output with one event per line. For each event, it prints the count, the unit, the event name, the cgroup, and a bunch of other event specific fields (such as insn per cycles). When you use CSV-style mode, you expect a normalized output where each event is printed with the same number of fields regardless of what it is so it can easily be imported into a spreadsheet or parsed. For instance, if an event does not have a unit, then print an empty field for it. Although this approach was implemented for the unit, it was not for the cgroup. When mixing cgroup and non-cgroup events, then non-cgroup events would not show an empty field, instead the next field was printed, make columns not line up correctly. This patch fixes the cgroup output issues by forcing an empty field for non-cgroup events as soon as one event has cgroup. Before: @ @cycles @foo @ 0 @100.00@@ 2531614 @ @cycles @6420922@100.00@ @ foo cgroup lines up with time_running! After: @ @cycles @foo @0 @100.00@@ 2594834 @ @cycles @ @5287372 @100.00@@ Fields line up. Signed-off-by: Stephane Eranian Acked-by: Jiri Olsa Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1541587845-9150-1-git-send-email-eranian@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/stat-display.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index e7b4c44ebb62..665ee374fc01 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -59,6 +59,15 @@ static void print_noise(struct perf_stat_config *config, print_noise_pct(config, stddev_stats(&ps->res_stats[0]), avg); } +static void print_cgroup(struct perf_stat_config *config, struct perf_evsel *evsel) +{ + if (nr_cgroups) { + const char *cgrp_name = evsel->cgrp ? evsel->cgrp->name : ""; + fprintf(config->output, "%s%s", config->csv_sep, cgrp_name); + } +} + + static void aggr_printout(struct perf_stat_config *config, struct perf_evsel *evsel, int id, int nr) { @@ -336,8 +345,7 @@ static void abs_printout(struct perf_stat_config *config, fprintf(output, "%-*s", config->csv_output ? 0 : 25, perf_evsel__name(evsel)); - if (evsel->cgrp) - fprintf(output, "%s%s", config->csv_sep, evsel->cgrp->name); + print_cgroup(config, evsel); } static bool is_mixed_hw_group(struct perf_evsel *counter) @@ -431,9 +439,7 @@ static void printout(struct perf_stat_config *config, int id, int nr, config->csv_output ? 0 : -25, perf_evsel__name(counter)); - if (counter->cgrp) - fprintf(config->output, "%s%s", - config->csv_sep, counter->cgrp->name); + print_cgroup(config, counter); if (!config->csv_output) pm(config, &os, NULL, NULL, "", 0); -- 2.19.1