libtraceevent: Add tep_record_is_event() API
PATCH 1/1 libtraceevent: Add tep_record_is_event() API
From: "Steven Rostedt (Google)" <[email protected]>
Add a new API tep_record_is_event(). It's becoming a common pattern in parsing traces, where the code will have:
int type;
type = tep_data_type(event->tep, record);
if (event->id == type) {
/* do something */
}Make it a helper function
Signed-off-by Steven Rostedt (Google) <[email protected]>
--- Documentation/libtraceevent-event_find.txt | 11 ++++++++--- Documentation/libtraceevent.txt | 1 + include/traceevent/event-parse.h | 2 ++ src/event-parse.c | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-)
Documentation/libtraceevent-event_find.txt +8 -3
@@ -3,7 +3,7 @@ libtraceevent(3) NAME ---- -tep_find_event,tep_find_event_by_name,tep_find_event_by_record - +tep_find_event,tep_find_event_by_name,tep_find_event_by_record, tep_record_is_event - Find events by given key. SYNOPSIS
@@ -15,6 +15,7 @@ SYNOPSIS struct tep_event pass:[*]*tep_find_event*(struct tep_handle pass:[*]_tep_, int _id_); struct tep_event pass:[*]*tep_find_event_by_name*(struct tep_handle pass:[*]_tep_, const char pass:[*]_sys_, const char pass:[*]_name_); struct tep_event pass:[*]*tep_find_event_by_record*(struct tep_handle pass:[*]_tep_, struct tep_record pass:[*]_record_); +bool *tep_record_is_event*(struct tep_record pass:[*]record, struct tep_event pass:[*]event); -- DESCRIPTION
@@ -31,12 +32,16 @@ The *tep_find_event_by_name()* function searches for an event by given event _name_, under the system _sys_. If the _sys_ is NULL (not specified), the first event with _name_ is returned. -The tep_find_event_by_record()* function searches for an event from a given +The *tep_find_event_by_record()* function searches for an event from a given _record_. +The *tep_record_is_event()* function tests if the given _record_ is of the type +of the _event_. This is normally used to know if the _record_ being processed is +of an _event_ where further processing should be done. + RETURN VALUE ------------ -All these functions return a pointer to the found event, or NULL if there is no +All these functions except *tep_record_is_event()* return a pointer to the found event, or NULL if there is no such event. EXAMPLE
Documentation/libtraceevent.txt +1 -0
@@ -83,6 +83,7 @@ Event finding: struct tep_event pass:[*]*tep_find_event*(struct tep_handle pass:[*]_tep_, int _id_); struct tep_event pass:[*]*tep_find_event_by_name*(struct tep_handle pass:[*]_tep_, const char pass:[*]_sys_, const char pass:[*]_name_); struct tep_event pass:[*]*tep_find_event_by_record*(struct tep_handle pass:[*]_tep_, struct tep_record pass:[*]_record_); + bool *tep_record_is_event*(struct tep_record pass:[*]record, struct tep_event pass:[*]event); Parsing of event files: int *tep_parse_header_page*(struct tep_handle pass:[*]_tep_, char pass:[*]_buf_, unsigned long _size_, int _long_size_);
include/traceevent/event-parse.h +2 -0
@@ -554,6 +554,8 @@ struct tep_cmdline *tep_data_pid_from_comm(struct tep_handle *tep, const char *c struct tep_cmdline *next);int tep_cmdline_pid (struct tep_handle *tep,struct tep_cmdline *cmdline); +bool tep_record_is_event (struct tep_record *record,struct tep_event *event); +void tep_print_field_content (struct trace_seq *s,void *data,int size,struct tep_format_field *field); void tep_record_print_fields(struct trace_seq *s,
src/event-parse.c +15 -0
@@ -6872,6 +6872,21 @@ const char *tep_data_comm_from_pid(struct tep_handle *tep, int pid)return comm; } +/** +* tep_record_is_event - return true if the given record is the given event +* @record: The record to see is the @event +* @event: The event to test against @record +* +* Returns true if the record is of the given event, false otherwise +*/ +bool tep_record_is_event (struct tep_record *record,struct tep_event *event) +{ +int type; + + type =tep_data_type (event->tep, record); +return event->id == type; +} +static struct tep_cmdline *pid_from_cmdlist (struct tep_handle *tep,const char *comm,struct tep_cmdline *next) {
Signature · 1 line
2.40.1