Commit 38847db9 authored by Tzvetomir Stoyanov's avatar Tzvetomir Stoyanov Committed by Arnaldo Carvalho de Melo

libtraceevent, perf tools: Changes in tep_print_event_* APIs

Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.

These APIs are reimplemented to provide a more simple interface for
printing event information.

Removed APIs:

 	tep_print_event_task()
	tep_print_event_time()
	tep_print_event_data()
	tep_event_info()
	tep_is_latency_format()
	tep_set_latency_format()
	tep_data_latency_format()
	tep_set_print_raw()

A new API for printing event information is introduced:
   void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
		        struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
 TEP_PRINT_PID, "%d" - event PID
 TEP_PRINT_CPU, "%d" - event CPU
 TEP_PRINT_COMM, "%s" - event command string
 TEP_PRINT_NAME, "%s" - event name
 TEP_PRINT_LATENCY, "%s" - event latency
 TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
   can be specified as part of this format string:
   "%precision.divisord". Example:
   "%3.1000d" - divide the time by 1000 and print the first 3 digits
   before the dot. Thus, the time stamp "123456000" will be printed as
   "123.456"
 TEP_PRINT_INFO, "%s" - event information.
 TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.

Example:
  tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
		  TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
		  TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
	ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: default avatarTzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.orgSigned-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 4cb3c6d5
