diff options
author | Namhyung Kim <namhyung@gmail.com> | 2016-07-08 14:56:11 +0900 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2016-07-11 12:49:16 -0400 |
commit | 496c5d9ce71e8648af4be7bf0912f86f1ea4f19e (patch) | |
tree | 37829cb42ff65797f5e4a5ec0cd1ffe8b0b121ad | |
parent | 4421d9551b903d720bb8534a02c3564187eab045 (diff) | |
download | trace-cmd-496c5d9ce71e8648af4be7bf0912f86f1ea4f19e.tar.gz |
trace-cmd: Introduce tracecmd_peek_next_data()
The tracecmd_peek_next_data() is similar to tracecmd_read_next_data()
but it doesn't consume the record.
Link: http://lkml.kernel.org/r/20160708055612.32221-1-namhyung@gmail.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-cmd.h | 3 | ||||
-rw-r--r-- | trace-input.c | 43 |
2 files changed, 46 insertions, 0 deletions
diff --git a/trace-cmd.h b/trace-cmd.h index cef2458a..57983453 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 2fea0668..e8253288 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. |