Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5879280ybi; Sun, 21 Jul 2019 04:32:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4fZVDmk9H6uHjijlocRTNIyZyJ/heoraVul7yoPkhaQgvYP6W68bGB4OEEz0vu64mpVMb X-Received: by 2002:a65:5304:: with SMTP id m4mr65417241pgq.126.1563708774501; Sun, 21 Jul 2019 04:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563708774; cv=none; d=google.com; s=arc-20160816; b=Py2Ag/WbmVwLlm/nCAimCU2Ly/eKjrJ5Xp4afXc8guoHLOZ0yszwpkuV0ooSGCG445 AziE9uaLSmPLJ2RbGpZUUQ22K0ND/3tQ/lusGrqfhNgrC0xAlWuU7ZHRG34SSyCau1US lsHJx1uPyWNFppqVoOfTfitpCtiL7VLVVXllXT+fFDUXksLeUpQb9xwhJRQube7UXibN aLWDAjlZPsTZJHE5baro4K0cD76/zB7lQ3ByKkePKWHrgxkSZEiMqcWdzLpdGRmcC/FB kR+WW4wy1dNfE68SLmhWRh4ue963rzRx23MY/m70nf1Hmz9QVcU9TfQBCycXeL7wk64y 8IOw== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=o5oUhs9qxw/4z9ZxS4ziRWnsUqfMNYFy1yfR7JX4q1E=; b=B2S+MDmDAkAEJf2hp4qzWeaRmfi/8bdLs3Nwj/6is+ZoLfPO0vAoh7WqxTA6RYy+Dp y8gNu6zLAb5hBLaoGFRZdv5KtjBmxUaQKQgmkhpuxAkfui9QXx1WYomBbHnUuBDVIkkB K6sCegRQgGVvHSfoSFYlFSJjJDqZkex13j9ghiqQdU94SE/XZIwrx7IK1r1hx5TIP+Kc WLVSIVIi3+w3GjDw7qAxLKYFRNCwUW8anGWTnb2RtlZYVhcElkVTjqOFjRBHj5KU9lpX THb88u6Go5iq707C7B/VNm2tgMNk1F3b3gnw8FzQwQqD0nkl0UJm1O5/pw8FXzVrX8Hd 9sag== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m189si7645725pgm.443.2019.07.21.04.32.38; Sun, 21 Jul 2019 04:32:54 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726741AbfGULal (ORCPT + 99 others); Sun, 21 Jul 2019 07:30:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35528 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726247AbfGULal (ORCPT ); Sun, 21 Jul 2019 07:30:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 010BF307D90E; Sun, 21 Jul 2019 11:30:41 +0000 (UTC) Received: from krava.redhat.com (ovpn-204-23.brq.redhat.com [10.40.204.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 057B15D9D3; Sun, 21 Jul 2019 11:30:36 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Andi Kleen , Alexey Budankov , Michael Petlan Subject: [PATCH 47/79] libperf: Add perf_evlist__for_each_evsel macro Date: Sun, 21 Jul 2019 13:24:34 +0200 Message-Id: <20190721112506.12306-48-jolsa@kernel.org> In-Reply-To: <20190721112506.12306-1-jolsa@kernel.org> References: <20190721112506.12306-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sun, 21 Jul 2019 11:30:41 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding perf_evlist__for_each_evsel macro to iterate perf_evsel objects in evlist. Adding perf_evlist__next function to do that. Link: http://lkml.kernel.org/n/tip-usi0zxyxmai1ld94nrbum43i@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/lib/evlist.c | 20 ++++++++++++++++++++ tools/perf/lib/include/perf/evlist.h | 7 +++++++ tools/perf/lib/libperf.map | 1 + 3 files changed, 28 insertions(+) diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c index 0517deb4cb1c..8c26ebf290f0 100644 --- a/tools/perf/lib/evlist.c +++ b/tools/perf/lib/evlist.c @@ -34,3 +34,23 @@ struct perf_evlist *perf_evlist__new(void) return evlist; } + +struct perf_evsel* +perf_evlist__next(struct perf_evlist *evlist, struct perf_evsel *prev) +{ + struct perf_evsel *next; + + if (!prev) { + next = list_first_entry(&evlist->entries, + struct perf_evsel, + node); + } else { + next = list_next_entry(prev, node); + } + + /* Empty list is noticed here so don't need checking on entry. */ + if (&next->node == &evlist->entries) + return NULL; + + return next; +} diff --git a/tools/perf/lib/include/perf/evlist.h b/tools/perf/lib/include/perf/evlist.h index 7255a60869a1..5092b622935b 100644 --- a/tools/perf/lib/include/perf/evlist.h +++ b/tools/perf/lib/include/perf/evlist.h @@ -13,5 +13,12 @@ LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist, LIBPERF_API void perf_evlist__remove(struct perf_evlist *evlist, struct perf_evsel *evsel); LIBPERF_API struct perf_evlist *perf_evlist__new(void); +LIBPERF_API struct perf_evsel* perf_evlist__next(struct perf_evlist *evlist, + struct perf_evsel *evsel); + +#define perf_evlist__for_each_evsel(evlist, pos) \ + for ((pos) = perf_evlist__next((evlist), NULL); \ + (pos) != NULL; \ + (pos) = perf_evlist__next((evlist), (pos))) #endif /* __LIBPERF_EVLIST_H */ diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map index e3eac9b60726..c0968226f7b6 100644 --- a/tools/perf/lib/libperf.map +++ b/tools/perf/lib/libperf.map @@ -17,6 +17,7 @@ LIBPERF_0.0.1 { perf_evlist__init; perf_evlist__add; perf_evlist__remove; + perf_evlist__next; local: *; }; -- 2.21.0