From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753777AbcGHF4t (ORCPT ); Fri, 8 Jul 2016 01:56:49 -0400 Received: from LGEAMRELO13.lge.com ([156.147.23.53]:55535 "EHLO lgeamrelo13.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751551AbcGHF4c (ORCPT ); Fri, 8 Jul 2016 01:56:32 -0400 X-Original-SENDERIP: 156.147.1.126 X-Original-MAILFROM: namhyung@gmail.com X-Original-SENDERIP: 10.177.227.17 X-Original-MAILFROM: namhyung@gmail.com From: Namhyung Kim To: Steven Rostedt Cc: LKML , Joonsoo Kim , Namhyung Kim Subject: [PATCH 1/2] trace-cmd: Introduce tracecmd_peek_next_data() Date: Fri, 8 Jul 2016 14:56:11 +0900 Message-Id: <20160708055612.32221-1-namhyung@gmail.com> X-Mailer: git-send-email 2.9.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The tracecmd_peek_next_data() is similar to tracecmd_read_next_data() but it doesn't consume the record. Signed-off-by: Namhyung Kim --- trace-cmd.h | 3 +++ trace-input.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/trace-cmd.h b/trace-cmd.h index cef2458..5798345 100644 --- a/trace-cmd.h +++ b/trace-cmd.h @@ -164,6 +164,9 @@ struct pevent_record * tracecmd_read_next_data(struct tracecmd_input *handle, int *rec_cpu); struct pevent_record * +tracecmd_peek_next_data(struct tracecmd_input *handle, int *rec_cpu); + +struct pevent_record * tracecmd_read_at(struct tracecmd_input *handle, unsigned long long offset, int *cpu); struct pevent_record * diff --git a/trace-input.c b/trace-input.c index 2fea066..e825328 100644 --- a/trace-input.c +++ b/trace-input.c @@ -1787,6 +1787,49 @@ tracecmd_read_next_data(struct tracecmd_input *handle, int *rec_cpu) } /** + * tracecmd_peek_next_data - return the next record + * @handle: input handle to the trace.dat file + * @rec_cpu: return pointer to the CPU that the record belongs to + * + * This returns the next record by time. This is different than + * tracecmd_peek_data in that it looks at all CPUs. It does a peek + * at each CPU and the record with the earliest time stame is + * returned. If @rec_cpu is not NULL it gets the CPU id the record was + * on. It does not increment the CPU iterator. + */ +struct pevent_record * +tracecmd_peek_next_data(struct tracecmd_input *handle, int *rec_cpu) +{ + unsigned long long ts; + struct pevent_record *record, *next_record = NULL; + int next_cpu; + int cpu; + + if (rec_cpu) + *rec_cpu = -1; + + next_cpu = -1; + ts = 0; + + for (cpu = 0; cpu < handle->cpus; cpu++) { + record = tracecmd_peek_data(handle, cpu); + if (record && (!next_record || record->ts < ts)) { + ts = record->ts; + next_cpu = cpu; + next_record = record; + } + } + + if (next_record) { + if (rec_cpu) + *rec_cpu = next_cpu; + return next_record; + } + + return NULL; +} + +/** * tracecmd_read_prev - read the record before the given record * @handle: input handle to the trace.dat file * @record: the record to use to find the previous record. -- 2.9.0