Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp588614ybg; Mon, 1 Jun 2020 09:05:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4WJoNSPj2c/hjHtj0Wykg/6u5yKNmJBvd/jaZmglsNU/w5Z8kp+EPV61XBHqROYxLdZg9 X-Received: by 2002:a05:6402:22a5:: with SMTP id cx5mr23466918edb.246.1591027556469; Mon, 01 Jun 2020 09:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591027556; cv=none; d=google.com; s=arc-20160816; b=vButlwpc/q+KyuY4qdJzAIbWOeHcmdN1favklrFhBjEK4XwcXWwQyHh5V5MKIeOc85 WNvXwc+UERrD5UBOkMJR2gmdQGP4RyedZbgps42O90MkStjHTxPNyzF585pFwi81ENRi PBxxMifcS2pfcvEz+G9YAWr7k59jR7ZVzbow2ywH0ago1WSKAMV+j9PBLO6k0guq8za/ 2wz/nGRMCw4+O5edTMlycSn6hp4wupS4fRfQ7y5spu4tvpP79hp4ldNYLmKyjtqCETfk 36KLCD5BnCplbw54xQe3iFaiMWIrPb8EIpiuNUrJaYNzUCdpE9pI2j10lJ1I14JliIoR ZkCA== 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=GN7Y1RqWJ+v/sAzqqNuX1zSKONJdxtwRQa1WPNNHdHs=; b=Sqqh0oGrxp2vBpSHv2Bn3ZibQZt7MiwtuQLYtKMNSuloesvE0u8xHdl10i9O1dEy3h F9sBZmmziNascnHpijqm2UKYUjiHsXn1plO9GYOgawt7/VoNi91M/EtZVP9slFJ7CTYb Jw/o2szZWtA2hbnEsUnOYVTQ6Eqgkr+zc2NM/CK/nUaVCQbsG6ua3JACzanVYqb4JXSX jUu/OCxYYGWSzaPNbEFM/JiH38VWzimuQsnRBLgCRmqXT29ZbpBzXDD1ObGm6bohIY+J lIOs3XjYDPMgSMwPZ/oI6GenU6BMIoDRMc+8pwZUugpSA+HU3Gz1L3lfHonZYmz5WHp+ npSQ== 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 m11si8369285edp.600.2020.06.01.09.05.28; Mon, 01 Jun 2020 09:05: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 S1726555AbgFAQDQ (ORCPT + 99 others); Mon, 1 Jun 2020 12:03:16 -0400 Received: from mga04.intel.com ([192.55.52.120]:45098 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726067AbgFAQDQ (ORCPT ); Mon, 1 Jun 2020 12:03:16 -0400 IronPort-SDR: eMLVIaAEA/NprLtO9eufgQm2/aR9ytI6ITaOpiYL96y5lfVRfu3OI24HAaKSjNDdG3JPBPNiPg K+VNE2gv0/OA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2020 09:03:11 -0700 IronPort-SDR: f+SZSahtHpea0Zsfx5dTpukYdev0Cqs4+2unU9N+vU1k4gFW+oqrF3OFIHVap86rpYaFYmRWea h/cCPlBGfVjA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,461,1583222400"; d="scan'208";a="303932214" Received: from linux.intel.com ([10.54.29.200]) by orsmga008.jf.intel.com with ESMTP; 01 Jun 2020 09:03:10 -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 B0EFA580646; Mon, 1 Jun 2020 09:03:08 -0700 (PDT) Subject: [PATCH v5 10/13] perf stat: introduce --ctl-fd[-ack] options 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: <030e1d2f-02a6-b924-afb4-24aad9b87625@linux.intel.com> Date: Mon, 1 Jun 2020 19:03:07 +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 --ctl-fd[-ack] options to pass open file descriptors numbers from command line. Extend perf-stat.txt file with --ctl-fd[-ack] options description. Document possible usage model introduced by --ctl-fd[-ack] options by providing example bash shell script. Signed-off-by: Alexey Budankov --- tools/perf/Documentation/perf-stat.txt | 40 ++++++++++++++++++++++++++ tools/perf/builtin-stat.c | 7 +++++ tools/perf/util/stat.h | 2 ++ 3 files changed, 49 insertions(+) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 9f32f6cd558d..c4a5d31062ef 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -176,6 +176,46 @@ with it. --append may be used here. Examples: 3>results perf stat --log-fd 3 -- $cmd 3>>results perf stat --log-fd 3 --append -- $cmd +--ctl-fd:: +--ctl-fd-ack:: + +Listen on ctl-fd descriptor for command to control measurement ('enable': enable events, +'disable': disable events). Optionally send control command completion ('ack') to fd-ack +descriptor to synchronize with the controlling process. Example of bash shell script +to enable and disable events during measurements: + +#!/bin/bash + +ctl_dir=/tmp/ + +ctl_fifo=${ctl_dir}perf_ctl.fifo +test -p ${ctl_fifo} && unlink ${ctl_fifo} +mkfifo ${ctl_fifo} +exec {ctl_fd}<>${ctl_fifo} + +ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo +test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo} +mkfifo ${ctl_ack_fifo} +exec {ctl_fd_ack}<>${ctl_ack_fifo} + +perf stat -D -1 -e cpu-cycles -a -I 1000 \ + --ctl-fd ${ctl_fd} --ctl-fd-ack ${ctl_fd_ack} \ + -- sleep 30 & +perf_pid=$! + +sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})" +sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})" + +exec {ctl_fd_ack}>&- +unlink ${ctl_ack_fifo} + +exec {ctl_fd}>&- +unlink ${ctl_fifo} + +wait -n ${perf_pid} +exit $? + + --pre:: --post:: Pre and post measurement hooks, e.g.: diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 7fb08454b343..f31126df5df7 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -188,6 +188,8 @@ static struct perf_stat_config stat_config = { .metric_only_len = METRIC_ONLY_LEN, .walltime_nsecs_stats = &walltime_nsecs_stats, .big_num = true, + .ctl_fd = -1, + .ctl_fd_ack = -1 }; static inline void diff_timespec(struct timespec *r, struct timespec *a, @@ -2249,6 +2251,9 @@ int cmd_stat(int argc, const char **argv) signal(SIGALRM, skip_signal); signal(SIGABRT, skip_signal); + if (evlist__initialize_ctlfd(evsel_list, stat_config.ctl_fd, stat_config.ctl_fd_ack)) + goto out; + status = 0; for (run_idx = 0; forever || run_idx < stat_config.run_count; run_idx++) { if (stat_config.run_count != 1 && verbose > 0) @@ -2268,6 +2273,8 @@ int cmd_stat(int argc, const char **argv) if (!forever && status != -1 && (!interval || stat_config.summary)) print_counters(NULL, argc, argv); + evlist__finalize_ctlfd(evsel_list); + if (STAT_RECORD) { /* * We synthesize the kernel mmap record just so that older tools diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 626421ef35c2..06f0baabe775 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -133,6 +133,8 @@ struct perf_stat_config { struct perf_cpu_map *cpus_aggr_map; u64 *walltime_run; struct rblist metric_events; + int ctl_fd; + int ctl_fd_ack; }; void perf_stat__set_big_num(int set); -- 2.24.1