Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5500987imm; Tue, 16 Oct 2018 11:11:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV61KPmyYW71NAKfs2Yk/lHIC49s/m6TXmEr8SBXbdKEFFYuulpfYl3YGWBpdPTMhQDxUz9yO X-Received: by 2002:a17:902:9b89:: with SMTP id y9-v6mr22535317plp.239.1539713469311; Tue, 16 Oct 2018 11:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539713469; cv=none; d=google.com; s=arc-20160816; b=RbYjS16TKO4rxbDv6XZJ/GP4OBLlKA7UyLRO9hv54ufjTmQQJxNMNoUKKB2WcU0Njs ndh6Xk+jLrvq9Pndgm6Fa/+euAGNY2fgJIlGd7AeVY+KargzNxc9aHWoKVzKOJzVoU9D cWpKeqNFd3B8QIiKA93wMO27NZmT1xLudYh9Z4EV+yKUEAIbM/4ragBueHmyGp6tP4lc TIMrHKNEmlj1TyZ6Ro7e46l7yJxrIKPgXka2uxAPLg4mty7MxckzAf1+aw/Q2WuqEL7r kS06lk83MDOj3shXg1rKwe4W0ZXGhyNXOUhFZa4NfGWKb+RUgnEyK1tBHyWllDTU5kM7 LlwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PMdqnSb9m/F9k8AXy5iOjzXITHV9FGY3Ks/LXRYr2CY=; b=vIQ69FUYDqxrze3Utgt60GTp3FQYzoINYp53kAYW44gNUNatCyg92G70B5MwNabNMo JshDaHLJ92VHeTmPnmsNoDxuo0NPnnoCcNbaY1PAejpLZeXYyXn6EE0eOabaaEHKuSCU 4JzKTDv/cBD3dF8XPrXrs4lrT31/mwHTkZJoGs1TY5MxuhrfwnzkSmf9+Idkx+Q0qKPs zOnsLB4PFNxOooweIPMXjwJhMiPbZCpPktilkSWgo85lrakpF9ASsNTPmUgWRB8U0Fj4 8uyl97wjCmif9jWlQPuUzlUzvockHF+PZ3iRM3qcXgHIYuDXVSZE6NxA0M8Y7Q7QQnmo oGig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oWYB9rr0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 74-v6si15368642pga.231.2018.10.16.11.10.53; Tue, 16 Oct 2018 11:11:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oWYB9rr0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727464AbeJQCCE (ORCPT + 99 others); Tue, 16 Oct 2018 22:02:04 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45222 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727006AbeJQCCD (ORCPT ); Tue, 16 Oct 2018 22:02:03 -0400 Received: by mail-wr1-f68.google.com with SMTP id q5-v6so26656904wrw.12 for ; Tue, 16 Oct 2018 11:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PMdqnSb9m/F9k8AXy5iOjzXITHV9FGY3Ks/LXRYr2CY=; b=oWYB9rr0hyAwH8gus/nUge6mDbC0SF/7c/xAbiz2GDSJKLOBrTKGhLRfMjNqAcX/7r I6pp4TREWFPp/1+xzXNWgqt0sKtcVI8u7ObITUTi2NY67SLaHI9FRZbhnQKGfJH/2XIN eQF5YEYErwHhXMbSsLHmyLNTk+rrWa8lSRFX5mItLpcNssQq8MdMlKeLK0xmrQn7PvSW hXsU2LX+vaVMyl4OfK2w2X7RrdjZKev8wGbLh5hciZ+WPNE0vPdARwxdgkHanW+ZQWeA Hrw0jkDvahxz+425QupJc6zRxeC8+EHJmKIAX0tg0gMats0tMztTYWPBVf2zvVSues+m tx3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PMdqnSb9m/F9k8AXy5iOjzXITHV9FGY3Ks/LXRYr2CY=; b=UTquhdLuq0dtUwfggH+en7knfjixKR+/e1RQDFqvU9CkDsd/bFLuWfoT+7YadWLtzC RZ9jz6Uqe6tTR7s7pBVIQI5xAj3BOJcxFDYQ6ovLGuHJn/WiM5LsQCTGbjIUV9FHUgW8 HYjXNexlNCi++5Alr8UFdelwK2s6wTsVxotplsiTSBXP4vHsL0kp0OzP2mRV8zfPvbsY elzX//oyDT6QmTsZ9xLA5WTMdVYLz92aFosFL6znFP9kI4HW3zw2HQO8X02U7tCY8vd0 3PZGSdq1Y9Yke5a5Pmpkv6lwGEmCJKomiaIHe8F6T401qVHYlA2VQ8yEPPxIboOjz3VJ naqQ== X-Gm-Message-State: ABuFfojE4bZVqCnBjLN5OLLIqx5yD2McWEMWubNF/7t9aGNkJVRYUITB Uwv93XlbHWccHG805RJhJD5hDbQurJanPQhVYRXntQ== X-Received: by 2002:a5d:438e:: with SMTP id i14-v6mr21179528wrq.156.1539713423528; Tue, 16 Oct 2018 11:10:23 -0700 (PDT) MIME-Version: 1.0 References: <20181016110341.GB18450@krava> <20181016162554.GD6631@krava> In-Reply-To: <20181016162554.GD6631@krava> From: Stephane Eranian Date: Tue, 16 Oct 2018 11:10:12 -0700 Message-ID: Subject: Re: [BUG] perf stat: hangs with -p and process completes To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , Jiri Olsa , LKML , Peter Zijlstra , Ingo Molnar , Namhyung Kim , Alexander Shishkin Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jiri, Thanks for looking into this. Yeah, I don't think you need a kernel patch to make this work. You can poll in the app. Let me try this out. On Tue, Oct 16, 2018 at 9:25 AM Jiri Olsa wrote: > > On Tue, Oct 16, 2018 at 01:03:41PM +0200, Jiri Olsa wrote: > > On Fri, Oct 12, 2018 at 02:26:09PM -0700, Stephane Eranian wrote: > > > Hi, > > > > > > I am running into a perf stat issue with the -p option which allows you > > > to attach to a running process. If that process happens to terminate > > > while under monitoring > > > perf hangs in there and never terminates. The proper behavior would be to stop. > > > I can see the issue in that the attached process is not a child, so > > > wait() would not work. > > > > > > To reproduce: > > > $ sleep 10 & > > > $ perf stat -p $! > > > > > > doing the same with perf record works, so there is a solution to this problem. > > > > yea, we don't poll for the event state change in perf stat, > > but we do that in perf record.. also because the perf poll > > code in kernel is originaly meant for tracking the ring > > buffer state > > > > maybe we could return EPOLLIN for alive events without ring > > buffer.. like below (totaly untested) and add polling for > > event state into perf stat > > > > cc-ing perf folks > > > > on the second thought attached patch works as well > without kernel change > > jirka > > > --- > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index b86aba1c8028..d1028d7755bb 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -409,6 +409,28 @@ static struct perf_evsel *perf_evsel__reset_weak_group(struct perf_evsel *evsel) > return leader; > } > > +static bool is_target_alive(struct target *_target, > + struct thread_map *threads) > +{ > + struct stat st; > + int i; > + > + if (!target__has_task(_target)) > + return true; > + > + for (i = 0; i < threads->nr; i++) { > + char path[PATH_MAX]; > + > + scnprintf(path, PATH_MAX, "%s/%d", procfs__mountpoint(), > + threads->map[i].pid); > + > + if (!stat(path, &st)) > + return true; > + } > + > + return false; > +} > + > static int __run_perf_stat(int argc, const char **argv, int run_idx) > { > int interval = stat_config.interval; > @@ -579,6 +601,8 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) > enable_counters(); > while (!done) { > nanosleep(&ts, NULL); > + if (!is_target_alive(&target, evsel_list->threads)) > + break; > if (timeout) > break; > if (interval) {