From patchwork Mon Nov 14 23:02:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2408402wru; Mon, 14 Nov 2022 15:04:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf4hjlkqjjf7LLlAItoCbiFsFKDVJ3S/0n/xmwJYR4lBEi6g61jRs4PNX9PB3/suNx1Mk0Q2 X-Received: by 2002:a17:907:a681:b0:78d:3505:6f3e with SMTP id vv1-20020a170907a68100b0078d35056f3emr11397017ejc.611.1668467086564; Mon, 14 Nov 2022 15:04:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467086; cv=none; d=google.com; s=arc-20160816; b=hUB9GuQ3jTq8Um501zbbgTP/QmxZeDpOfaIGkp2As/QHNxpeA3TkJQGp44Tl2UTp4k K5BqBdo7Min8nmXCHnfk5lE9NosfyUa8lOgogBA2CjxA2rr5kHTEj9p+7oofB1rvx7vO hWaPh6+W9NBXY3yvQy+jHxq4ZAbThD9q96aERy8lA3yVfGeFEAWMf7hpJwBj93INZ0yx UbgT/D3sO/SISd56tx6Z15e4iFGLQIuMT47UlyixGrlMVYAZtoWqmNFC1i7N0hmBIodA AfHb5PicV9w9te4BpM7xTl2eFC3hoSxMZ13+kALaJl9HzCRVhfd89SQHVfYDfqrwFDOt IG0A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xa6-20020a170906fd8600b00730936657d1si4658217ejb.552.2022.11.14.15.04.22; Mon, 14 Nov 2022 15:04:46 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514543682222424?= X-GMAIL-MSGID: =?utf-8?q?1749514543682222424?= 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,