Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp607363ybg; Wed, 3 Jun 2020 08:59:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHac/aeIjz4ZURXhO6Xp7t5yqZF8UdiVSQBzoZH0Da4JSojpAF1LYH/pZb/2u+lDVGrygH X-Received: by 2002:a17:906:7746:: with SMTP id o6mr14121391ejn.75.1591199996631; Wed, 03 Jun 2020 08:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591199996; cv=none; d=google.com; s=arc-20160816; b=IO86/B6dNDY93npI4eCmvQ0KwzbBjIbrsyGprxjcH4btqsWlbSBE1qYA33o9Pi9tN8 VrhqOa1z43G5ge+K0hVIxPHznWbONDWHU8eW4QJvnuPFXyPokK0j8ZpYZxbSTBs1q3Q2 rbWSNQz98kpPjf6FrX7le5z9DOzwQqYfoto0Hn3QY/HuJxlsYVmAJbCQp9F6MUCY4KXM NlZu2iZkxzGaUW5dPZER6gZaSWmdYFuix6w72td0MJEqfrJCKwGA++MaELFKwOoI0Qlh 8SITfQvTU0XkQXLQW/yX2VIeCEo51Xp7U8x45k0n3+ugQta55oI1uDGGwIM/9KBoz6X/ +I2A== 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=L0YXoRoOzAMMNFRZj8K8stDwBnkR+ixeVfl0RHNIyNw=; b=OIoVy58ZT7akh2y19iggT9rXyLt7r2RDSfRIv/3aNte0WL5kF7zlLwMofc3i3ykMRc wyXeuQUjjZu2pWWYOv/ZS0wFA1o+IfHBiyfk9BNfXLbKKDs/E/nRJmfsQR8vGfiy/yQe s41Trbc1WJuBRwq5ncWK3lQ9uCNSWgdLxkHVLnyYIGl4QohsVjgOJbzPsuwYKuzS5Ivw ughVOVShcnXNJAT3lFAemKyf7HSgU9QGTtnMvYlO6YFka59NgjG3xKihZNwAelT8Lfm3 /FXcpjFJ04C7pE9x8CduputpCog4manaHi5mpY0bLVV3ldbqN+RDlDyG7gGEeu6fCJy0 tkDw== 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 u21si1350400edq.299.2020.06.03.08.59.32; Wed, 03 Jun 2020 08:59: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 S1726116AbgFCPzn (ORCPT + 99 others); Wed, 3 Jun 2020 11:55:43 -0400 Received: from mga14.intel.com ([192.55.52.115]:30616 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725867AbgFCPzm (ORCPT ); Wed, 3 Jun 2020 11:55:42 -0400 IronPort-SDR: FOYOpihQMBKEsunq4LBzKdbB/PcvD0bvQ2nmffPRPQ/w9Qt+M01BdAVmqlZahH1BtRN9EWCgTN eKiBwNcqpuiw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2020 08:55:41 -0700 IronPort-SDR: EW20/+Ln5zAEqhjezti/2mNZhM6nIP65JVUVPAib8nZKLqN32Aab1iE9u/arMXpqIMrcLmGUsY Eo7n5qFlw00A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,468,1583222400"; d="scan'208";a="269116000" Received: from linux.intel.com ([10.54.29.200]) by orsmga003.jf.intel.com with ESMTP; 03 Jun 2020 08:55:41 -0700 Received: from [10.249.225.188] (abudanko-mobl.ccr.corp.intel.com [10.249.225.188]) by linux.intel.com (Postfix) with ESMTP id CE8EA58045A; Wed, 3 Jun 2020 08:55:39 -0700 (PDT) Subject: [PATCH v7 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: <5de4b954-24f0-1e8d-5a0d-7b12783b8218@linux.intel.com> Organization: Intel Corp. Message-ID: <2619acc2-b49a-2850-3de5-bb76958996ee@linux.intel.com> Date: Wed, 3 Jun 2020 18:55:38 +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: <5de4b954-24f0-1e8d-5a0d-7b12783b8218@linux.intel.com> 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_interval() and process_timeout() 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 9be020e0098a..31f7ccf9537b 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -475,6 +475,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(int 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) @@ -611,6 +628,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; @@ -805,17 +823,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