Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6192360rwb; Mon, 14 Nov 2022 16:06:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf5H1HyEjeFODQmzjCI/HIEgpeyI6zSG2GHBaS03EcaPkanELEyNEXVzUrk7HbqS+p2HWVLj X-Received: by 2002:a17:902:f10c:b0:186:cbf1:27e3 with SMTP id e12-20020a170902f10c00b00186cbf127e3mr1414763plb.143.1668470788874; Mon, 14 Nov 2022 16:06:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668470788; cv=none; d=google.com; s=arc-20160816; b=MKeazyJdHhCHKL9xRwHyiZSv4L1/ETOXIrlOjqynv7opLZHKepa9hk3K71rO5KwbBu AomElmsHwXCReRf7KLqWOCPVQaU7lZF8a3TDY1dIS1BSCnzC9p/vOPRjIZJxQQMOk/mZ kYD4aZ5F59bOKZh4Qqz0dkIL4w6i9awYikOx2qD6mVgMyoRSRRBZJjLj6/a5kk7BW8uj W7lu8th2VfBrsPpdyrUu4CmzxuQpnyHIa+sggRUDELcHvzwit0jTQ5vwyVM4fRUm8tKZ kVIuc6VLKFZ9Br6JudQiv0QbrQCfy8FG8+83KGJVz7wFpXBAnbSBwv8nKUIcP5iKU5ZY enKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=g9gVgzaugGBijq/uNgO/XLVSIa4Ghp/O4hPteTZwehU=; b=dz+CmLo/wDMh94il49O8N+vIqu0RNy1GGLSl7IzbfLUeKRZgSw8Yr3egfYjE6Nn0Vo P4gIYUK1vHsivC2UFvmtOHnnj9wREI1vn05xzU7reNqtoqZM5yjT0EJMY+Ge7Ioif65b ukySerZ0Vs4uH6tcU+A5aER5jxc+4iXe9JWrYsOcwFA8ugOYVPBLLPdmjSP2h4YQSndN ScUjmvG1WxmsyZ058688xhXb1dmZhJNho7OGuVszjXHb226xY7v8QGyl+xh6iZOV/g5k bwv4JlBcztBbYivFQ16iM69eW99ieQb2+mNTLizvXkyNu277xzxzW2JU5KEglm3zheeJ mHFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=P8ggZH5F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 20-20020a630514000000b0045a8b142a48si10951296pgf.657.2022.11.14.16.06.17; Mon, 14 Nov 2022 16:06:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=P8ggZH5F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237977AbiKNXDD (ORCPT + 88 others); Mon, 14 Nov 2022 18:03:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237878AbiKNXCg (ORCPT ); Mon, 14 Nov 2022 18:02:36 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96E861B9C0; Mon, 14 Nov 2022 15:02:33 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id w23so5069001ply.12; Mon, 14 Nov 2022 15:02:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=g9gVgzaugGBijq/uNgO/XLVSIa4Ghp/O4hPteTZwehU=; b=P8ggZH5FleD5Kv20TgngyEO98qnMIP+IsgWyIAedDwGn9PltGQOruty/I/EBflF9jY Y9aAWqJGxZ6sYB/SEl+gL4P753EPvL+bZd2ZG2uWnEHn9GSH8nezaQ/1rJJeMjR9T91S K91fp0aQN/6P8jV8qiuaqS6vqfU3ODpplDsCgKJu/3zYjBWxIqa+310hRfF+hDGIYv2E OEMVFoY95QIowZI04HJaFiQ7ixcLAgPKGj1crbjaUUN211lBL0y2ZlJT3ZdaLvqrEM1P HOLZYpkKRhZZLjYY7KuYHKzlcaigqUeDzJzq2xm/VRPvZc5Tsmc0i5nFx74APmrLeRoi KSjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=g9gVgzaugGBijq/uNgO/XLVSIa4Ghp/O4hPteTZwehU=; b=CdmM80VIuA/zy0NsrWqAnyKenwrBS+ryRwn4E1gshzCkTQRndZeo60R8cn7OkmUW/m CZDHLcMXG9djTtFbmGB2Ex6XAJc4wUMXGSgOkM+RMhgCF8/ynUrcAi4p4pqPcikWFUk7 RQEY6ym1g3hKGpiKeXpa1zLL1WMqxi7kohGnVecNVvMlUsDS9WVLl9HF6O759P1TyywR D/CAheNCkWIP2x5SL683Hi9PLhDcHim3rbT3FoeHaLvIKvQbZAg4Rt2EcvKOPkWe7yu3 utDTLC6VoAHZPLhla14uSkR0ZVBqOG0221rmylxWQ4btwe4tf3PD59k5QmCqaTdgdmME nwHQ== X-Gm-Message-State: ANoB5pksApLHw4rzxGgJ5a5pdU9vD4JAh583bwbHIiDwk+CVhZN7ACXW EplVbBR6P1uXqjiR5CZiivA= X-Received: by 2002:a17:90a:fa11:b0:212:6a0b:7d55 with SMTP id cm17-20020a17090afa1100b002126a0b7d55mr15484594pjb.16.1668466953078; Mon, 14 Nov 2022 15:02:33 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:a80:cf9f:e038:c19b:797e]) by smtp.gmail.com with ESMTPSA id 132-20020a62148a000000b0056c814a501dsm7534724pfu.10.2022.11.14.15.02.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:32 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark , Athira Jajeev Subject: [PATCH 02/19] perf stat: Split print_running() function Date: Mon, 14 Nov 2022 15:02:10 -0800 Message-Id: <20221114230227.1255976-3-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.493.g58b659f92b-goog In-Reply-To: <20221114230227.1255976-1-namhyung@kernel.org> References: <20221114230227.1255976-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To make the code more obvious and hopefully simpler, factor out the code for each output mode - stdio, CSV, JSON. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 37 +++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 2a3c1e0098b9..281b811f8574 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -25,24 +25,41 @@ #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" -static void print_running(struct perf_stat_config *config, - u64 run, u64 ena) +static void print_running_std(struct perf_stat_config *config, u64 run, u64 ena) +{ + if (run != ena) + fprintf(config->output, " (%.2f%%)", 100.0 * run / ena); +} + +static void print_running_csv(struct perf_stat_config *config, u64 run, u64 ena) { + double enabled_percent = 100; + + if (run != ena) + enabled_percent = 100 * run / ena; + fprintf(config->output, "%s%" PRIu64 "%s%.2f", + config->csv_sep, run, config->csv_sep, enabled_percent); +} +static void print_running_json(struct perf_stat_config *config, u64 run, u64 ena) +{ double enabled_percent = 100; if (run != ena) enabled_percent = 100 * run / ena; + fprintf(config->output, "\"event-runtime\" : %" PRIu64 ", \"pcnt-running\" : %.2f, ", + run, enabled_percent); +} + +static void print_running(struct perf_stat_config *config, + u64 run, u64 ena) +{ if (config->json_output) - fprintf(config->output, - "\"event-runtime\" : %" PRIu64 ", \"pcnt-running\" : %.2f, ", - run, enabled_percent); + print_running_json(config, run, ena); else if (config->csv_output) - fprintf(config->output, - "%s%" PRIu64 "%s%.2f", config->csv_sep, - run, config->csv_sep, enabled_percent); - else if (run != ena) - fprintf(config->output, " (%.2f%%)", 100.0 * run / ena); + print_running_csv(config, run, ena); + else + print_running_std(config, run, ena); } static void print_noise_pct(struct perf_stat_config *config, -- 2.38.1.493.g58b659f92b-goog