Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2112143ybt; Fri, 3 Jul 2020 00:48:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzi9c02sXAFQSNhYXmUAdKJi+dTWXiLj6Jimb2RRs+GLJBsnauMzUWb/VVAXpiNFqSQajIT X-Received: by 2002:a05:6402:354:: with SMTP id r20mr39445039edw.32.1593762512116; Fri, 03 Jul 2020 00:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593762512; cv=none; d=google.com; s=arc-20160816; b=aMd7ib07+5pLXqzyNaynueCdpiutgd/zENz89lcfZP3BjNk7Xy7zwFAozNrDI8zxXf +qj1tU3On6Iq5GuhrwSk1kQgIAO5S8Wv4I+kAL5GnJzfThSV/eyyYEq9X66KaUm1iFW/ CrHqQL2EEQfkT2x71PDZQl3ELU4dgNiNZpF9PS7p0NLj/XT/emTZbWkjzLVh4iSy6B7l Uz74s9+hC9W4VQBJeZNWbvvgFsK8HI+5o575heeonzCgX3iggYnbkCc5Kg1wLlsBqe+B vhgaa6ogBhy2V5RvxZPuMg8qzbAcu4ju0y5MGEgL9gKM1zPpzMaM9nismlkNYnh8K3Da FpOg== 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=o+NRzMpBYOrVk1tH/G08uDTdU2YtoaJlVjBadX9W4ts=; b=074cC+GtRzq3LY/xIZBmIA58bp8Go68BVrJzHaa/XKK9OD65jUuv0qs2AVGKb3SPkP aGVeW8/QfUbcedJa7Rjm76dvFrH6xPupT/0FweD1KvoGNh0yXz9Ur1zuzIlhOMGKpRRc 93iJdjraGnuLp5cWrgDldoz6qA2rKHfYk7FZfUntsrtsZkfyz2RYkwvlZtimuG6vp+/B qC9WJyjSyaQ7iNmo51yE4cUaTEYxx/9FDVbmXmUqjFMhIItvYYVVh+33GLDBdTan3Qu5 JTFYQengisfRRF2jUkJsJUFQyNqjxD1M7wAVtna+qZnUMjcgfvqRVYtoF9l5GLRbFeDS BsIw== 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 cb18si7278200ejb.534.2020.07.03.00.48.09; Fri, 03 Jul 2020 00:48:32 -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 S1726638AbgGCHok (ORCPT + 99 others); Fri, 3 Jul 2020 03:44:40 -0400 Received: from mga12.intel.com ([192.55.52.136]:31137 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726082AbgGCHok (ORCPT ); Fri, 3 Jul 2020 03:44:40 -0400 IronPort-SDR: HQEXlKY1h2Fnemgsykq2iDWUFeVV4M45L4JNW6+i2DSQQPD1By9quwThGYWrboQQ78mWUgSMw8 XMZVVQM9o8dg== X-IronPort-AV: E=McAfee;i="6000,8403,9670"; a="126723726" X-IronPort-AV: E=Sophos;i="5.75,307,1589266800"; d="scan'208";a="126723726" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jul 2020 00:44:39 -0700 IronPort-SDR: gXU0nCLFEgxjOMI/X5UovLo8FqS4mohcrkXT2k/z/bsqbwEMHxgzpva8NjjMr8q6ilqz7qfqYo msBBmJccm7Iw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,307,1589266800"; d="scan'208";a="455813132" Received: from linux.intel.com ([10.54.29.200]) by orsmga005.jf.intel.com with ESMTP; 03 Jul 2020 00:44:37 -0700 Received: from [10.249.231.67] (abudanko-mobl.ccr.corp.intel.com [10.249.231.67]) by linux.intel.com (Postfix) with ESMTP id A629C580781; Fri, 3 Jul 2020 00:44:35 -0700 (PDT) Subject: [PATCH v9 06/15] perf stat: factor out body of event handling loop for system wide From: Alexey Budankov To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: Organization: Intel Corp. Message-ID: <84dc0a4f-3b47-5969-c78f-426d3b0438df@linux.intel.com> Date: Fri, 3 Jul 2020 10:44:34 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 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 handle_interval() function that factors out body of event handling loop for attach and system wide monitoring use cases. Signed-off-by: Alexey Budankov --- tools/perf/builtin-stat.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 922d9961ba98..c74e8f94375c 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -475,6 +475,16 @@ static void process_interval(void) print_counters(&rs, 0, NULL); } +static bool handle_interval(unsigned int interval, int *times) +{ + if (interval) { + process_interval(); + if (interval_count && !(--(*times))) + return true; + } + return false; +} + static void enable_counters(void) { if (stat_config.initial_delay) @@ -611,6 +621,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 +816,13 @@ 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 = handle_interval(interval, ×); } } -- 2.24.1