libtracecmd: Add tracecmd_iterate_reset() API
PATCH 1/1 libtracecmd: Add tracecmd_iterate_reset() API
From: "Steven Rostedt (Google)" <[email protected]>
As tracecmd_iterate_events_reverse() takes a flag to state if it should continue where it left off the last time it was called, or to start back at the end of the file, I realized there was no equivalent flag for tracecmd_iterate_events() itself. Currently it always starts where it left off.
Add tracecmd_iterate_reset() that will make cause tracecmd_iterate_events() to start at the beginning of the file.
Signed-off-by Steven Rostedt (Google) <[email protected]>
--- .../libtracecmd/libtracecmd-iterate.txt | 9 +++++- Documentation/libtracecmd/libtracecmd.txt | 1 + include/trace-cmd/trace-cmd.h | 2 ++ lib/trace-cmd/trace-input.c | 28 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-)
Documentation/libtracecmd/libtracecmd-iterate.txt +8 -1
@@ -4,7 +4,7 @@ libtracecmd(3) NAME ---- tracecmd_iterate_events, tracecmd_iterate_events_multi, tracecmd_follow_event, -tracecmd_follow_missed_events, tracecmd_filter_add - Read events from a trace file +tracecmd_follow_missed_events, tracecmd_filter_add, tracecmd_iterate_reset - Read events from a trace file SYNOPSIS --------
@@ -30,6 +30,7 @@ int *tracecmd_iterate_events_reverse*(struct tracecmd_input pass:[*]_handle_, struct tep_record pass:[*], int, void pass:[*]), void pass:[*]_callback_data_, bool _cont_); +void *tracecmd_iterate_reset*(struct tracecmd_input pass:[*]_handle_); int *tracecmd_follow_event*(struct tracecmd_input pass:[*]_handle_, const char pass:[*]_system_, const char pass:[*]_event_name_, int (pass:[*]_callback_)(struct tracecmd_input pass:[*],
@@ -102,6 +103,10 @@ The _record_ is the current event record. The _cpu_ is the current CPU being pro CPU of all the _handles_ put together. Use _record_->cpu to get the actual CPU that the event is on. +The *tracecmd_iterate_reset()* function resets the cursor back to the start of the +trace file. That is, the next call to *tracecmd_iterate_events()* on _handle_ will start at the +first event of _handle_. + The *tracecmd_follow_event()* function will attach to a trace file descriptor _handle_ and call the _callback_ when the event described by _system_ and _name_ matches an event in the iteration of *tracecmd_iterate_events()* or *tracecmd_iterate_events_multi()*.
@@ -147,6 +152,8 @@ Both *tracecmd_iterate_events()*, *tracecmd_iterate_events_reverse()* and (handling the follow and filters appropriately). Or an error value, which can include returning a non-zero result from the _callback()_ function. +The *tracecmd_iterate_reset()* returns 0 on success and -1 on error. + EXAMPLE ------- [source,c]
Documentation/libtracecmd/libtracecmd.txt +1 -0
@@ -46,6 +46,7 @@ Iterating over events in a trace file: struct tep_record pass:[*], int, void pass:[*]), void pass:[*]_callback_data_, bool _cont_); + void *tracecmd_iterate_reset*(struct tracecmd_input pass:[*]_handle_); int *tracecmd_follow_event*(struct tracecmd_input pass:[*]_handle_, const char pass:[*]_system_, const char pass:[*]_event_name_, int (pass:[*]_callback_)(struct tracecmd_input pass:[*],
include/trace-cmd/trace-cmd.h +2 -0
@@ -72,6 +72,8 @@ int tracecmd_follow_missed_events(struct tracecmd_input *handle, int, void *), void *callback_data); +void tracecmd_iterate_reset (struct tracecmd_input *handle); + int tracecmd_iterate_events(struct tracecmd_input *handle, cpu_set_t *cpus, int cpu_size, int (*callback)(struct tracecmd_input *handle,
lib/trace-cmd/trace-input.c +28 -0
@@ -2108,6 +2108,34 @@ tracecmd_read_cpu_first(struct tracecmd_input *handle, int cpu)return tracecmd_read_data (handle, cpu); } +/** +* tracecmd_iterate_reset - Set the handle to iterate from the beginning +* @handle: input handle for the trace.dat file +* +* This causes tracecmd_iterate_events*() to start from the beginning +* of the trace.dat file. +*/ +void tracecmd_iterate_reset (struct tracecmd_input *handle) +{ +unsigned long long page_offset; +int cpu; +int ret; + +for (cpu =0 ; cpu < handle->cpus; cpu++) { + page_offset =calc_page_offset (handle, handle->cpu_data[cpu].file_offset); + + ret =get_page (handle, cpu, page_offset); +if (ret <0 ) +continue ;/* ?? */ + +/* If the page was already mapped, we need to reset it */ +if (ret) +update_page_info (handle, cpu); + +free_next (handle, cpu); + } +} +/** * tracecmd_read_cpu_last - get the last record in a CPU * @handle: input handle for the trace.dat file
Signature · 1 line
2.42.0