Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752607AbdLFXe3 (ORCPT ); Wed, 6 Dec 2017 18:34:29 -0500 Received: from mga14.intel.com ([192.55.52.115]:6561 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752214AbdLFXd2 (ORCPT ); Wed, 6 Dec 2017 18:33:28 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,370,1508828400"; d="scan'208";a="9735666" From: kan.liang@intel.com To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: jolsa@kernel.org, wangnan0@huawei.com, namhyung@kernel.org, ak@linux.intel.com, yao.jin@linux.intel.com, Kan Liang Subject: [PATCH V2 4/8] perf tools: introduce perf_mmap__read_event Date: Wed, 6 Dec 2017 15:32:59 -0800 Message-Id: <1512603183-42754-5-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1512603183-42754-1-git-send-email-kan.liang@intel.com> References: <1512603183-42754-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2220 Lines: 73 From: Kan Liang Currently, there is no generic function to read event from ring buffer, which support both overwirte and non-overwrite mode. Indroduce perf_mmap__read_event to do so. The usage is as below. perf_mmap__read_catchup() while(event = perf_mmap__read_event()) { //process the event perf_mmap__consume() } perf_mmap__read_done() Signed-off-by: Kan Liang --- tools/perf/util/mmap.c | 25 +++++++++++++++++++++++++ tools/perf/util/mmap.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 61237eb..7c4c69a 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -146,6 +146,31 @@ void perf_mmap__read_done(struct perf_mmap *map) map->prev = perf_mmap__read_head(map); } + +/* + * Read event from ring buffer. Return one event for each call. + * Support both overwirte and non-overwrite mode. + * The start and end are only available for overwirte mode, which + * pause the ringbuffer. + * + * Usage: + * perf_mmap__read_catchup + * while(event = perf_mmap__read_event) { + * //process the event + * perf_mmap__consume + * } + * perf_mmap__read_done + */ +union perf_event *perf_mmap__read_event(struct perf_mmap *map, + bool overwrite, + u64 *start, u64 end) +{ + if (overwrite) + return perf_mmap__read_backward(map, start, end); + else + return perf_mmap__read_forward(map); +} + static bool perf_mmap__empty(struct perf_mmap *map) { return perf_mmap__read_head(map) == map->prev && !map->auxtrace_mmap.base; diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index a91222e..7082a7c 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h @@ -91,6 +91,9 @@ static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail) union perf_event *perf_mmap__read_forward(struct perf_mmap *map); union perf_event *perf_mmap__read_backward(struct perf_mmap *map, u64 *start, u64 end); +union perf_event *perf_mmap__read_event(struct perf_mmap *map, + bool overwrite, + u64 *start, u64 end); int perf_mmap__push(struct perf_mmap *md, bool backward, void *to, int push(void *to, void *buf, size_t size)); -- 2.5.5