Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp740830ybg; Mon, 1 Jun 2020 13:10:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNRXaM7QJwRtSyvutOgo04wjyRo8bcsnEgnz4r8m7b15jzN9RqcW/lW2VqG4+mrNPRV2uN X-Received: by 2002:a17:906:1f8b:: with SMTP id t11mr20928869ejr.201.1591042230303; Mon, 01 Jun 2020 13:10:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591042230; cv=none; d=google.com; s=arc-20160816; b=T0Q0dvz6Tx9df5wqDmzOJOqlVyNo1PyKeWuLT+JLJ4eGk7gBwHegnm+Pyxi7T8vICf iTM3MopMGAzOlewpGFbyY1lJUJXTTmpMgZ0sa4TWWGDRXsA3BQnI8SvuzIw+6Kh3TiWf Cg4yZU/r1ERp+WRzqO3/R0ljAgxyj4eMrY1XeiUdHtXfeOb+j0mlq9hLvBELttHDPiiq k2cMbl+yCYonf2AlkWl4oudvbbYoaI4gf84y5mMHOqEHxLWWykXVmGY3ow0NFpJaPI9K vWhMgGQXoWtF94DTTIorvP7pGoY6FS7LmKXTVRYuOhHUjCydoDYUzKUTQuxKD97j9Oih EClQ== 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=t0twGYBAnvAlNSwuRFpEvZMZMx0pQGbTqR7SzjO8rIQ=; b=gpCOGH43COADghQej4VgBni8/nri/qTnNYsF11osh2i3c5OD7OR5Nzz/U/i9VIxTvB ktMX4SbbShhrzKPE+8s42gS4thGOcEdS/pWthMlk0E4IpU2e2ocWGg+9UIoRUChAVt+o GHMuoyqE4rBG4qT0sjUIIF6P5VZH1GmNy4oWKe8k7smXgDxuyuZgW7oDQ6UlGDIwLD5Y VcyMedJ1lR3z5M4CQyePPyG7aC2Zseo6YZtyr0RBZz0KDKCsbQBfWnzb72l1VtPxh/uX jxmm9ye1ZaQXbYLW3Z8StsZYoaIOJyEpEBWTGPuHlgP5qfpQTIIofisqpGxEiVmosiKc Bvhw== 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 dv16si286375ejb.557.2020.06.01.13.10.07; Mon, 01 Jun 2020 13:10:30 -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 S1728294AbgFAUII (ORCPT + 99 others); Mon, 1 Jun 2020 16:08:08 -0400 Received: from mga18.intel.com ([134.134.136.126]:58214 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726201AbgFAUII (ORCPT ); Mon, 1 Jun 2020 16:08:08 -0400 IronPort-SDR: HJ7UwdaG+FNpHYFjFf4pl5JnJ9RtqY6FYYQzDUrh9yy1oYASMuVMeXZ98FwzVzUEIkIYpSezq8 DygslOi9V8NA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2020 13:08:07 -0700 IronPort-SDR: efbdzejADLTmhF//dV8jm1kG+dZdqIX/7Tq02nGus7KNtaGvfWHSNgR6cK88s3lW2cD/GTTxAH 317n8Miw3NWQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,462,1583222400"; d="scan'208";a="303750467" Received: from linux.intel.com ([10.54.29.200]) by fmsmga002.fm.intel.com with ESMTP; 01 Jun 2020 13:08:07 -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 D11D858010E; Mon, 1 Jun 2020 13:08:04 -0700 (PDT) Subject: [PATCH v6 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: <19c16087-3d8e-2d50-bdc0-19bfc52d8ab0@linux.intel.com> Date: Mon, 1 Jun 2020 23:08:03 +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..6dd28c714f4a 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(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) @@ -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