Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp377808imn; Fri, 29 Jul 2022 09:33:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uFim+YOoKG2Fa/Qo+r+s/l2u0JXp3Z8DEC1QOPbCOaJjm8DUXiESl9ScDyvxkyFtGhz2lh X-Received: by 2002:a17:907:2bc6:b0:72e:ceea:862b with SMTP id gv6-20020a1709072bc600b0072eceea862bmr3459931ejc.134.1659112409366; Fri, 29 Jul 2022 09:33:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659112409; cv=none; d=google.com; s=arc-20160816; b=IPy1YEqLYK401A1c+Fr4uBfMvEU9Kl077ucQgE/hyoT9/iz6Xa76PjA+ruV7X9vij/ tLy8+ElAcRQvD3WBlQHAq5BJqr+In1ZdvGprUFt2AftGTNcsZI5HXmSCTap5Q0nDSj+H iM/apOY6IOhir63wZP/K/SE6290EJhBax707hiAAaYcBh6F1eFkmBRopz74oX/kvXeTs ZFT70jIBT/ahEQLvCP5cuXZsMQe621IcYaO3iwb3FPQO9YAh/vSJMtpMO831G56lgsz7 uvHqsLp0NDoF9XLoyax2HxBQwSTlZkvLQEWn8yJrG1EOTC0+63OosLCO6SuA9e5eKqXb in5A== 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 :message-id:date:subject:cc:to:from; bh=NB7TW6DQg7fN0zgDc9e+2qp17w6h6046zSwQY7x4t5E=; b=v8drOJILL1Qb6hMMXsH+fyQIy9i5UltAABV9TTlnKExGpAASqk5+tVXjGXsaae/URK +y/Qrtj4lCitEXEkzq+SzaGr5J/nepL81yGtdw5WRZZEMCwuDKzQ8T6StrKfNWYcd+Nf gli6NM/HYcqHmQC+s+lLar5qDe1ibRiEuzj/JwwL5FgjCl29U+Kbd2Af0mtbEMlactOi xMnCM/QzT+FQRb5d1M1BkbZ5FQq6egy4GamYhRkPI45IikLTKdzuWal1I3DjXo1b9vHp 0ClGIc0PMFsdQsE0UOZpClHFS85u5avn7xjl7qIovscDJbg6eT12EqTE8XDLsMy6LBV3 i6QQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w1-20020a056402268100b0043bf03b720fsi502552edd.27.2022.07.29.09.33.03; Fri, 29 Jul 2022 09:33:29 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236038AbiG2QNU (ORCPT + 99 others); Fri, 29 Jul 2022 12:13:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236129AbiG2QNT (ORCPT ); Fri, 29 Jul 2022 12:13:19 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D5EEC8052F; Fri, 29 Jul 2022 09:13:16 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3F1571063; Fri, 29 Jul 2022 09:13:17 -0700 (PDT) Received: from localhost.localdomain (H2XD2X12VG.cambridge.arm.com [10.1.36.148]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CF6F13F73B; Fri, 29 Jul 2022 09:13:14 -0700 (PDT) From: =?UTF-8?q?Adri=C3=A1n=20Herrera=20Arcila?= To: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, leo.yan@linaro.org, songliubraving@fb.com, james.clark@arm.com, =?UTF-8?q?Adri=C3=A1n=20Herrera=20Arcila?= Subject: [PATCH 1/2] perf stat: refactor __run_perf_stat common code Date: Fri, 29 Jul 2022 16:12:43 +0000 Message-Id: <20220729161244.10522-1-adrian.herrera@arm.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE autolearn=ham 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 This extracts common code from the branches of the forks if-then-else. enable_counters(), which was at the beginning of both branches of the conditional, is now unconditional; evlist__start_workload is extracted to a different if, which enables making the common clocking code unconditional. Signed-off-by: Adrián Herrera Arcila --- tools/perf/builtin-stat.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d2ecd4d29624..318ffd119dad 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -966,18 +966,18 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) return err; } - /* - * Enable counters and exec the command: - */ - if (forks) { - err = enable_counters(); - if (err) - return -1; + err = enable_counters(); + if (err) + return -1; + + /* Exec the command, if any */ + if (forks) evlist__start_workload(evsel_list); - t0 = rdclock(); - clock_gettime(CLOCK_MONOTONIC, &ref_time); + t0 = rdclock(); + clock_gettime(CLOCK_MONOTONIC, &ref_time); + if (forks) { if (interval || timeout || evlist__ctlfd_initialized(evsel_list)) status = dispatch_events(forks, timeout, interval, ×); if (child_pid != -1) { @@ -995,13 +995,6 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) if (WIFSIGNALED(status)) psignal(WTERMSIG(status), argv[0]); } else { - err = enable_counters(); - if (err) - return -1; - - t0 = rdclock(); - clock_gettime(CLOCK_MONOTONIC, &ref_time); - status = dispatch_events(forks, timeout, interval, ×); } -- 2.36.1