trace-cmd library: Add tracecmd_iterate_events_reverse() API
PATCH 1/1 trace-cmd library: Add tracecmd_iterate_events_reverse() API
From: "Steven Rostedt (Google)" <[email protected]>
Add an iterator that starts at the end of a trace.dat file and iterates the events backward in time. That is, the first event will be the last event in the file, followed by the previous event, etc. This is useful for looking into what caused an event.
A flag is also added to continue where it last left off, as the end of the file is not a normal location, it doesn't make sense to have it start where it last left off like tracecmd_iterate_events() does.
The use case that inspired this change is to analyze cyclictest latency. First the print of the failed threshold must be found, which is at the end of the trace. Then the event of the wake up before the failed trace has to be found, and so on. Having a way to iterate backward is helpful in this case.
--- .../libtracecmd/libtracecmd-iterate.txt | 29 ++- Documentation/libtracecmd/libtracecmd.txt | 6 + include/trace-cmd/trace-cmd.h | 6 + lib/trace-cmd/trace-input.c | 198 ++++++++++++++++++ 4 files changed, 234 insertions(+), 5 deletions(-)
Documentation/libtracecmd/libtracecmd-iterate.txt +24 -5
@@ -24,6 +24,12 @@ int *tracecmd_iterate_events_multi*(struct tracecmd_input pass:[**]_handles_, struct tep_record pass:[*], int, void pass:[*]), void pass:[*]_callback_data_); +int *tracecmd_iterate_events_reverse*(struct tracecmd_input pass:[*]_handle_, + cpu_set_t pass:[*]_cpus_, int _cpu_size_, + int (pass:[*]_callback_)(struct tracecmd_input pass:[*], + struct tep_record pass:[*], + int, void pass:[*]), + void pass:[*]_callback_data_, bool _cont_); 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:[*],
@@ -71,7 +77,20 @@ as its last parameter. _callback_ may be NULL, which is useful if *tracecmd_fol is used, but note if _callback_ is NULL, then _callback_data_ is ignored and not sent to the _callback_ of *tracecmd_follow_event()*. -The _callback()_ for both *tracecmd_iterate_events()* and *tracecmd_iterate_events_multi()* is of the prototype: +The function *tracecmd_iterate_events_reverse()* works pretty much the same way as +*tracecmd_iterate_events()* works, but instead of calling the _callback_() function for +each event in order of the timestamp, it will call the _callback_() function for +each event in reverse order of the timestamp. If _cont_ is false, it will start by +calling the event with the oldest timestamp in the trace.dat file. If _cont_ is set +to true, then it will start whereever the current position of the tracing data is. +For instance, if the _callback()_ return something other than zero it will exit the +iteration. If *tracecmd_iterate_events_reverse()* is called again with _cont_ to true +it will continue where it left off. If _cont_ is false, it will start again at the event +with the oldest timestamp. The _handle_, _cpus_, _cpu_size_, and _callback_data_ act the +same as *tracecmd_iterate_events()*. + +The _callback()_ for both *tracecmd_iterate_events()*, *tracecmd_iterate_events_reverse()* +and *tracecmd_iterate_events_multi()* is of the prototype: int _callback()_(struct tracecmd_input pass:[*]_handle_, struct tep_record pass:[*]_record_, int _cpu_, void pass:[*]_data_);
@@ -123,10 +142,10 @@ the _callback()_ function in the iterators. RETURN VALUE ------------ -Both *tracecmd_iterate_events()* and *tracecmd_iterate_events_multi()* return zero -if they successfully iterated all events (handling the follow and filters appropriately). -Or an error value, which can include returning a non-zero result from the _callback()_ -function. +Both *tracecmd_iterate_events()*, *tracecmd_iterate_events_reverse()* and +*tracecmd_iterate_events_multi()* return zero if they successfully iterated all events +(handling the follow and filters appropriately). Or an error value, which can include +returning a non-zero result from the _callback()_ function. EXAMPLE -------
Documentation/libtracecmd/libtracecmd.txt +6 -0
@@ -40,6 +40,12 @@ Iterating over events in a trace file: struct tep_record pass:[*], int, void pass:[*]), void pass:[*]_callback_data_); + int *tracecmd_iterate_events_reverse*(struct tracecmd_input pass:[*]_handle_, + cpu_set_t pass:[*]_cpus_, int _cpu_size_, + int (pass:[*]_callback_)(struct tracecmd_input pass:[*], + struct tep_record pass:[*], + int, void pass:[*]), + void pass:[*]_callback_data_, bool _cont_); 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 +6 -0
@@ -84,6 +84,12 @@ int tracecmd_iterate_events_multi(struct tracecmd_input **handles, struct tep_record *, int, void *), void *callback_data); +int tracecmd_iterate_events_reverse (struct tracecmd_input *handle, +cpu_set_t *cpus,int cpu_size, +int (*callback)(struct tracecmd_input *handle, +struct tep_record *, +int ,void *), +void *callback_data,bool cont);void tracecmd_set_loglevel (enum tep_loglevel level);
lib/trace-cmd/trace-input.c +198 -0
204 lines not on this page · raw message
Signature · 1 line
2.39.2