Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2132589rdb; Tue, 20 Feb 2024 19:42:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWo09sccRoU1q/nYXXH/FA+OwD/KKP22iW/ZEKrRPoCkDFWWyNTb67PsecbzwFWUPRx7I6IJZj856y/FYuif/dadkNYOBRDBnmie9cs0Q== X-Google-Smtp-Source: AGHT+IF5bLqSDj172PB8GXY458rp7G/LOUJWyUDABf5yt2OV8VJJZmKK1OvNXnqoUxhNyku3b6sj X-Received: by 2002:a05:6402:1513:b0:561:33dd:621c with SMTP id f19-20020a056402151300b0056133dd621cmr14885667edw.7.1708486974027; Tue, 20 Feb 2024 19:42:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708486974; cv=pass; d=google.com; s=arc-20160816; b=0+Hpi063qOzYW72r+MQ0zw78mA1V+L3WtqbCWj62lrDj2ozMF79YxI2cnFHZ/gQ4RR 6lD65cqPufUfA3R7ayXRPmiH0ExdICTlW1RPigx/jj2vG8pmuvXde06E8w4emgudCA6b C/iWCE4JqDMxspBJZyFH90oi1RsSdqp3L3DEYHvv+XtiFvUPrH38y3cIi2NumQo5jKBS MqsfV8/huPWfJOQte6WxzhB46P9NMPU7oR+HzNEnOa58xTe6bG++S+m1iiferHtYqLe8 KS24xKThDzasP+W3nKiys13AUYtjYKUsVnImhhEt1CqpQMJxQQnL8GLlMMbaf2RXdkWY illA== 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=GN8DooxqnWYMX4Lx9QAzw7baLGn2b+1JMBP0il1xEM0=; fh=0fMRXu6fb19wc1ls5/A6XgmrIZ8VOCjNytU+xlwEpzM=; b=uxSPzM/ZFw61HGD3HnU++QqFdwQeESEYoJahImKo2qq9W44JMuYRS0wTkxBnIG20aJ /K5DHCXqzUUJWYiwMeWeWox4AW3d8jxwydVa7fpaaq1lzovsLCJoqEYfbqRJzbIyfMtY kpM0FngR4faFnwat7Pat+cn7s2V4DODxw2zgcZvJLP8ZgyT/6ScMCIkUJLniY4BFlmhv Pafj3D7oVsbHkJrvitCp1z1rnZ4QNLf7ZqrUKXbexTyJIXgA0APq3FrVEDuqyKkRfC2D 7XFeyCV9Aft2tx7rQcSe5KpaS+wnxtRGKBveTR8UA6trB6jHWZjQ6YA6LRkrz/Swm3tt xmIw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=F2QQAfnN; 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-74009-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74009-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cy28-20020a0564021c9c00b00563e973660asi3989810edb.100.2024.02.20.19.42.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:42:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74009-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=F2QQAfnN; 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-74009-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74009-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 9EF641F22402 for ; Wed, 21 Feb 2024 03:42:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2615139FCC; Wed, 21 Feb 2024 03:42:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="F2QQAfnN" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 2714438FAF for ; Wed, 21 Feb 2024 03:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486929; cv=none; b=pS4pvSBVoFzDsUPC4jPcLszMg9oAM56pZoyZBcnRlPAzb9ZItRvpNz+9AyF/5XFPmJV3m8TQpDos0EM/R4UFDqECSbOC5iT8x/0GolT0eEKF1AwRnb/zWSl+6Gyh9YxikvCIvVUb1uiJBIJiC7+KyYct09GoLRUrTCs1tKN1vY4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486929; c=relaxed/simple; bh=3dph1oOgPNiMARTIk1TUv0cnoXVZ3w2YcrnwEMmaGXE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=BHoQL74pAz8x207E14WUgn1vr6ByYCCaRImYUR1ce4NiUD97eO/25CWdx778zOFKe5m4LpJOAdJj0Wd+XEHXLRSTLVNlPDkCt212/ApytOrG3i2/CyK0tI5MxujB0DgOuLxC5GCQyb2pFTRPqlbE+T6rornkCB+KrlQUCobe0WQ= 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=F2QQAfnN; arc=none smtp.client-ip=209.85.128.201 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-yw1-f201.google.com with SMTP id 00721157ae682-60802b0afd2so42498567b3.1 for ; Tue, 20 Feb 2024 19:42:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708486927; x=1709091727; 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=GN8DooxqnWYMX4Lx9QAzw7baLGn2b+1JMBP0il1xEM0=; b=F2QQAfnNm3m+i8aHhWZVTGpzA2iBwyCjcb5CFKPzWgFZkzC4a3ty6VDa69vefd2k7Y Jq7P9oPJ2I3F0bRiMt6J330w6k1AifoFp5VS3fKE/diZOEip0lcp9Bh8GgRJFDwpDHnx ySWs600npH2jgmotkLzox7uWtUGwiFFtyBUkAhR0TwyJpWwZbu3Uw958rgOpxsJDD1O5 m+T7IE+btMN0xdlkuJnjcIBngdHU6AFgagmEhfDtZDPauBCx1EJEGDLi51pqhyJrplFv hgzDFSpYFoYndNGW33yrEVDIHP1JYd9eMTkgIML2DQy3gwx2FWfKVSVbcQokYH8NLvKM 15Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708486927; x=1709091727; 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=GN8DooxqnWYMX4Lx9QAzw7baLGn2b+1JMBP0il1xEM0=; b=omPr6rhUtX1iJ3vpOrIqZVhC/peBvTplZwyhfLVvBTXqpTFzDTUcRf55gqafmuX+Oe ZinGTFhfWyxF/RPLLMKwz9lSfKD+z/30PmhqTk4trGmSR9SvfJagi9U0Yhz8IdBTFPbz vj0ND4PXjIUFeQuBEklVY5D3qQijg9akHBY4OqnNhwvFncT0j4aGzGmVweb7+Oa0G84Y JlI4B5qW/U2GuIWB08eD5hT0IN86g6VfsMhklwT1ztYOgQNqWNVMIfWb1Ek+QIhaR4GV 5xzWvHNwoX/hn0v1d1PM4C/893/HmaMDGd9ibnf+rcoc1mhoPRUyHLULDv1RqDqU3VBE p3Fw== X-Forwarded-Encrypted: i=1; AJvYcCXQirE8AdTPktxsNuTtin/Ik1GHCig8Ew8+Md4LNpSObIP5L13EHKhjQp1z+33loExEFQWlniu60W2OW8h86KZwC2xZJHrX9LSQM+ii X-Gm-Message-State: AOJu0YzUV/vr7YQaqtxsKUuhIlmIQHuZ3+4oRoaC8yC4/IfrA0juYDEv vosmPQ1jH+5NXHlNcIi0rVAvkxevnurCGTMpQDvmvwVsa5HulUtVW34soYn9PDQWRtJA1kS4auI ye/6etw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:3c02:f882:5876:b7ab]) (user=irogers job=sendgmr) by 2002:a05:690c:338e:b0:608:28cf:3592 with SMTP id fl14-20020a05690c338e00b0060828cf3592mr2065532ywb.1.1708486927165; Tue, 20 Feb 2024 19:42:07 -0800 (PST) Date: Tue, 20 Feb 2024 19:41:49 -0800 In-Reply-To: <20240221034155.1500118-1-irogers@google.com> Message-Id: <20240221034155.1500118-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240221034155.1500118-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v6 2/8] perf list: Add scandirat compatibility function From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Athira Jajeev , James Clark , Kan Liang , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" scandirat is used during the printing of tracepoint events but may be missing from certain libcs. Add a compatibility implementation that uses the symlink of an fd in /proc as a path for the reliably present scandir. Signed-off-by: Ian Rogers --- tools/perf/util/print-events.c | 13 ++++--------- tools/perf/util/util.c | 19 +++++++++++++++++++ tools/perf/util/util.h | 8 ++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 9e47712507cc..0dc70b87d609 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -28,6 +28,7 @@ #include "tracepoint.h" #include "pfm.h" #include "thread_map.h" +#include "util.h" #define MAX_NAME_LEN 100 @@ -63,6 +64,8 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus { char *events_path = get_tracing_file("events"); int events_fd = open(events_path, O_PATH); + struct dirent **sys_namelist = NULL; + int sys_items; put_tracing_file(events_path); if (events_fd < 0) { @@ -70,10 +73,7 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus return; } -#ifdef HAVE_SCANDIRAT_SUPPORT -{ - struct dirent **sys_namelist = NULL; - int sys_items = tracing_events__scandir_alphasort(&sys_namelist); + sys_items = tracing_events__scandir_alphasort(&sys_namelist); for (int i = 0; i < sys_items; i++) { struct dirent *sys_dirent = sys_namelist[i]; @@ -130,11 +130,6 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus } free(sys_namelist); -} -#else - printf("\nWARNING: Your libc doesn't have the scandirat function, please ask its maintainers to implement it.\n" - " As a rough fallback, please do 'ls %s' to see the available tracepoint events.\n", events_path); -#endif close(events_fd); } diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index c1fd9ba6d697..4f561e5e4162 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -552,3 +552,22 @@ int sched_getcpu(void) return -1; } #endif + +#ifndef HAVE_SCANDIRAT_SUPPORT +int scandirat(int dirfd, const char *dirp, + struct dirent ***namelist, + int (*filter)(const struct dirent *), + int (*compar)(const struct dirent **, const struct dirent **)) +{ + char path[PATH_MAX]; + int err, fd = openat(dirfd, dirp, O_PATH); + + if (fd < 0) + return fd; + + snprintf(path, sizeof(path), "/proc/%d/fd/%d", getpid(), fd); + err = scandir(path, namelist, filter, compar); + close(fd); + return err; +} +#endif diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 7c8915d92dca..9966c21aaf04 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -6,6 +6,7 @@ /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ #define _DEFAULT_SOURCE 1 +#include #include #include #include @@ -56,6 +57,13 @@ int perf_tip(char **strp, const char *dirpath); int sched_getcpu(void); #endif +#ifndef HAVE_SCANDIRAT_SUPPORT +int scandirat(int dirfd, const char *dirp, + struct dirent ***namelist, + int (*filter)(const struct dirent *), + int (*compar)(const struct dirent **, const struct dirent **)); +#endif + extern bool perf_singlethreaded; void perf_set_singlethreaded(void); -- 2.44.0.rc0.258.g7320e95886-goog