...@@ -302,33 +302,6 @@ void tep_set_local_bigendian(struct tep_handle *tep, enum tep_endian endian) ...@@ -302,33 +302,6 @@ void tep_set_local_bigendian(struct tep_handle *tep, enum tep_endian endian)
tep->host_bigendian = endian; tep->host_bigendian = endian;
} }
/**
* tep_is_latency_format - get if the latency output format is configured
* @tep: a handle to the tep_handle
*
* This returns true if the latency output format is configured
* If @tep is NULL, false is returned.
*/
bool tep_is_latency_format(struct tep_handle *tep)
{
if (tep)
return (tep->latency_format);
return false;
}
/**
* tep_set_latency_format - set the latency output format
* @tep: a handle to the tep_handle
* @lat: non zero for latency output format
*
* This sets the latency output format
*/
void tep_set_latency_format(struct tep_handle *tep, int lat)
{
if (tep)
tep->latency_format = lat;
}
/** /**
* tep_is_old_format - get if an old kernel is used * tep_is_old_format - get if an old kernel is used
* @tep: a handle to the tep_handle * @tep: a handle to the tep_handle
...@@ -344,19 +317,6 @@ bool tep_is_old_format(struct tep_handle *tep) ...@@ -344,19 +317,6 @@ bool tep_is_old_format(struct tep_handle *tep)
return false; return false;
} }
/**
* tep_set_print_raw - set a flag to force print in raw format
* @tep: a handle to the tep_handle
* @print_raw: the new value of the print_raw flag
*
* This sets a flag to force print in raw format
*/
void tep_set_print_raw(struct tep_handle *tep, int print_raw)
{
if (tep)
tep->print_raw = print_raw;
}
/** /**
* tep_set_test_filters - set a flag to test a filter string * tep_set_test_filters - set a flag to test a filter string
* @tep: a handle to the tep_handle * @tep: a handle to the tep_handle
......
...@@ -28,8 +28,6 @@ struct tep_handle { ...@@ -28,8 +28,6 @@ struct tep_handle {
enum tep_endian file_bigendian; enum tep_endian file_bigendian;
enum tep_endian host_bigendian; enum tep_endian host_bigendian;
int latency_format;
int old_format; int old_format;
int cpus; int cpus;
...@@ -70,8 +68,6 @@ struct tep_handle { ...@@ -70,8 +68,6 @@ struct tep_handle {
int ld_offset; int ld_offset;
int ld_size; int ld_size;
int print_raw;
int test_filters; int test_filters;
int flags; int flags;
......
This diff is collapsed.
...@@ -442,18 +442,18 @@ int tep_register_print_string(struct tep_handle *tep, const char *fmt, ...@@ -442,18 +442,18 @@ int tep_register_print_string(struct tep_handle *tep, const char *fmt,
unsigned long long addr); unsigned long long addr);
bool tep_is_pid_registered(struct tep_handle *tep, int pid); bool tep_is_pid_registered(struct tep_handle *tep, int pid);
void tep_print_event_task(struct tep_handle *tep, struct trace_seq *s, #define TEP_PRINT_INFO "INFO"
struct tep_event *event, #define TEP_PRINT_INFO_RAW "INFO_RAW"
struct tep_record *record); #define TEP_PRINT_COMM "COMM"
void tep_print_event_time(struct tep_handle *tep, struct trace_seq *s, #define TEP_PRINT_LATENCY "LATENCY"
struct tep_event *event, #define TEP_PRINT_NAME "NAME"
struct tep_record *record, #define TEP_PRINT_PID 1U
bool use_trace_clock); #define TEP_PRINT_TIME 2U
void tep_print_event_data(struct tep_handle *tep, struct trace_seq *s, #define TEP_PRINT_CPU 3U
struct tep_event *event,
struct tep_record *record);
void tep_print_event(struct tep_handle *tep, struct trace_seq *s, void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, bool use_trace_clock); struct tep_record *record, const char *fmt, ...)
__attribute__ ((format (printf, 4, 5)));
int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size, int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size,
int long_size); int long_size);
...@@ -525,8 +525,6 @@ tep_find_event_by_name(struct tep_handle *tep, const char *sys, const char *name ...@@ -525,8 +525,6 @@ tep_find_event_by_name(struct tep_handle *tep, const char *sys, const char *name
struct tep_event * struct tep_event *
tep_find_event_by_record(struct tep_handle *tep, struct tep_record *record); tep_find_event_by_record(struct tep_handle *tep, struct tep_record *record);
void tep_data_latency_format(struct tep_handle *tep,
struct trace_seq *s, struct tep_record *record);
int tep_data_type(struct tep_handle *tep, struct tep_record *rec); int tep_data_type(struct tep_handle *tep, struct tep_record *rec);
int tep_data_pid(struct tep_handle *tep, struct tep_record *rec); int tep_data_pid(struct tep_handle *tep, struct tep_record *rec);
int tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec); int tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec);
...@@ -541,8 +539,6 @@ void tep_print_field(struct trace_seq *s, void *data, ...@@ -541,8 +539,6 @@ void tep_print_field(struct trace_seq *s, void *data,
struct tep_format_field *field); struct tep_format_field *field);
void tep_print_fields(struct trace_seq *s, void *data, void tep_print_fields(struct trace_seq *s, void *data,
int size __maybe_unused, struct tep_event *event); int size __maybe_unused, struct tep_event *event);
void tep_event_info(struct trace_seq *s, struct tep_event *event,
struct tep_record *record);
int tep_strerror(struct tep_handle *tep, enum tep_errno errnum, int tep_strerror(struct tep_handle *tep, enum tep_errno errnum,
char *buf, size_t buflen); char *buf, size_t buflen);
...@@ -566,12 +562,9 @@ bool tep_is_file_bigendian(struct tep_handle *tep); ...@@ -566,12 +562,9 @@ bool tep_is_file_bigendian(struct tep_handle *tep);
void tep_set_file_bigendian(struct tep_handle *tep, enum tep_endian endian); void tep_set_file_bigendian(struct tep_handle *tep, enum tep_endian endian);
bool tep_is_local_bigendian(struct tep_handle *tep); bool tep_is_local_bigendian(struct tep_handle *tep);
void tep_set_local_bigendian(struct tep_handle *tep, enum tep_endian endian); void tep_set_local_bigendian(struct tep_handle *tep, enum tep_endian endian);
bool tep_is_latency_format(struct tep_handle *tep);
void tep_set_latency_format(struct tep_handle *tep, int lat);
int tep_get_header_page_size(struct tep_handle *tep); int tep_get_header_page_size(struct tep_handle *tep);
int tep_get_header_timestamp_size(struct tep_handle *tep); int tep_get_header_timestamp_size(struct tep_handle *tep);
bool tep_is_old_format(struct tep_handle *tep); bool tep_is_old_format(struct tep_handle *tep);
void tep_set_print_raw(struct tep_handle *tep, int print_raw);
void tep_set_test_filters(struct tep_handle *tep, int test_filters); void tep_set_test_filters(struct tep_handle *tep, int test_filters);
struct tep_handle *tep_alloc(void); struct tep_handle *tep_alloc(void);
......
...@@ -750,7 +750,8 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, ...@@ -750,7 +750,8 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample,
} }
trace_seq_init(&seq); trace_seq_init(&seq);
tep_event_info(&seq, evsel->tp_format, &record); tep_print_event(evsel->tp_format->tep,
&seq, &record, "%s", TEP_PRINT_INFO);
str = strtok_r(seq.buffer, " ", &pos); str = strtok_r(seq.buffer, " ", &pos);
while (str) { while (str) {
......
...@@ -709,7 +709,8 @@ static char *get_trace_output(struct hist_entry *he) ...@@ -709,7 +709,8 @@ static char *get_trace_output(struct hist_entry *he)
tep_print_fields(&seq, he->raw_data, he->raw_size, tep_print_fields(&seq, he->raw_data, he->raw_size,
evsel->tp_format); evsel->tp_format);
} else { } else {
tep_event_info(&seq, evsel->tp_format, &rec); tep_print_event(evsel->tp_format->tep,
&seq, &rec, "%s", TEP_PRINT_INFO);
} }
/* /*
* Trim the buffer, it starts at 4KB and we're not going to * Trim the buffer, it starts at 4KB and we're not going to
......
...@@ -109,7 +109,7 @@ void event_format__fprintf(struct tep_event *event, ...@@ -109,7 +109,7 @@ void event_format__fprintf(struct tep_event *event,
record.data = data; record.data = data;
trace_seq_init(&s); trace_seq_init(&s);
tep_event_info(&s, event, &record); tep_print_event(event->tep, &s, &record, "%s", TEP_PRINT_INFO);
trace_seq_do_fprintf(&s, fp); trace_seq_do_fprintf(&s, fp);
trace_seq_destroy(&s); trace_seq_destroy(&s);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment