Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1556942imm; Wed, 13 Jun 2018 23:25:43 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIcOkiM8IllWZpMoh7DbNwhzAx1RoL7R16PFJV0yjFWpLqmWQvO5D1J7CmrEHcKprC/th+U X-Received: by 2002:a17:902:ab95:: with SMTP id f21-v6mr1478675plr.264.1528957543783; Wed, 13 Jun 2018 23:25:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528957543; cv=none; d=google.com; s=arc-20160816; b=HSTR8mt7UB0yGYafIL355NktEVrzFenpSqNHKC/dab3kwODVV/xzuxIXMDSEUhJVOg 7NCIKLFA2ipxp7g5pZXyPg3yj6Mc/E+wZKWeIz8ebVHmNwcKyjaPEeb37Qu38vO8oQVd yfsVlKwLP9BP4kK8FDu625/bnbC0jjCQn1k22nwAarusXzHnGoh0Hzdj715aHNZuWKOG hmnLz33mWhvrIKfobQ3IZ1bpMdtDsw4T8YYsZDf+iT5LoiDUUQBurthq/DIQ8iAIzQHn 0Uvze9bxOHwjTJxCijZ3zj22G+j0qvjK+hwQZBlg4a0Ax0mGkNfBxRWgmgFBRgnMxofO Osrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=QGRxdyPqB48/ErqUG/MK0PzFpn3+QaGttUB6qF+qmTU=; b=Fn/Nk9AT0dIKhcIjCEcy8WyiMzqg2PTg/Rxgf69WX8OOloIvQ1w6pgwsk1ac48kXF5 XOp218lhn7fj8pebaXTOE+K0gwUFp35oljGuP1iRkzb2BHnwlXUjVZUDe0msifNAkVCU Ef8w2B6boIawXUJMAHp7s6pzfh8DqaKfou57eJktxma7gq6wvo1b3vlJLsM42CKzxI2S PIO08+BJ/6zv0P86pxGluEi9q4R95Al1CUuyxDfVSR8hEAqOQGRJVA+wDqy2TxNDE3Cy /MqVGwRANyOrfR1WQfdHjMDArXWagxZ8Pq9zKPAUSQ+sU31rjTS8akpMp+id1c/BIbTv ox7Q== ARC-Authentication-Results: i=1; mx.google.com; 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 v38-v6si4663301plg.283.2018.06.13.23.25.29; Wed, 13 Jun 2018 23:25:43 -0700 (PDT) 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; 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 S1754686AbeFNGXb (ORCPT + 99 others); Thu, 14 Jun 2018 02:23:31 -0400 Received: from terminus.zytor.com ([198.137.202.136]:56253 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752781AbeFNGX1 (ORCPT ); Thu, 14 Jun 2018 02:23:27 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w5E6MmgE763831 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 13 Jun 2018 23:22:48 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w5E6MmCV763828; Wed, 13 Jun 2018 23:22:48 -0700 Date: Wed, 13 Jun 2018 23:22:48 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Jiri Olsa Message-ID: Cc: jolsa@kernel.org, mingo@kernel.org, namhyung@kernel.org, hpa@zytor.com, tglx@linutronix.de, alexander.shishkin@linux.intel.com, dsahern@gmail.com, linux-kernel@vger.kernel.org, andi@firstfloor.org, acme@redhat.com, eranian@google.com, milian.wolff@kdab.com, frederic@kernel.org, peterz@infradead.org Reply-To: linux-kernel@vger.kernel.org, frederic@kernel.org, milian.wolff@kdab.com, eranian@google.com, andi@firstfloor.org, acme@redhat.com, peterz@infradead.org, mingo@kernel.org, jolsa@kernel.org, namhyung@kernel.org, tglx@linutronix.de, hpa@zytor.com, dsahern@gmail.com, alexander.shishkin@linux.intel.com In-Reply-To: <20180606221513.11302-6-jolsa@kernel.org> References: <20180606221513.11302-6-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf stat: Fix metric column header display alignment Git-Commit-ID: f515572734fb323aa0efe9ea2c546cd7fee327f7 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: f515572734fb323aa0efe9ea2c546cd7fee327f7 Gitweb: https://git.kernel.org/tip/f515572734fb323aa0efe9ea2c546cd7fee327f7 Author: Jiri Olsa AuthorDate: Thu, 7 Jun 2018 00:15:08 +0200 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 7 Jun 2018 15:59:13 -0300 perf stat: Fix metric column header display alignment Make the metric only display aligned. Before: # perf stat --topdown -I 1000 # time core cpus retiring bad speculation frontend bound backend bound 1.000394323 S0-C0 2 37.4% 12.0% 31.4% 19.2% 1.000394323 S0-C1 2 25.1% 9.2% 43.8% 21.9% 2.001521204 S0-C0 2 36.4% 11.4% 32.4% 19.8% 2.001521204 S0-C1 2 26.2% 9.4% 43.1% 21.3% 3.001930208 S0-C0 2 35.1% 10.7% 33.6% 20.6% 3.001930208 S0-C1 2 28.9% 10.0% 40.0% 21.1% After: # perf stat --topdown -I 1000 # time core cpus retiring bad speculation frontend bound backend bound 1.000303722 S0-C0 2 34.2% 7.6% 34.2% 24.0% 1.000303722 S0-C1 2 33.1% 6.4% 36.9% 23.6% 2.001281055 S0-C0 2 34.6% 6.7% 36.8% 21.8% 2.001281055 S0-C1 2 32.8% 7.1% 38.1% 22.0% 3.001546080 S0-C0 2 39.3% 5.5% 32.7% 22.5% 3.001546080 S0-C1 2 37.8% 6.0% 33.1% 23.1% Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Andi Kleen Cc: David Ahern Cc: Frederic Weisbecker Cc: Milian Wolff Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180606221513.11302-6-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-stat.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 9e7b6f108956..8f3fdc052728 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1001,19 +1001,20 @@ static void print_metric_only(void *ctx, const char *color, const char *fmt, { struct outstate *os = ctx; FILE *out = os->fh; - int n; - char buf[1024]; + char buf[1024], str[1024]; unsigned mlen = METRIC_ONLY_LEN; if (!valid_only_metric(unit)) return; unit = fixunit(buf, os->evsel, unit); - n = color_fprintf(out, color ?: "", fmt, val); - if (n > METRIC_ONLY_LEN) - n = METRIC_ONLY_LEN; if (mlen < strlen(unit)) mlen = strlen(unit) + 1; - fprintf(out, "%*s", mlen - n, ""); + + if (color) + mlen += strlen(color) + sizeof(PERF_COLOR_RESET) - 1; + + color_snprintf(str, sizeof(str), color ?: "", fmt, val); + fprintf(out, "%*s ", mlen, str); } static void print_metric_only_csv(void *ctx, const char *color __maybe_unused, @@ -1053,7 +1054,7 @@ static void print_metric_header(void *ctx, const char *color __maybe_unused, if (csv_output) fprintf(os->fh, "%s%s", unit, csv_sep); else - fprintf(os->fh, "%-*s ", METRIC_ONLY_LEN, unit); + fprintf(os->fh, "%*s ", METRIC_ONLY_LEN, unit); } static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg) @@ -1721,7 +1722,7 @@ static void print_interval(char *prefix, struct timespec *ts) fprintf(output, " counts %*s events\n", unit_width, "unit"); break; case AGGR_NONE: - fprintf(output, "# time CPU"); + fprintf(output, "# time CPU "); if (!metric_only) fprintf(output, " counts %*s events\n", unit_width, "unit"); break;