Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2974995imu; Wed, 7 Nov 2018 02:52:51 -0800 (PST) X-Google-Smtp-Source: AJdET5chh8XAjfOblmzDpTutCFWd9T8Yc4/acjXRIQCTlhsDpL/YZyHo0uUKdxaxXQzW6SMcRV2Q X-Received: by 2002:a63:4706:: with SMTP id u6mr1071953pga.95.1541587971286; Wed, 07 Nov 2018 02:52:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541587971; cv=none; d=google.com; s=arc-20160816; b=RSVxNK378rh55IJp24Pwhx3GrczfClCLB2QODVgN7X8JpB9jl/eq28KOwL3JM1CezI V8gRmi6dk7d9ZpYwy/M706sf0kvebX6IOjK12gsDF/qY9fseTaw0gGekwfR7i4dlAsSx deo9HV8mUg+bSNIuQwRWVp9lwUjnGF6sckk25CwGyMWctiXUZO1jpvozUbfAitZhoqUS nRmOCrVHnFyUQOiyxqTG14hM6Kxg2zTwJZKpCYkM/2pro9WiK1f6iDvPJeXNgje6mSD7 uv9bkJBSla7fAjZIBihYWvsvd49AQOP5W+tvphKyJnBOvkSax0Y9zvwh6bzr4Yyw7aYR gGNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=sEv3uOrcvNCjZbB1HGF/zWr7WB0LAuhTeYz66AM57eQ=; b=ulxtBnqNhTAIOOJBRxvZcs46dbekvSkbwNuYySj7hyGszjMsuf6cJzYJHH9teTlROj Rgd+O+RjGmzavPY6bTWUssmC3NeQSA2zQ7g/biF8e9DBIQwDE2SokY00yxhEn6OfRHxJ TTTFLHqmHv5V1VPl3D/2WOXw7tLGpgGk2BNFkqSNIBWypNZgsgCSQl8BjdEF043+0O+8 b9irSJi8Bjk5JxmbLVaTla1NV0OhblaPw5TTVJv30WNMaoXaxrHhzeG8jC2GLopI4v1A Dzsvto+Bbtadj7lleggZSaN6O5MpEVAVdkTuw+Mctj02SPHHAB4ZwjU27s2p3aIsnosE H0OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WPwqqOPt; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8-v6si242147pgj.192.2018.11.07.02.52.36; Wed, 07 Nov 2018 02:52:51 -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=@google.com header.s=20161025 header.b=WPwqqOPt; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726493AbeKGUUj (ORCPT + 99 others); Wed, 7 Nov 2018 15:20:39 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34392 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbeKGUUj (ORCPT ); Wed, 7 Nov 2018 15:20:39 -0500 Received: by mail-wr1-f66.google.com with SMTP id j26-v6so16891978wre.1 for ; Wed, 07 Nov 2018 02:50:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=sEv3uOrcvNCjZbB1HGF/zWr7WB0LAuhTeYz66AM57eQ=; b=WPwqqOPteOe4Ny4fxv+Vd6sqyX1NXIzXgunkzdnvywvoI/x3ffgKqpqTxPj0a86vme MspQTzgqJNIF9FN+oz3ISh4A1+eUtgePt0Ae3l7iF3AmoTkfLZqnkgqOnk3UBsW5ldLy YBFl3zH2EflaQPNS6AKZRvg0972jWONuObF9WbqZNpVL//s+hXH23/zFMcGLq5Vf46o8 hKcJ1o2PFqD3oxN3vXhJcJ/mUb7jpZrTILIgABWjJylD2hPetLfMIhuVUvbPOE2WVLY7 n1sxf0HfLftakYjrhOEHOg/9SQcL7WNtJLAoH7pjkXFkCUMX2+MMG3hWpdvJThMaVp6r fGSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=sEv3uOrcvNCjZbB1HGF/zWr7WB0LAuhTeYz66AM57eQ=; b=B9l5DMMms37Lk5jBa3+lr3Js/RMMs8nC/CB9yRv5tRa55FBskvGjE82Zt2TsQGHz4a UALMTXKnTiwaaWnhcIwdGJVppfKgKYkID2AD+0EyX6T53FfJiw2MdrYF4Px83yLI4AvO RVFrdWkh65f/p18wChIVKataONt8X+ofxxyy0eeufpCMWrH39xVdfby46BbKWTVCF8XE ACBERpKg2mgfxUPpOnVzKUhaEQpvUaALrCAmNvFF8YZkJItfoc9KD8MSsGui6u6HUfp3 /IfUX/A1vRP0ZcLyxI0AfMawGlmz6cLnw0faDAx6mZGNCN6Jh61sWG6rGfUOW5A3OdFA BoxQ== X-Gm-Message-State: AGRZ1gLPcz45e4iTekbz53nf6uua8dPywQhqWJ7xvJRPuEX1zpD73p8B QS+biW+lG1HUSi6PmJ4AHxi23l/rsIR0Qg== X-Received: by 2002:adf:9022:: with SMTP id h31-v6mr1439150wrh.297.1541587847852; Wed, 07 Nov 2018 02:50:47 -0800 (PST) Received: from localhost ([104.132.117.109]) by smtp.gmail.com with ESMTPSA id x16-v6sm330736wro.28.2018.11.07.02.50.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 02:50:47 -0800 (PST) From: Stephane Eranian To: linux-kernel@vger.kernel.org Cc: acme@redhat.com, peterz@infradead.org, mingo@elte.hu, jolsa@redhat.com Subject: [PATCH] perf stat: fix csv mode column output for non-cgroup events Date: Wed, 7 Nov 2018 02:50:45 -0800 Message-Id: <1541587845-9150-1-git-send-email-eranian@google.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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.7.4