Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp321856ybt; Wed, 17 Jun 2020 01:39:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvdopoQjHS73Wh+koxAZWTd9CvZaSMu5iYJpty643uHgnTTibKeYfk8R5Mg0Y37Th6G7A+ X-Received: by 2002:a17:906:784c:: with SMTP id p12mr6403270ejm.123.1592383188270; Wed, 17 Jun 2020 01:39:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592383188; cv=none; d=google.com; s=arc-20160816; b=BIpK7PD4jEf7q1vDp5r/VeMeJEy5yrUIeuEVBpR2OjSlGOdSSgzDs5yXHmvqjO7e07 Am+/jspdRGQrb5kwq0RK3E1UwCkEU0KTYAwyBr0Li+7MAaWQPsX2vPhktfjcWU/2V1wL BCIDFoZePFDFYs/5uUWZvUwe0K2TI27H2Rxa6gacaOZhDDdZ5gqA1zEzCZB7oueSQ0ma Ftj8hRB9hhj7OaQaWpNHKlOhgGmJPBFiAivT0eSYJkLBsfyJvQWfXWQKgdKuKpiOoJif XwU6rv07c0kLpj0zVVptH8Lf7kjIbgBRGLdP1C8rjfPJBMQJxbY6B19tA6M6bpmrjI97 BQJg== 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=tu46xYvh9l3rYVNl+a2ILkf4lctvrGcr3fup3UAHw+8=; b=East7Cqxdnel98fHkB9jPIpWTjbMmeFEMxkUsbYVmErxeIPS19in48W787MJF0PzMH V77+mngPg93ChAgzAJG29rbaGkmJVxg0Kcpbis4DfIiJLRe3PDSNQWewQtUA5Xm0+TO8 5/1WE/6zj8Zwi6q01WLNnyiCxHjKPZHUptIfs4YisFI/BTMivaRVZnLUlq1gR1MACz1s 5hjA4OZfTql/gBaJ51N+A6W5SisuwKt2OMZk4qz2NkE54q4VYarErA4YtwdI8rvd+wd2 KCNs8i5+hCxDxn7f6KZTGJZVO33c2ztUJUAkHqIf+WvFzyvrrys1/tnvPzhtwUom1MMY QM8A== 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 vr3si12193568ejb.520.2020.06.17.01.39.26; Wed, 17 Jun 2020 01:39:48 -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 S1726652AbgFQIhr (ORCPT + 99 others); Wed, 17 Jun 2020 04:37:47 -0400 Received: from mga17.intel.com ([192.55.52.151]:60716 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725979AbgFQIhr (ORCPT ); Wed, 17 Jun 2020 04:37:47 -0400 IronPort-SDR: xvqsJemtidT4ijCv0Ym3OasdSyqBYzqTMrtp5awa6KIkRWIoHD0FpR92AxzkEWrTbOPGsqKUBt t4/SDlQoj/VA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2020 01:37:46 -0700 IronPort-SDR: JoPdcwtzheymRhccxuLexPkEUr45lYVnNcluC6Q1QHA96zIQ8Y2YOEuLTCp0FEo+aGnW38ui8L sMBVdDfKWpQg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,522,1583222400"; d="scan'208";a="450162490" Received: from linux.intel.com ([10.54.29.200]) by orsmga005.jf.intel.com with ESMTP; 17 Jun 2020 01:37:46 -0700 Received: from [10.249.225.191] (abudanko-mobl.ccr.corp.intel.com [10.249.225.191]) by linux.intel.com (Postfix) with ESMTP id 9A99458026B; Wed, 17 Jun 2020 01:37:44 -0700 (PDT) Subject: [PATCH v8 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: <0781a077-aa82-5b4a-273e-c17372a72b93@linux.intel.com> Organization: Intel Corp. Message-ID: Date: Wed, 17 Jun 2020 11:37:43 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <0781a077-aa82-5b4a-273e-c17372a72b93@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_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 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