Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp582368ybg; Mon, 1 Jun 2020 08:57:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZJijIwvzehNQMzhF1HFSvSc2LqoSV4Q5YJGgrVXz7ijvIak/KMxt+FgrY0jqh8daQCcJY X-Received: by 2002:aa7:d388:: with SMTP id x8mr7082301edq.380.1591027076133; Mon, 01 Jun 2020 08:57:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591027076; cv=none; d=google.com; s=arc-20160816; b=0A/oQ9Z2M+7h4rcNvX0UvJGuErHbvzUFc6AXerGNBTHwJH45DV0Irs6byXMYL56Z/f DrfdG6iaYN5i6V3fcmO6wxA7Ke8+N4CTdzSADpzvArBbBQlZAJjZui5j4oM3hzkqd8A9 wn8y4JmTk0EGONUOXWX0iM+YcZ+eq19SMHGGh1AQTEA5oAqm2IOBVuM/KOLA+ujX1tLo IqGrLAPrPurAf5cBcHlJhdcpcIOWLdt3OqsQP1v3aXDlXTgdcAvR5S48V/v7dPFn+JDL HXH/qZi/g8uKo1V7EYfHNXn51qf7q4OEngEH1bUdyyJ04e9x14YEYlHcvKgNkXU54OYd o+PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:references:cc:to:from:subject:ironport-sdr :ironport-sdr; bh=+Yq0crg9hKtpWruCyjqRTICXyP8Xge3/GAweSr/mKuw=; b=YDbUyIPt5u6buNTeIuNsGdgs9tMWFztgtdjemycx5f4K6IqoKiHxi2TZKyQDl622cR mv4mdX/2r9FWqVpn84JjAjKppAKSN33zKJ5yGQg+1rQyqtWjIN34RLxgLGyfVFJkU8tg uc2zmBvdT+YHgKlwhxA7BgMBzRpN2e4cKNoKj3fZP0l2Gn71pXuN9G/kvu+AfM9LpP6B smuIIAE9cq4ikFWtZlYrBxWjHSN/4VC5cKD9UOs3qjfbZ3VScW+Zpgkxzchg7SxGhnOZ B9unlteJgx4CSurkrV3kMkUXJKFzlD0VFL7yX2yf4+G3M6QMv3fOo6noN5rNNr3/vlXY fSJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y22si1498854ejq.391.2020.06.01.08.57.33; Mon, 01 Jun 2020 08:57:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726555AbgFAPxt (ORCPT + 99 others); Mon, 1 Jun 2020 11:53:49 -0400 Received: from mga18.intel.com ([134.134.136.126]:50718 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726075AbgFAPxt (ORCPT ); Mon, 1 Jun 2020 11:53:49 -0400 IronPort-SDR: 3q05Z5mwo2tG0KLGps3uEBeko1N0i7EL/XFk8FYFe591M9e3nzYXQshZrnNahWmG/wzkEEt90X QHzG5XvXL0hA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2020 08:53:48 -0700 IronPort-SDR: GA/vsuzZvZkURpH37FFwxvZVb79wunqzjnG3Ac5I9KYjrWXQEysjUV5MSGQLnroqtI1tURZ07k 5SDVi+43jR8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,461,1583222400"; d="scan'208";a="415845234" Received: from linux.intel.com ([10.54.29.200]) by orsmga004.jf.intel.com with ESMTP; 01 Jun 2020 08:53:48 -0700 Received: from [10.249.230.65] (abudanko-mobl.ccr.corp.intel.com [10.249.230.65]) by linux.intel.com (Postfix) with ESMTP id 77B69580646; Mon, 1 Jun 2020 08:53:46 -0700 (PDT) Subject: [PATCH v5 04/13] perf stat: factor out body of event handling loop for system wide From: Alexey Budankov To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: Organization: Intel Corp. Message-ID: <81e85195-e65f-a7bc-55bd-426edb4da35b@linux.intel.com> Date: Mon, 1 Jun 2020 18:53:45 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce process_timeout() and process_interval() functions that factor out body of event handling loop for attach and system wide monitoring use cases. Signed-off-by: Alexey Budankov --- tools/perf/builtin-stat.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index b2b79aa161dd..834a3d791ee5 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -422,6 +422,23 @@ static void process_interval(void) print_counters(&rs, 0, NULL); } +static bool print_interval(unsigned int interval, int *times) +{ + if (interval) { + process_interval(); + if (interval_count && !(--(*times))) + return true; + } + return false; +} + +static bool process_timeout(bool timeout, unsigned int interval, int *times) +{ + if (timeout) + return true; + return print_interval(interval, times); +} + static void enable_counters(void) { if (stat_config.initial_delay) @@ -558,6 +575,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) struct affinity affinity; int i, cpu; bool second_pass = false; + bool stop = false; if (interval) { ts.tv_sec = interval / USEC_PER_MSEC; @@ -752,17 +770,11 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) psignal(WTERMSIG(status), argv[0]); } else { enable_counters(); - while (!done) { + while (!done && !stop) { nanosleep(&ts, NULL); if (!is_target_alive(&target, evsel_list->core.threads)) break; - if (timeout) - break; - if (interval) { - process_interval(); - if (interval_count && !(--times)) - break; - } + stop = process_timeout(timeout, interval, ×); } } -- 2.24.1