Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp56544lqo; Wed, 15 May 2024 21:20:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVx/4xDuqBvGfziBuobWOtDNVNw+N85fMdpU1dDCypNE50xqWn68gxZBlyoIS0NQgfSbILRJ73kJPoZwe3ffcQsnWtfvv0l8N+IZ6SoMA== X-Google-Smtp-Source: AGHT+IFs0KVg59838pCo4pOKPtM8Vh7xv162fjfnFmGu3cKqQUTWOt+EARQ20hvESQaheTAkFNXO X-Received: by 2002:a50:9f44:0:b0:572:72ff:da35 with SMTP id 4fb4d7f45d1cf-5734d5cc9b8mr10880022a12.12.1715833246577; Wed, 15 May 2024 21:20:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715833246; cv=pass; d=google.com; s=arc-20160816; b=sVthZrkvqIXjFbTx4PWuOQAG72tYZo3jOQidVIlv0YjReNsoNIROMsp/8xUOOD5M3M wqlyS/KgeSFQaWB6Kkuy99W+K8rmteK/r7AG4uRPzPFtJVG29zNiHrWcMMi6m+HnUt1M cRO9SDxEZvmbgNJaebm/wG8H1l1cU5vlR1YiszIAbzAyL1Bp04gNMKUsLBQ43YzMZerY aFC33eSEvgvgTI9Bxis7w0yz9iGYBm+2ifHr1q7TE2mxPj5kzs6orUTtPxM7RpNL7y0F 8+NG4OfMN7C37mi+bnkZfdOoGx9/USgO/HzSF6nkpjuYP72a4Ctxcgtq5vzJL+ZTFO8Q hOww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=e6nxXyVAqYg+7CILkdLqmh6c58xAPU1gAIUJoi7JwDM=; fh=s4BR1sTrGTBmL8D4sBU2m9/SgJ06dVFDW/vazFRorio=; b=wNZdy2JmGDShtADY+hMQrrmI5BGyV0nFf9Oc541aw5tYZg5aVp/wrH27+KRQfD2kCM zo6Uq3MMg+i/zCXWg3XQGWJ0oSrpv+iEzQK63429+/IaYb8Hdt5frxHgY2Jn6uEGqpxl qefpF/S+2433lZRpnb/J8du1quLxv9kBxOeJzROC0IenE03PRqI5cC2ZRyYtO3qjxuso anTebjkam4iqH9j86zAg5g2e1eBKz/KY1hZmi8sLuNbFksHUzs5oDzl6uqXHq9LTAMUN g3lkwZdYLPefJFTfhuI0+NFtXjPzwvF1uQJg8JeXhoKXS3uoVTo20nzSFQvkDeTzPeJO +KAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="sXA/O0ag"; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-180620-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180620-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733beace87si8572544a12.8.2024.05.15.21.20.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 21:20:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180620-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="sXA/O0ag"; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-180620-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180620-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4D46C1F24041 for ; Thu, 16 May 2024 04:20:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA57D43AB2; Thu, 16 May 2024 04:20:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sXA/O0ag" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A9A13D0BD for ; Thu, 16 May 2024 04:20:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715833210; cv=none; b=KksX1T+qDiBBwLEKCtHmpfRHvfywG+UEi+AX/P+oc38LIYjf1pLpkIdxq4ze/+k+0g0R/4a7J1fAHdHVM/ebpxBaNDVE8NXcWOKtf23O8yTRMh5ZKA0RC/e8g8qosZLc2jb4EskQdgkgveCCV0xSP1B17zH+EfqgRGiFmK2iGp8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715833210; c=relaxed/simple; bh=tm50rM0/vPAY35AZcNIkh9G+ITQ1yOK+pmrR/wf9O70=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=M9NR1Pccr/6x2ZlPvrWSeZ6r4a9/ArdPjQqbI6CVzssEfRQgDacjFAWNKWb5AsAOzFhVBUpODtXSE7YCT5Xg9B0og6MVIRZiShrHLM6+dBZYmxiUt8kK+TogpvxqiZpjFfkZrlicrfRiReb7yM3wkMOE8uS6s+Vi11FONX0Hi3E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=sXA/O0ag; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de54ccab44aso14315010276.3 for ; Wed, 15 May 2024 21:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715833208; x=1716438008; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=e6nxXyVAqYg+7CILkdLqmh6c58xAPU1gAIUJoi7JwDM=; b=sXA/O0agGCg+1UF0X3HIuqhuczwjWjicjB94RD1GtFoRXMM/6rIR8/A3Lg08ST7POc n7r6ui04LJHJp2DNfCNJ3U3cCMU2Po2XQz1dXlU6rHY0fH/8IrkOtqTAxTh8R+fx5jEK 7YZ1+eEufd9ogb8Q/hpn9cEqn5XUftkAu9B271zIw5vIFc9qlG+mhjj3/bc7VTasKhhH MELJ6QpT5ioYkF9P/6kpV6k9frLexBxw3qvRu8oZHZkUEjBnDOh3yHfEg3lnoB2KwEEN AB1cpWaNHwt+fURgPwJ3ufrD1PV2hWqklx8hkGE85s0bZlBg0x6y9gSLkQGo7VE/QnGF Uocg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715833208; x=1716438008; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=e6nxXyVAqYg+7CILkdLqmh6c58xAPU1gAIUJoi7JwDM=; b=AZFdViFT0Cj6hat2CGePis3uxzDJ0234/5Ctj/um7x0LGtS/F90DDZhle3j8tiZkks gv8vUg8BxAMJskQUboPFxJMAGBIozoDO3HF+JWHqTmdjtaA2YXFdC33zEj0KnGJmDNom 0LNPVJSU725tfq04o0C8CsaZLasbX41CVLZ95efJF+2F9Lxg2xffjr4cCAT9z6XelyXn 9EipzGWSWFX9zVTDjjA54wuL/0gsGylB0nqdy9Uu12+BPzmjIUlAlIrUs2LTqu3k6nnK 0LXABCk2VFVRfDximHU5VkkGYpPPdvTWBQqLcPM+2e5hadQxuaRq+Ie/vItkzOAH+w8j CA2g== X-Forwarded-Encrypted: i=1; AJvYcCVPhQJHTDCKOwEQhGnWFtKysitA92P2nKspXaDGX9dAJYze3yfumqwtBYB3IuPvIfxUjhx5Hi2JfEsI7U2Q11fhDj8+5NRohO9hgHK5 X-Gm-Message-State: AOJu0YxFDwiixkoSp/akDKTnS5bSXu0AR8M835dhXPhsURBV1ipeq+Ne kTU0E3ZY5tS1mVOgoGed7JiaEP4SaEohaejhDN9exe0ZAaKH18lB5LtcNjj6I9SVjyYfVrx3uDk 2vkyXhw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bac3:cca1:c362:572]) (user=irogers job=sendgmr) by 2002:a25:7486:0:b0:de5:2325:72a1 with SMTP id 3f1490d57ef6-dee4f192850mr4368968276.4.1715833208535; Wed, 15 May 2024 21:20:08 -0700 (PDT) Date: Wed, 15 May 2024 21:19:48 -0700 In-Reply-To: <20240516041948.3546553-1-irogers@google.com> Message-Id: <20240516041948.3546553-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240516041948.3546553-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v1 3/3] perf top: Allow filters on events From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Changbin Du , John Fastabend , Andrii Nakryiko , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Allow filters to be added to perf top events. One use is to workaround issues with: ``` $ perf top --uid="$(id -u)" ``` which tries to scan /proc find processes belonging to the uid and can fail in such a pid terminates between the scan and the perf_event_open reporting: ``` Error: The sys_perf_event_open() syscall returned with 3 (No such process) for event (cycles:P). /bin/dmesg | grep -i perf may provide additional information. ``` A similar filter: ``` $ perf top -e cycles:P --filter "uid == $(id -u)" ``` doesn't fail this way. Signed-off-by: Ian Rogers --- tools/perf/Documentation/perf-top.txt | 4 ++++ tools/perf/builtin-top.c | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt index a754875fa5bb..667e5102075e 100644 --- a/tools/perf/Documentation/perf-top.txt +++ b/tools/perf/Documentation/perf-top.txt @@ -43,6 +43,10 @@ Default is to monitor all CPUS. encoding with the layout of the event control registers as described by entries in /sys/bus/event_source/devices/cpu/format/*. +--filter=:: + Event filter. This option should follow an event selector (-e). For + syntax see linkperf:perf-record[1]. + -E :: --entries=:: Display this many functions. diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 1d6aef51c122..e8cbbf10d361 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1055,6 +1055,13 @@ static int perf_top__start_counters(struct perf_top *top) } } + if (evlist__apply_filters(evlist, &counter)) { + pr_err("failed to set filter \"%s\" on event %s with %d (%s)\n", + counter->filter ?: "BPF", evsel__name(counter), errno, + str_error_r(errno, msg, sizeof(msg))); + goto out_err; + } + if (evlist__mmap(evlist, opts->mmap_pages) < 0) { ui__error("Failed to mmap with %d (%s)\n", errno, str_error_r(errno, msg, sizeof(msg))); @@ -1462,6 +1469,8 @@ int cmd_top(int argc, const char **argv) OPT_CALLBACK('e', "event", &parse_events_option_args, "event", "event selector. use 'perf list' to list available events", parse_events_option), + OPT_CALLBACK(0, "filter", &top.evlist, "filter", + "event filter", parse_filter), OPT_U64('c', "count", &opts->user_interval, "event period to sample"), OPT_STRING('p', "pid", &target->pid, "pid", "profile events on existing process id"), -- 2.45.0.rc1.225.g2a3ae87e7f-goog