Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933818AbdDGOYr (ORCPT ); Fri, 7 Apr 2017 10:24:47 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35110 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756628AbdDGOYf (ORCPT ); Fri, 7 Apr 2017 10:24:35 -0400 From: Taeung Song To: Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Namhyung Kim , Ingo Molnar , Peter Zijlstra , Wang Nan , Masami Hiramatsu , Taeung Song , Andi Kleen Subject: [PATCH 2/5] perf stat: Refactor the code to strip csv output with ltrim() Date: Fri, 7 Apr 2017 23:24:18 +0900 Message-Id: <1491575061-704-3-git-send-email-treeze.taeung@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491575061-704-1-git-send-email-treeze.taeung@gmail.com> References: <1491575061-704-1-git-send-email-treeze.taeung@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1158 Lines: 41 To strip csv output, use ltrim() instead of just while loop and isspace() at print_metric_{only}_csv(). Cc: Andi Kleen Cc: Jiri Olsa Cc: Namhyung Kim Signed-off-by: Taeung Song --- tools/perf/builtin-stat.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 2158ea1..868e086a 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -875,10 +875,7 @@ static void print_metric_csv(void *ctx, return; } snprintf(buf, sizeof(buf), fmt, val); - vals = buf; - while (isspace(*vals)) - vals++; - ends = vals; + ends = vals = ltrim(buf); while (isdigit(*ends) || *ends == '.') ends++; *ends = 0; @@ -950,10 +947,7 @@ static void print_metric_only_csv(void *ctx, const char *color __maybe_unused, return; unit = fixunit(tbuf, os->evsel, unit); snprintf(buf, sizeof buf, fmt, val); - vals = buf; - while (isspace(*vals)) - vals++; - ends = vals; + ends = vals = ltrim(buf); while (isdigit(*ends) || *ends == '.') ends++; *ends = 0; -- 2.7.4