Avoid parsing tracepoint format just for id
Ian Rogers
reviewerv2 cover Avoid parsing tracepoint format just for id
The tracepoint format isn't needed to open an event, just the id for the config value. Refactor the use of evsel->tp_format to use an accessor that will lazily construct its value. In evsel__newtp_idx read the id so the config value can be set up/used.
This allows tracepoints to be used without libtraceevent in a number of tests. Other functionality is enabled without libtracevent, such as mapping a tracepoint id back to its name. There may be some performance benefit to code using tracepoints but not using the format information.
v2. Add additional error checking/handling in evsel__tp_format.
Ian Rogers (6):
tool api fs: Correctly encode errno for read/write open failures perf trace-event: Constify print arguments
perf trace-event: Always build trace-event-info.c perf evsel: Add/use accessor for tp_format
perf evsel: Allow evsel__newtp without libtraceevent perf tests: Enable tests disabled due to tracepoint parsing
tools/lib/api/fs/fs.c | 6 +- tools/perf/builtin-kmem.c | 15 ++- tools/perf/builtin-kwork.c | 3 +- tools/perf/builtin-record.c | 2 - tools/perf/builtin-script.c | 9 +- tools/perf/builtin-trace.c | 80 +++++++++---- tools/perf/tests/Build | 6 +- tools/perf/tests/builtin-test.c | 2 - tools/perf/tests/parse-events.c | 25 +--- tools/perf/util/Build | 2 +- tools/perf/util/data-convert-bt.c | 10 +- tools/perf/util/data-convert-json.c | 8 +- tools/perf/util/evsel.c | 110 +++++++++++++----- tools/perf/util/evsel.h | 9 +- tools/perf/util/evsel_fprintf.c | 4 +- tools/perf/util/parse-events.c | 16 +-- tools/perf/util/perf_event_attr_fprintf.c | 4 - .../util/scripting-engines/trace-event-perl.c | 3 +- .../scripting-engines/trace-event-python.c | 3 +- tools/perf/util/sort.c | 33 ++++-- tools/perf/util/trace-event-parse.c | 4 +- tools/perf/util/trace-event-scripting.c | 10 +- tools/perf/util/trace-event.h | 4 +- 23 files changed, 219 insertions(+), 149 deletions(-)
Signature · 1 line
2.47.0.199.ga7371fff76-goog
Ian Rogers
reviewerPATCH v2 1/6 tool api fs: Correctly encode errno for read/write open failures
Switch from returning -1 to -errno so that callers can determine types of failure.
--- tools/lib/api/fs/fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/lib/api/fs/fs.c +3 -3
@@ -296,7 +296,7 @@ int filename__read_int(const char *filename, int *value)int fd =open (filename,O_RDONLY ), err =-1 ;if (fd <0 ) -return -1 ; +return -errno;if (read (fd, line,sizeof (line)) >0 ) { *value =atoi (line);
@@ -314,7 +314,7 @@ static int filename__read_ull_base(const char *filename,int fd =open (filename,O_RDONLY ), err =-1 ;if (fd <0 ) -return -1 ; +return -errno;if (read (fd, line,sizeof (line)) >0 ) { *value =strtoull (line,NULL , base);
@@ -372,7 +372,7 @@ int filename__write_int(const char *filename, int value)char buf[64 ];if (fd <0 ) -return err; +return -errno;sprintf (buf,"%d" , value);if (write (fd, buf,sizeof (buf)) ==sizeof (buf))
Signature · 1 line
2.47.0.199.ga7371fff76-goog
Re: [PATCH v2 1/6] tool api fs: Correctly encode errno for read/write open failures
Quoted 2 lines · Ian Rogers
Switch from returning -1 to -errno so that callers can determine types of failure.
- Arnaldo
Quoted 38 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/lib/api/fs/fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)tools/lib/api/fs/fs.c +3
-3@@ -296,7 +296,7 @@ int filename__read_int(const char *filename, int *value)int fd =open (filename,O_RDONLY ), err =-1 ;if (fd <0 ) -return -1 ; +return -errno;if (read (fd, line,sizeof (line)) >0 ) { *value =atoi (line);@@ -314,7 +314,7 @@ static int filename__read_ull_base(const char *filename,int fd =open (filename,O_RDONLY ), err =-1 ;if (fd <0 ) -return -1 ; +return -errno;if (read (fd, line,sizeof (line)) >0 ) { *value =strtoull (line,NULL , base);@@ -372,7 +372,7 @@ int filename__write_int(const char *filename, int value)char buf[64 ];if (fd <0 ) -return err; +return -errno;sprintf (buf,"%d" , value);if (write (fd, buf,sizeof (buf)) ==sizeof (buf))Signature · 1 line
2.47.0.199.ga7371fff76-goog
Ian Rogers
reviewerPATCH v2 2/6 perf trace-event: Constify print arguments
In reply to Ian RogersCapture that these functions don't mutate their input.
--- tools/perf/util/trace-event-parse.c | 4 ++-- tools/perf/util/trace-event.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/trace-event-parse.c +2 -2
@@ -99,7 +99,7 @@ unsigned long long read_size(struct tep_event *event, void *ptr, int size)return tep_read_number (event->tep, ptr, size); } -void event_format__fprintf (struct tep_event *event, +void event_format__fprintf (const struct tep_event *event,int cpu,void *data,int size,FILE *fp) {struct tep_record record;
@@ -116,7 +116,7 @@ void event_format__fprintf(struct tep_event *event,trace_seq_destroy (&s); } -void event_format__print (struct tep_event *event, +void event_format__print (const struct tep_event *event,int cpu,void *data,int size) {return event_format__fprintf (event, cpu, data, size, stdout);
tools/perf/util/trace-event.h +2 -2
@@ -39,10 +39,10 @@ trace_event__tp_format(const char *sys, const char *name);struct tep_event *trace_event__tp_format_id (int id); -void event_format__fprintf (struct tep_event *event, +void event_format__fprintf (const struct tep_event *event,int cpu,void *data,int size,FILE *fp); -void event_format__print (struct tep_event *event, +void event_format__print (const struct tep_event *event,int cpu,void *data,int size);int parse_ftrace_file (struct tep_handle *pevent,char *buf,unsigned long size);
Signature · 1 line
2.47.0.199.ga7371fff76-goog
Re: [PATCH v2 2/6] perf trace-event: Constify print arguments
Quoted 1 line · Ian Rogers
Capture that these functions don't mutate their input.
- Arnaldo
Quoted 47 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/trace-event-parse.c | 4 ++-- tools/perf/util/trace-event.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)tools/perf/util/trace-event-parse.c +2
-2@@ -99,7 +99,7 @@ unsigned long long read_size(struct tep_event *event, void *ptr, int size)return tep_read_number (event->tep, ptr, size); } -void event_format__fprintf (struct tep_event *event, +void event_format__fprintf (const struct tep_event *event,int cpu,void *data,int size,FILE *fp) {struct tep_record record;@@ -116,7 +116,7 @@ void event_format__fprintf(struct tep_event *event,trace_seq_destroy (&s); } -void event_format__print (struct tep_event *event, +void event_format__print (const struct tep_event *event,int cpu,void *data,int size) {return event_format__fprintf (event, cpu, data, size, stdout);tools/perf/util/trace-event.h +2
-2@@ -39,10 +39,10 @@ trace_event__tp_format(const char *sys, const char *name);struct tep_event *trace_event__tp_format_id (int id); -void event_format__fprintf (struct tep_event *event, +void event_format__fprintf (const struct tep_event *event,int cpu,void *data,int size,FILE *fp); -void event_format__print (struct tep_event *event, +void event_format__print (const struct tep_event *event,int cpu,void *data,int size);int parse_ftrace_file (struct tep_handle *pevent,char *buf,unsigned long size);Signature · 1 line
2.47.0.199.ga7371fff76-goog
Ian Rogers
reviewerPATCH v2 3/6 perf trace-event: Always build trace-event-info.c
In reply to Ian Rogerstrace-event-info.c has no libtraceevent depdendencies, always build it and use it in builtin-record and perf_event_attr printing.
--- tools/perf/builtin-record.c | 2 -- tools/perf/util/Build | 2 +- tools/perf/util/perf_event_attr_fprintf.c | 4 ---- 3 files changed, 1 insertion(+), 7 deletions(-)
tools/perf/builtin-record.c +0 -2
@@ -1748,10 +1748,8 @@ static void record__init_features(struct record *rec)if (rec->no_buildid)perf_header__clear_feat (&session->header,HEADER_BUILD_ID ); -#ifdef HAVE_LIBTRACEEVENT if (!have_tracepoints (&rec->evlist->core.entries))perf_header__clear_feat (&session->header,HEADER_TRACING_DATA ); -#endif if (!rec->opts.branch_stack)perf_header__clear_feat (&session->header,HEADER_BRANCH_STACK );
tools/perf/util/Build +1 -1
@@ -85,7 +85,7 @@ perf-util-y += pmu-flex.o perf-util-y += pmu-bison.o perf-util-y += tool_pmu.o perf-util-y += svghelper.o -perf-util-$(CONFIG_LIBTRACEEVENT) += trace-event-info.o +perf-util-y += trace-event-info.o perf-util-y += trace-event-scripting.o perf-util-$(CONFIG_LIBTRACEEVENT) += trace-event.o perf-util-$(CONFIG_LIBTRACEEVENT) += trace-event-parse.o
tools/perf/util/perf_event_attr_fprintf.c +0 -4
@@ -212,7 +212,6 @@ static void __p_config_hw_cache_id(char *buf, size_t size, u64 value) } } -#ifdef HAVE_LIBTRACEEVENT static void __p_config_tracepoint_id (char *buf,size_t size,u64 value) {char *str =tracepoint_id_to_name (value);
@@ -220,7 +219,6 @@ static void __p_config_tracepoint_id(char *buf, size_t size, u64 value)print_id_hex (str);free (str); } -#endif static void __p_config_id (struct perf_pmu *pmu,char *buf,size_t size,u32 type,u64 value) {
@@ -238,9 +236,7 @@ static void __p_config_id(struct perf_pmu *pmu, char *buf, size_t size, u32 typecase PERF_TYPE_HW_CACHE :return __p_config_hw_cache_id (buf, size, value);case PERF_TYPE_TRACEPOINT : -#ifdef HAVE_LIBTRACEEVENT return __p_config_tracepoint_id (buf, size, value); -#endif case PERF_TYPE_RAW :case PERF_TYPE_BREAKPOINT :default :
Signature · 1 line
2.47.0.199.ga7371fff76-goog
Re: [PATCH v2 3/6] perf trace-event: Always build trace-event-info.c
Quoted 2 lines · Ian Rogers
trace-event-info.chas no libtraceevent depdendencies, always build it and use it in builtin-record andperf_event_attrprinting.
- Arnaldo
Quoted 67 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/builtin-record.c | 2 -- tools/perf/util/Build | 2 +- tools/perf/util/perf_event_attr_fprintf.c | 4 ---- 3 files changed, 1 insertion(+), 7 deletions(-)tools/perf/builtin-record.c +0
-2@@ -1748,10 +1748,8 @@ static void record__init_features(struct record *rec)if (rec->no_buildid)perf_header__clear_feat (&session->header,HEADER_BUILD_ID ); -#ifdef HAVE_LIBTRACEEVENT if (!have_tracepoints (&rec->evlist->core.entries))perf_header__clear_feat (&session->header,HEADER_TRACING_DATA ); -#endif if (!rec->opts.branch_stack)perf_header__clear_feat (&session->header,HEADER_BRANCH_STACK );tools/perf/util/Build +1
-1@@ -85,7 +85,7 @@ perf-util-y += pmu-flex.o perf-util-y += pmu-bison.o perf-util-y += tool_pmu.o perf-util-y += svghelper.o -perf-util-$(CONFIG_LIBTRACEEVENT) += trace-event-info.o +perf-util-y += trace-event-info.o perf-util-y += trace-event-scripting.o perf-util-$(CONFIG_LIBTRACEEVENT) += trace-event.o perf-util-$(CONFIG_LIBTRACEEVENT) += trace-event-parse.otools/perf/util/perf_event_attr_fprintf.c +0
-4@@ -212,7 +212,6 @@ static void __p_config_hw_cache_id(char *buf, size_t size, u64 value) } } -#ifdef HAVE_LIBTRACEEVENT static void __p_config_tracepoint_id (char *buf,size_t size,u64 value) {char *str =tracepoint_id_to_name (value);@@ -220,7 +219,6 @@ static void __p_config_tracepoint_id(char *buf, size_t size, u64 value)print_id_hex (str);free (str); } -#endif static void __p_config_id (struct perf_pmu *pmu,char *buf,size_t size,u32 type,u64 value) {@@ -238,9 +236,7 @@ static void __p_config_id(struct perf_pmu *pmu, char *buf, size_t size, u32 typecase PERF_TYPE_HW_CACHE :return __p_config_hw_cache_id (buf, size, value);case PERF_TYPE_TRACEPOINT : -#ifdef HAVE_LIBTRACEEVENT return __p_config_tracepoint_id (buf, size, value); -#endif case PERF_TYPE_RAW :case PERF_TYPE_BREAKPOINT :default :Signature · 1 line
2.47.0.199.ga7371fff76-goog
Ian Rogers
reviewerPATCH v2 4/6 perf evsel: Add/use accessor for tp_format
In reply to Ian RogersAdd an accessor function for tp_format. Rather than search+replace uses try to use a variable and reuse it. Add additional NULL checks when accessing/using the value. Make sure the PTR_ERR is nulled out on error path in evsel__newtp_idx.
--- tools/perf/builtin-kmem.c | 15 ++-- tools/perf/builtin-kwork.c | 3 +- tools/perf/builtin-script.c | 9 ++- tools/perf/builtin-trace.c | 80 +++++++++++++------ tools/perf/util/data-convert-bt.c | 10 ++- tools/perf/util/data-convert-json.c | 8 +- tools/perf/util/evsel.c | 9 ++- tools/perf/util/evsel.h | 5 ++ tools/perf/util/evsel_fprintf.c | 4 +- .../util/scripting-engines/trace-event-perl.c | 3 +- .../scripting-engines/trace-event-python.c | 3 +- tools/perf/util/sort.c | 33 +++++--- tools/perf/util/trace-event-scripting.c | 10 ++- 13 files changed, 131 insertions(+), 61 deletions(-)
tools/perf/builtin-kmem.c +9 -6
@@ -761,6 +761,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, };struct trace_seq seq;char *str, *pos =NULL ; +const struct tep_event *tp_format;if (nr_gfps) {struct gfp_flag key = {
@@ -772,8 +773,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, }trace_seq_init (&seq); -tep_print_event (evsel->tp_format->tep, - &seq, &record,"%s" ,TEP_PRINT_INFO ); + tp_format =evsel__tp_format (evsel); +if (tp_format) +tep_print_event (tp_format->tep, &seq, &record,"%s" ,TEP_PRINT_INFO ); str =strtok_r (seq.buffer," " , &pos);while (str) {
@@ -2011,14 +2013,15 @@ int cmd_kmem(int argc, const char **argv) }if (kmem_page) { -struct evsel *evsel =evlist__find_tracepoint_by_name (session->evlist,"kmem:mm_page_alloc" ); +struct evsel *evsel =evlist__find_tracepoint_by_name (session->evlist, +"kmem:mm_page_alloc" ); +const struct tep_event *tp_format = evsel ?evsel__tp_format (evsel) :NULL ; -if (evsel ==NULL ) { +if (tp_format ==NULL ) {pr_err (errmsg,"page" ,"page" ); goto out_delete; } - - kmem_page_size =tep_get_page_size (evsel->tp_format->tep); + kmem_page_size =tep_get_page_size (tp_format->tep); symbol_conf.use_callchain = true; }
tools/perf/builtin-kwork.c +2 -1
@@ -1103,7 +1103,8 @@ static char *evsel__softirq_name(struct evsel *evsel, u64 num)char *name =NULL ;bool found = false;struct tep_print_flag_sym *sym =NULL ; -struct tep_print_arg *args = evsel->tp_format->print_fmt.args; +const struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_print_arg *args = tp_format ?evsel__tp_format (evsel)->print_fmt.args :NULL ;if ((args ==NULL ) || (args->next ==NULL ))return NULL ;
tools/perf/builtin-script.c +7 -2
@@ -2289,8 +2289,13 @@ static void process_event(struct perf_script *script, }#ifdef HAVE_LIBTRACEEVENT if (PRINT_FIELD (TRACE ) && sample->raw_data) { -event_format__fprintf (evsel->tp_format, sample->cpu, - sample->raw_data, sample->raw_size, fp); +const struct tep_event *tp_format =evsel__tp_format (evsel); + +if (tp_format) { +event_format__fprintf (tp_format, sample->cpu, + sample->raw_data, sample->raw_size, + fp); + } }#endif if (attr->type ==PERF_TYPE_SYNTH &&PRINT_FIELD (SYNTH ))
tools/perf/builtin-trace.c +57 -23
156 lines not on this page · raw message
tools/perf/util/data-convert-bt.c +6 -4
@@ -426,8 +426,9 @@ static int add_tracepoint_values(struct ctf_writer *cw,struct evsel *evsel, struct perf_sample *sample) { - struct tep_format_field *common_fields = evsel->tp_format->format.common_fields; -struct tep_format_field *fields = evsel->tp_format->format.fields; + const struct tep_event *tp_format = evsel__tp_format(evsel); +struct tep_format_field *common_fields = tp_format->format.common_fields; +struct tep_format_field *fields = tp_format->format.fields;int ret; ret = add_tracepoint_fields_values(cw, event_class, event,
@@ -1064,8 +1065,9 @@ static int add_tracepoint_types(struct ctf_writer *cw,struct evsel *evsel, struct bt_ctf_event_class *class) { - struct tep_format_field *common_fields = evsel->tp_format->format.common_fields; -struct tep_format_field *fields = evsel->tp_format->format.fields; + const struct tep_event *tp_format = evsel__tp_format(evsel); +struct tep_format_field *common_fields = tp_format ? tp_format->format.common_fields :NULL ; +struct tep_format_field *fields = tp_format ? tp_format->format.fields :NULL ;int ret; ret =add_tracepoint_fields_types (cw, common_fields, class);
tools/perf/util/data-convert-json.c +4 -4
@@ -230,12 +230,12 @@ static int process_sample_event(const struct perf_tool *tool,#ifdef HAVE_LIBTRACEEVENT if (sample->raw_data) { -int i; -struct tep_format_field **fields; +struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_format_field **fields = tp_format ?tep_event_fields (tp_format) :NULL ; - fields =tep_event_fields (evsel->tp_format);if (fields) { - i =0 ; +int i =0 ; +while (fields[i]) {struct trace_seq s;
tools/perf/util/evsel.c +7 -2
@@ -570,6 +570,7 @@ struct evsel *evsel__newtp_idx(const char *sys, const char *name, int idx, bool evsel->tp_format =trace_event__tp_format (sys, name);if (IS_ERR (evsel->tp_format)) { err =PTR_ERR (evsel->tp_format); + evsel->tp_format =NULL ; goto out_free; } attr.config = evsel->tp_format->id;
@@ -3209,12 +3210,16 @@ u16 evsel__id_hdr_size(const struct evsel *evsel)#ifdef HAVE_LIBTRACEEVENT struct tep_format_field *evsel__field (struct evsel *evsel,const char *name) { -return tep_find_field (evsel->tp_format, name); +struct tep_event *tp_format =evsel__tp_format (evsel); + +return tp_format ?tep_find_field (tp_format, name) :NULL ; }struct tep_format_field *evsel__common_field (struct evsel *evsel,const char *name) { -return tep_find_common_field (evsel->tp_format, name); +struct tep_event *tp_format =evsel__tp_format (evsel); + +return tp_format ?tep_find_common_field (tp_format, name) :NULL ; }void *evsel__rawptr (struct evsel *evsel,struct perf_sample *sample,const char *name)
tools/perf/util/evsel.h +5 -0
@@ -257,6 +257,11 @@ static inline struct evsel *evsel__newtp(const char *sys, const char *name) {return evsel__newtp_idx (sys, name,0 , true); } + +static inline struct tep_event *evsel__tp_format (struct evsel *evsel) +{ +return evsel->tp_format; +}#endif #ifdef HAVE_LIBTRACEEVENT
tools/perf/util/evsel_fprintf.c +3 -1
@@ -81,13 +81,15 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#ifdef HAVE_LIBTRACEEVENT if (details->trace_fields) {struct tep_format_field *field; +const struct tep_event *tp_format;if (evsel->core.attr.type !=PERF_TYPE_TRACEPOINT ) { printed +=comma_fprintf (fp, &first," (not a tracepoint)" ); goto out; } - field = evsel->tp_format->format.fields; + tp_format =evsel__tp_format (evsel); + field = tp_format ? tp_format->format.fields :NULL ;if (field ==NULL ) { printed +=comma_fprintf (fp, &first," (no trace field)" ); goto out;
tools/perf/util/scripting-engines/trace-event-perl.c +2 -1
@@ -344,7 +344,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, struct addr_location *al) {struct thread *thread = al->thread; -struct tep_event *event = evsel->tp_format; +struct tep_event *event;struct tep_format_field *field;static char handler[256 ];unsigned long long val;
@@ -362,6 +362,7 @@ static void perl_process_tracepoint(struct perf_sample *sample,if (evsel->core.attr.type !=PERF_TYPE_TRACEPOINT )return ; + event =evsel__tp_format (evsel);if (!event) {pr_debug ("ug! no event found for type %" PRIu64, (u64 )evsel->core.attr.config);return ;
tools/perf/util/scripting-engines/trace-event-python.c +2 -1
@@ -946,7 +946,7 @@ static void python_process_tracepoint(struct perf_sample *sample,struct addr_location *al, struct addr_location *addr_al) { - struct tep_event *event = evsel->tp_format; + struct tep_event *event;PyObject *handler, *context, *t, *obj =NULL , *callchain;PyObject *dict =NULL , *all_entries_dict =NULL ;static char handler_name[256 ];
@@ -963,6 +963,7 @@ static void python_process_tracepoint(struct perf_sample *sample,bitmap_zero (events_defined,TRACE_EVENT_TYPE_MAX ); + event =evsel__tp_format (evsel);if (!event) {snprintf (handler_name,sizeof (handler_name),"ug! no event found for type %" PRIu64, (u64 )evsel->core.attr.config);
tools/perf/util/sort.c +21 -12
@@ -1038,17 +1038,19 @@ static char *get_trace_output(struct hist_entry *he) .data = he->raw_data, .size = he->raw_size, }; +struct tep_event *tp_format; evsel =hists_to_evsel (he->hists);trace_seq_init (&seq); -if (symbol_conf.raw_trace) { -tep_print_fields (&seq, he->raw_data, he->raw_size, - evsel->tp_format); - }else { -tep_print_event (evsel->tp_format->tep, - &seq, &rec,"%s" ,TEP_PRINT_INFO ); + tp_format =evsel__tp_format (evsel); +if (tp_format) { +if (symbol_conf.raw_trace) +tep_print_fields (&seq, he->raw_data, he->raw_size, tp_format); +else +tep_print_event (tp_format->tep, &seq, &rec,"%s" ,TEP_PRINT_INFO ); } +/* * Trim the buffer, it starts at 4KB and we're not going to * add anything more to this buffer.
@@ -3293,9 +3295,8 @@ static int __dynamic_dimension__add(struct evsel *evsel,static int add_evsel_fields (struct evsel *evsel,bool raw_trace,int level) {int ret; -struct tep_format_field *field; - - field = evsel->tp_format->format.fields; +struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_format_field *field = tp_format ? tp_format->format.fields :NULL ;while (field) { ret =__dynamic_dimension__add (evsel, field, raw_trace, level);if (ret <0 )
@@ -3328,13 +3329,19 @@ static int add_all_matching_fields(struct evlist *evlist, {int ret = -ESRCH ;struct evsel *evsel; -struct tep_format_field *field;evlist__for_each_entry (evlist, evsel) { +struct tep_event *tp_format; +struct tep_format_field *field; +if (evsel->core.attr.type !=PERF_TYPE_TRACEPOINT )continue ; - field =tep_find_any_field (evsel->tp_format, field_name); + tp_format =evsel__tp_format (evsel); +if (tp_format ==NULL ) +continue ; + + field =tep_find_any_field (tp_format, field_name);if (field ==NULL )continue ;
@@ -3416,7 +3423,9 @@ static int add_dynamic_entry(struct evlist *evlist, const char *tok,if (!strcmp (field_name,"*" )) { ret =add_evsel_fields (evsel, raw_trace, level); }else { -struct tep_format_field *field =tep_find_any_field (evsel->tp_format, field_name); +struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_format_field *field = + tp_format ?tep_find_any_field (tp_format, field_name) :NULL ;if (field ==NULL ) { pr_debug("Cannot find event field for %s.%s\n",
tools/perf/util/trace-event-scripting.c +6 -4
@@ -28,12 +28,14 @@ void scripting_context__update(struct scripting_context *c,struct addr_location *al, struct addr_location *addr_al) { - c->event_data = sample->raw_data; - c->pevent =NULL ; #ifdef HAVE_LIBTRACEEVENT -if (evsel->tp_format) - c->pevent = evsel->tp_format->tep; + const struct tep_event *tp_format = evsel__tp_format(evsel); + + c->pevent = tp_format ? tp_format->tep :NULL ; +#else + c->pevent =NULL ;#endif + c->event_data = sample->raw_data; c->event = event; c->sample = sample; c->evsel = evsel;
Signature · 1 line
2.47.0.199.ga7371fff76-goog
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2 4/6] perf evsel: Add/use accessor for tp_format
Quoted 47 lines · Ian Rogers
Add an accessor function for
tp_format. Rather than search+replace uses try to use a variable and reuse it. Add additional NULL checks when accessing/using the value. Make sure thePTR_ERRis nulled out on error path inevsel__newtp_idx.Signed-off-by Ian Rogers <[email protected]>--- tools/perf/builtin-kmem.c | 15 ++-- tools/perf/builtin-kwork.c | 3 +- tools/perf/builtin-script.c | 9 ++- tools/perf/builtin-trace.c | 80 +++++++++++++------ tools/perf/util/data-convert-bt.c | 10 ++- tools/perf/util/data-convert-json.c | 8 +- tools/perf/util/evsel.c | 9 ++- tools/perf/util/evsel.h | 5 ++ tools/perf/util/evsel_fprintf.c | 4 +- .../util/scripting-engines/trace-event-perl.c | 3 +- .../scripting-engines/trace-event-python.c | 3 +- tools/perf/util/sort.c | 33 +++++--- tools/perf/util/trace-event-scripting.c | 10 ++- 13 files changed, 131 insertions(+), 61 deletions(-)tools/perf/builtin-kmem.c +4
-2@@ -761,6 +761,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, };struct trace_seq seq;char *str, *pos =NULL ; +const struct tep_event *tp_format;if (nr_gfps) {struct gfp_flag key = {@@ -772,8 +773,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, }trace_seq_init (&seq); -tep_print_event (evsel->tp_format->tep, - &seq, &record,"%s" ,TEP_PRINT_INFO ); + tp_format =evsel__tp_format (evsel); +if (tp_format) +tep_print_event (tp_format->tep, &seq, &record,"%s" ,TEP_PRINT_INFO ); str =strtok_r (seq.buffer," " , &pos);while (str) {
tools/perf/builtin-kmem.c int cmd_kmem(int argc, const char **argv) · line 2017
Quoted 6 lines
tools/perf/builtin-kmem.c +2
-1@@ -2011,14 +2013,15 @@ int cmd_kmem(int argc, const char **argv) }if (kmem_page) { -struct evsel *evsel =evlist__find_tracepoint_by_name (session->evlist,"kmem:mm_page_alloc" ); +struct evsel *evsel =evlist__find_tracepoint_by_name (session->evlist, +"kmem:mm_page_alloc" );
Try to avoid these reflows to reduce patch size, please.
Quoted 18 lines
tools/perf/builtin-kmem.c +3
-3+const struct tep_event *tp_format = evsel ?evsel__tp_format (evsel) :NULL ; -if (evsel ==NULL ) { +if (tp_format ==NULL ) {pr_err (errmsg,"page" ,"page" ); goto out_delete; } - - kmem_page_size =tep_get_page_size (evsel->tp_format->tep); + kmem_page_size =tep_get_page_size (tp_format->tep); symbol_conf.use_callchain = true; }tools/perf/builtin-kwork.c +0
-0
tools/perf/builtin-kwork.c static char *evsel__softirq_name(struct evsel *evsel, u64 num) · line 1107
Quoted 6 lines
tools/perf/builtin-kwork.c +2
-1@@ -1103,7 +1103,8 @@ static char *evsel__softirq_name(struct evsel *evsel, u64 num)char *name =NULL ;bool found = false;struct tep_print_flag_sym *sym =NULL ; -struct tep_print_arg *args = evsel->tp_format->print_fmt.args; +const struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_print_arg *args = tp_format ?evsel__tp_format (evsel)->print_fmt.args :NULL ;
why not use tp_format, i.e.:
struct tep_print_arg *args = tp_format ? tp_format->print_fmt.args : NULL;
Quoted 67 lines
tools/perf/builtin-kwork.c +0
-0if ((args ==NULL ) || (args->next ==NULL ))return NULL ;tools/perf/builtin-script.c +7
-2@@ -2289,8 +2289,13 @@ static void process_event(struct perf_script *script, }#ifdef HAVE_LIBTRACEEVENT if (PRINT_FIELD (TRACE ) && sample->raw_data) { -event_format__fprintf (evsel->tp_format, sample->cpu, - sample->raw_data, sample->raw_size, fp); +const struct tep_event *tp_format =evsel__tp_format (evsel); + +if (tp_format) { +event_format__fprintf (tp_format, sample->cpu, + sample->raw_data, sample->raw_size, + fp); + } }#endif if (attr->type ==PERF_TYPE_SYNTH &&PRINT_FIELD (SYNTH ))tools/perf/builtin-trace.c +14
-4@@ -389,7 +389,12 @@ static struct syscall_arg_fmt *evsel__syscall_arg_fmt(struct evsel *evsel) }if (et->fmt ==NULL ) { - et->fmt =calloc (evsel->tp_format->format.nr_fields,sizeof (struct syscall_arg_fmt )); +const struct tep_event *tp_format =evsel__tp_format (evsel); + +if (tp_format ==NULL ) + goto out_delete; + + et->fmt =calloc (tp_format->format.nr_fields,sizeof (struct syscall_arg_fmt ));if (et->fmt ==NULL ) goto out_delete; }@@ -2154,8 +2159,12 @@ static int evsel__init_tp_arg_scnprintf(struct evsel *evsel, bool *use_btf)struct syscall_arg_fmt *fmt =evsel__syscall_arg_fmt (evsel);if (fmt !=NULL ) { -syscall_arg_fmt__init_array (fmt, evsel->tp_format->format.fields, use_btf); -return 0 ; +const struct tep_event *tp_format =evsel__tp_format (evsel); + +if (tp_format) { +syscall_arg_fmt__init_array (fmt, tp_format->format.fields, use_btf); +return 0 ; + } }return -ENOMEM ;@@ -3026,7 +3035,8 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, {char bf[2048 ];size_t size =sizeof (bf); -struct tep_format_field *field = evsel->tp_format->format.fields; +const struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_format_field *field = tp_format ? tp_format->format.fields :NULL ;struct syscall_arg_fmt *arg =__evsel__syscall_arg_fmt (evsel);size_t printed =0 , btf_printed;unsigned long val;
tools/perf/builtin-trace.c static int trace__event_handler(struct trace *trace, struct evsel *evsel, · line 3109
Quoted 4 lines
tools/perf/builtin-trace.c +1
-0@@ -3096,6 +3106,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, {struct thread *thread;int callchain_ret =0 ; +
?
Quoted 30 lines
tools/perf/builtin-trace.c +9
-5/* * Check if we called perf_evsel__disable(evsel) due to, for instance, * this event's max_events having been hit and this is an entry coming @@ -3149,11 +3160,13 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,if (evsel__is_bpf_output (evsel)) {bpf_output__fprintf (trace, sample); - }else if (evsel->tp_format) { -if (strncmp (evsel->tp_format->name,"sys_enter_" ,10 ) || -trace__fprintf_sys_enter (trace, evsel, sample)) { + }else { +const struct tep_event *tp_format =evsel__tp_format (evsel); + +if (tp_format && (strncmp (tp_format->name,"sys_enter_" ,10 ) || +trace__fprintf_sys_enter (trace, evsel, sample))) {if (trace->libtraceevent_print) { -event_format__fprintf (evsel->tp_format, sample->cpu, +event_format__fprintf (tp_format, sample->cpu, sample->raw_data, sample->raw_size, trace->output); }else {@@ -4081,17 +4094,23 @@ static int ordered_events__deliver_event(struct ordered_events *oe,static struct syscall_arg_fmt *evsel__find_syscall_arg_fmt_by_name (struct evsel *evsel,char *arg,char **type) { -struct tep_format_field *field; +const struct tep_format_field *field;struct syscall_arg_fmt *fmt =__evsel__syscall_arg_fmt (evsel); +const struct tep_event *tp_format; +
tools/perf/builtin-trace.c static int ordered_events__deliver_event(struct ordered_events *oe, · line 4108
Quoted 10 lines
tools/perf/builtin-trace.c +5
-2+if (!fmt) +return NULL ; -if (evsel->tp_format ==NULL || fmt ==NULL ) + tp_format =evsel__tp_format (evsel); +if (!tp_format)return NULL ; -for (field = evsel->tp_format->format.fields; field; field = field->next, ++fmt) +for (field = tp_format->format.fields; field; field = field->next, ++fmt) {
Since you're touching above and constifying the 'field' variable, probably you could make it:
for (const struct tep_format_field *field = tp_format->format.fields; field; field = field->next, ++fmt) {?
Just tried this on top of your series, it builds:
tools/perf/builtin-trace.c +1 -2
@@ -4094,7 +4094,6 @@ static int ordered_events__deliver_event(struct ordered_events *oe,static struct syscall_arg_fmt *evsel__find_syscall_arg_fmt_by_name (struct evsel *evsel,char *arg,char **type) { -const struct tep_format_field *field;struct syscall_arg_fmt *fmt =__evsel__syscall_arg_fmt (evsel);const struct tep_event *tp_format;
@@ -4105,7 +4104,7 @@ static struct syscall_arg_fmt *evsel__find_syscall_arg_fmt_by_name(struct evselif (!tp_format)return NULL ; -for (field = tp_format->format.fields; field; field = field->next, ++fmt) { +for (const struct tep_format_field *field= tp_format->format.fields; field; field = field->next, ++fmt) {if (strcmp (field->name, arg) ==0 ) { *type = field->type;return fmt;
------------------------------------------------------------
Quoted 68 lines
tools/perf/builtin-trace.c +23
-10if (strcmp (field->name, arg) ==0 ) { *type = field->type;return fmt; } + }return NULL ; }@@ -4844,13 +4863,18 @@ static void evsel__set_syscall_arg_fmt(struct evsel *evsel, const char *name)const struct syscall_fmt *scfmt =syscall_fmt__find (name);if (scfmt) { -int skip =0 ; +const struct tep_event *tp_format =evsel__tp_format (evsel); + +if (tp_format) { +int skip =0 ; -if (strcmp (evsel->tp_format->format.fields->name,"__syscall_nr" ) ==0 || -strcmp (evsel->tp_format->format.fields->name,"nr" ) ==0 ) - ++skip; +if (strcmp (tp_format->format.fields->name,"__syscall_nr" ) ==0 || +strcmp (tp_format->format.fields->name,"nr" ) ==0 ) + ++skip; -memcpy (fmt + skip, scfmt->arg, (evsel->tp_format->format.nr_fields - skip) *sizeof (*fmt)); +memcpy (fmt + skip, scfmt->arg, + (tp_format->format.nr_fields - skip) *sizeof (*fmt)); + } } } }@@ -4860,10 +4884,16 @@ static int evlist__set_syscall_tp_fields(struct evlist *evlist, bool *use_btf)struct evsel *evsel;evlist__for_each_entry (evlist, evsel) { -if (evsel->priv || !evsel->tp_format) +const struct tep_event *tp_format; + +if (evsel->priv) +continue ; + + tp_format =evsel__tp_format (evsel); +if (!tp_format)continue ; -if (strcmp (evsel->tp_format->system,"syscalls" )) { +if (strcmp (tp_format->system,"syscalls" )) {evsel__init_tp_arg_scnprintf (evsel, use_btf);continue ; }@@ -4871,20 +4901,24 @@ static int evlist__set_syscall_tp_fields(struct evlist *evlist, bool *use_btf)if (evsel__init_syscall_tp (evsel))return -1 ; -if (!strncmp (evsel->tp_format->name,"sys_enter_" ,10 )) { +if (!strncmp (tp_format->name,"sys_enter_" ,10 )) {struct syscall_tp *sc =__evsel__syscall_tp (evsel);if (__tp_field__init_ptr (&sc->args, sc->id.offset +sizeof (u64)))return -1 ; -evsel__set_syscall_arg_fmt (evsel, evsel->tp_format->name +sizeof ("sys_enter_" ) -1 ); - }else if (!strncmp (evsel->tp_format->name,"sys_exit_" ,9 )) { +evsel__set_syscall_arg_fmt (evsel, + tp_format->name +sizeof ("sys_enter_" ) -1 ); + }else if (!strncmp (tp_format->name,"sys_exit_" ,9 )) {struct syscall_tp *sc =__evsel__syscall_tp (evsel);
tools/perf/builtin-trace.c static int evlist__set_syscall_tp_fields(struct evlist *evlist, bool *use_btf) · line 4921
Quoted 10 lines
tools/perf/builtin-trace.c +5
-2-if (__tp_field__init_uint (&sc->ret,sizeof (u64), sc->id.offset +sizeof (u64), evsel->needs_swap)) +if (__tp_field__init_uint (&sc->ret,sizeof (u64), + sc->id.offset +sizeof (u64), + evsel->needs_swap))return -1 ; -evsel__set_syscall_arg_fmt (evsel, evsel->tp_format->name +sizeof ("sys_exit_" ) -1 ); +evsel__set_syscall_arg_fmt (evsel, + tp_format->name +sizeof ("sys_exit_" ) -1 );
If you left it as
- evsel__set_syscall_arg_fmt(evsel, evsel->tp_format->name + sizeof("sys_exit_") - 1);
+ evsel__set_syscall_arg_fmt(evsel, tp_format->name + sizeof("sys_exit_") - 1);
It would be shorter than before and slightly faster to visually decode.
Quoted 262 lines
tools/perf/builtin-trace.c +0
-0} }tools/perf/util/data-convert-bt.c +6
-4@@ -426,8 +426,9 @@ static int add_tracepoint_values(struct ctf_writer *cw,struct evsel *evsel, struct perf_sample *sample) { - struct tep_format_field *common_fields = evsel->tp_format->format.common_fields; -struct tep_format_field *fields = evsel->tp_format->format.fields; + const struct tep_event *tp_format = evsel__tp_format(evsel); +struct tep_format_field *common_fields = tp_format->format.common_fields; +struct tep_format_field *fields = tp_format->format.fields;int ret; ret = add_tracepoint_fields_values(cw, event_class, event,@@ -1064,8 +1065,9 @@ static int add_tracepoint_types(struct ctf_writer *cw,struct evsel *evsel, struct bt_ctf_event_class *class) { - struct tep_format_field *common_fields = evsel->tp_format->format.common_fields; -struct tep_format_field *fields = evsel->tp_format->format.fields; + const struct tep_event *tp_format = evsel__tp_format(evsel); +struct tep_format_field *common_fields = tp_format ? tp_format->format.common_fields :NULL ; +struct tep_format_field *fields = tp_format ? tp_format->format.fields :NULL ;int ret; ret =add_tracepoint_fields_types (cw, common_fields, class);tools/perf/util/data-convert-json.c +4
-4@@ -230,12 +230,12 @@ static int process_sample_event(const struct perf_tool *tool,#ifdef HAVE_LIBTRACEEVENT if (sample->raw_data) { -int i; -struct tep_format_field **fields; +struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_format_field **fields = tp_format ?tep_event_fields (tp_format) :NULL ; - fields =tep_event_fields (evsel->tp_format);if (fields) { - i =0 ; +int i =0 ; +while (fields[i]) {struct trace_seq s;tools/perf/util/evsel.c +7
-2@@ -570,6 +570,7 @@ struct evsel *evsel__newtp_idx(const char *sys, const char *name, int idx, bool evsel->tp_format =trace_event__tp_format (sys, name);if (IS_ERR (evsel->tp_format)) { err =PTR_ERR (evsel->tp_format); + evsel->tp_format =NULL ; goto out_free; } attr.config = evsel->tp_format->id;@@ -3209,12 +3210,16 @@ u16 evsel__id_hdr_size(const struct evsel *evsel)#ifdef HAVE_LIBTRACEEVENT struct tep_format_field *evsel__field (struct evsel *evsel,const char *name) { -return tep_find_field (evsel->tp_format, name); +struct tep_event *tp_format =evsel__tp_format (evsel); + +return tp_format ?tep_find_field (tp_format, name) :NULL ; }struct tep_format_field *evsel__common_field (struct evsel *evsel,const char *name) { -return tep_find_common_field (evsel->tp_format, name); +struct tep_event *tp_format =evsel__tp_format (evsel); + +return tp_format ?tep_find_common_field (tp_format, name) :NULL ; }void *evsel__rawptr (struct evsel *evsel,struct perf_sample *sample,const char *name)tools/perf/util/evsel.h +5
-0@@ -257,6 +257,11 @@ static inline struct evsel *evsel__newtp(const char *sys, const char *name) {return evsel__newtp_idx (sys, name,0 , true); } + +static inline struct tep_event *evsel__tp_format (struct evsel *evsel) +{ +return evsel->tp_format; +}#endif #ifdef HAVE_LIBTRACEEVENT tools/perf/util/evsel_fprintf.c +3
-1@@ -81,13 +81,15 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#ifdef HAVE_LIBTRACEEVENT if (details->trace_fields) {struct tep_format_field *field; +const struct tep_event *tp_format;if (evsel->core.attr.type !=PERF_TYPE_TRACEPOINT ) { printed +=comma_fprintf (fp, &first," (not a tracepoint)" ); goto out; } - field = evsel->tp_format->format.fields; + tp_format =evsel__tp_format (evsel); + field = tp_format ? tp_format->format.fields :NULL ;if (field ==NULL ) { printed +=comma_fprintf (fp, &first," (no trace field)" ); goto out;tools/perf/util/scripting-engines/trace-event-perl.c +2
-1@@ -344,7 +344,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, struct addr_location *al) {struct thread *thread = al->thread; -struct tep_event *event = evsel->tp_format; +struct tep_event *event;struct tep_format_field *field;static char handler[256 ];unsigned long long val;@@ -362,6 +362,7 @@ static void perl_process_tracepoint(struct perf_sample *sample,if (evsel->core.attr.type !=PERF_TYPE_TRACEPOINT )return ; + event =evsel__tp_format (evsel);if (!event) {pr_debug ("ug! no event found for type %" PRIu64, (u64 )evsel->core.attr.config);return ;tools/perf/util/scripting-engines/trace-event-python.c +2
-1@@ -946,7 +946,7 @@ static void python_process_tracepoint(struct perf_sample *sample,struct addr_location *al, struct addr_location *addr_al) { - struct tep_event *event = evsel->tp_format; + struct tep_event *event;PyObject *handler, *context, *t, *obj =NULL , *callchain;PyObject *dict =NULL , *all_entries_dict =NULL ;static char handler_name[256 ];@@ -963,6 +963,7 @@ static void python_process_tracepoint(struct perf_sample *sample,bitmap_zero (events_defined,TRACE_EVENT_TYPE_MAX ); + event =evsel__tp_format (evsel);if (!event) {snprintf (handler_name,sizeof (handler_name),"ug! no event found for type %" PRIu64, (u64 )evsel->core.attr.config);tools/perf/util/sort.c +21
-12@@ -1038,17 +1038,19 @@ static char *get_trace_output(struct hist_entry *he) .data = he->raw_data, .size = he->raw_size, }; +struct tep_event *tp_format; evsel =hists_to_evsel (he->hists);trace_seq_init (&seq); -if (symbol_conf.raw_trace) { -tep_print_fields (&seq, he->raw_data, he->raw_size, - evsel->tp_format); - }else { -tep_print_event (evsel->tp_format->tep, - &seq, &rec,"%s" ,TEP_PRINT_INFO ); + tp_format =evsel__tp_format (evsel); +if (tp_format) { +if (symbol_conf.raw_trace) +tep_print_fields (&seq, he->raw_data, he->raw_size, tp_format); +else +tep_print_event (tp_format->tep, &seq, &rec,"%s" ,TEP_PRINT_INFO ); } +/* * Trim the buffer, it starts at 4KB and we're not going to * add anything more to this buffer. @@ -3293,9 +3295,8 @@ static int __dynamic_dimension__add(struct evsel *evsel,static int add_evsel_fields (struct evsel *evsel,bool raw_trace,int level) {int ret; -struct tep_format_field *field; - - field = evsel->tp_format->format.fields; +struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_format_field *field = tp_format ? tp_format->format.fields :NULL ;while (field) { ret =__dynamic_dimension__add (evsel, field, raw_trace, level);if (ret <0 )@@ -3328,13 +3329,19 @@ static int add_all_matching_fields(struct evlist *evlist, {int ret = -ESRCH ;struct evsel *evsel; -struct tep_format_field *field;evlist__for_each_entry (evlist, evsel) { +struct tep_event *tp_format; +struct tep_format_field *field; +if (evsel->core.attr.type !=PERF_TYPE_TRACEPOINT )continue ; - field =tep_find_any_field (evsel->tp_format, field_name); + tp_format =evsel__tp_format (evsel); +if (tp_format ==NULL ) +continue ; + + field =tep_find_any_field (tp_format, field_name);if (field ==NULL )continue ;@@ -3416,7 +3423,9 @@ static int add_dynamic_entry(struct evlist *evlist, const char *tok,if (!strcmp (field_name,"*" )) { ret =add_evsel_fields (evsel, raw_trace, level); }else { -struct tep_format_field *field =tep_find_any_field (evsel->tp_format, field_name); +struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_format_field *field = + tp_format ?tep_find_any_field (tp_format, field_name) :NULL ;if (field ==NULL ) { pr_debug("Cannot find event field for %s.%s\n",tools/perf/util/trace-event-scripting.c +6
-4@@ -28,12 +28,14 @@ void scripting_context__update(struct scripting_context *c,struct addr_location *al, struct addr_location *addr_al) { - c->event_data = sample->raw_data; - c->pevent =NULL ; #ifdef HAVE_LIBTRACEEVENT -if (evsel->tp_format) - c->pevent = evsel->tp_format->tep; + const struct tep_event *tp_format = evsel__tp_format(evsel); + + c->pevent = tp_format ? tp_format->tep :NULL ; +#else + c->pevent =NULL ;#endif + c->event_data = sample->raw_data; c->event = event; c->sample = sample; c->evsel = evsel;Signature · 1 line
2.47.0.199.ga7371fff76-goog
Ian Rogers
reviewerRe: [PATCH v2 4/6] perf evsel: Add/use accessor for tp_format
Quoted 51 lines · Arnaldo Carvalho de Melo
Quoted 49 lines · Ian Rogers
Add an accessor function for
tp_format. Rather than search+replace uses try to use a variable and reuse it. Add additional NULL checks when accessing/using the value. Make sure thePTR_ERRis nulled out on error path inevsel__newtp_idx.Signed-off-by Ian Rogers <[email protected]>--- tools/perf/builtin-kmem.c | 15 ++-- tools/perf/builtin-kwork.c | 3 +- tools/perf/builtin-script.c | 9 ++- tools/perf/builtin-trace.c | 80 +++++++++++++------ tools/perf/util/data-convert-bt.c | 10 ++- tools/perf/util/data-convert-json.c | 8 +- tools/perf/util/evsel.c | 9 ++- tools/perf/util/evsel.h | 5 ++ tools/perf/util/evsel_fprintf.c | 4 +- .../util/scripting-engines/trace-event-perl.c | 3 +- .../scripting-engines/trace-event-python.c | 3 +- tools/perf/util/sort.c | 33 +++++--- tools/perf/util/trace-event-scripting.c | 10 ++- 13 files changed, 131 insertions(+), 61 deletions(-)tools/perf/builtin-kmem.c +4
-2@@ -761,6 +761,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, };struct trace_seq seq;char *str, *pos =NULL ; +const struct tep_event *tp_format;if (nr_gfps) {struct gfp_flag key = {@@ -772,8 +773,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, }trace_seq_init (&seq); -tep_print_event (evsel->tp_format->tep, - &seq, &record,"%s" ,TEP_PRINT_INFO ); + tp_format =evsel__tp_format (evsel); +if (tp_format) +tep_print_event (tp_format->tep, &seq, &record,"%s" ,TEP_PRINT_INFO ); str =strtok_r (seq.buffer," " , &pos);while (str) {@@ -2011,14 +2013,15 @@ int cmd_kmem(int argc, const char **argv) }
Quoted 6 lines
tools/perf/builtin-kmem.c int cmd_kmem(int argc, const char **argv) · line 2017
Quoted 4 lines
tools/perf/builtin-kmem.c +2
-1if (kmem_page) { -struct evsel *evsel =evlist__find_tracepoint_by_name (session->evlist,"kmem:mm_page_alloc" ); +struct evsel *evsel =evlist__find_tracepoint_by_name (session->evlist, +"kmem:mm_page_alloc" );Try to avoid these reflows to reduce patch size, please.
Agreed, in this case check checkpatch.pl is complaining that the line length is 109 columns.
Quoted 94 lines
Quoted 18 lines
tools/perf/builtin-kmem.c +3
-3+const struct tep_event *tp_format = evsel ?evsel__tp_format (evsel) :NULL ; -if (evsel ==NULL ) { +if (tp_format ==NULL ) {pr_err (errmsg,"page" ,"page" ); goto out_delete; } - - kmem_page_size =tep_get_page_size (evsel->tp_format->tep); + kmem_page_size =tep_get_page_size (tp_format->tep); symbol_conf.use_callchain = true; }tools/perf/builtin-kwork.c +0
-0tools/perf/builtin-kwork.c static char *evsel__softirq_name(struct evsel *evsel, u64 num) · line 1107
Quoted 6 lines
tools/perf/builtin-kwork.c +2
-1@@ -1103,7 +1103,8 @@ static char *evsel__softirq_name(struct evsel *evsel, u64 num)char *name =NULL ;bool found = false;struct tep_print_flag_sym *sym =NULL ; -struct tep_print_arg *args = evsel->tp_format->print_fmt.args; +const struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_print_arg *args = tp_format ?evsel__tp_format (evsel)->print_fmt.args :NULL ;why not use
tp_format, i.e.:struct
tep_print_arg*args =tp_format?tp_format->print_fmt.args: NULL;Quoted 65 lines
tools/perf/builtin-kwork.c +0
-0if ((args ==NULL ) || (args->next ==NULL ))return NULL ;tools/perf/builtin-script.c +7
-2@@ -2289,8 +2289,13 @@ static void process_event(struct perf_script *script, }#ifdef HAVE_LIBTRACEEVENT if (PRINT_FIELD (TRACE ) && sample->raw_data) { -event_format__fprintf (evsel->tp_format, sample->cpu, - sample->raw_data, sample->raw_size, fp); +const struct tep_event *tp_format =evsel__tp_format (evsel); + +if (tp_format) { +event_format__fprintf (tp_format, sample->cpu, + sample->raw_data, sample->raw_size, + fp); + } }#endif if (attr->type ==PERF_TYPE_SYNTH &&PRINT_FIELD (SYNTH ))tools/perf/builtin-trace.c +14
-4@@ -389,7 +389,12 @@ static struct syscall_arg_fmt *evsel__syscall_arg_fmt(struct evsel *evsel) }if (et->fmt ==NULL ) { - et->fmt =calloc (evsel->tp_format->format.nr_fields,sizeof (struct syscall_arg_fmt )); +const struct tep_event *tp_format =evsel__tp_format (evsel); + +if (tp_format ==NULL ) + goto out_delete; + + et->fmt =calloc (tp_format->format.nr_fields,sizeof (struct syscall_arg_fmt ));if (et->fmt ==NULL ) goto out_delete; }@@ -2154,8 +2159,12 @@ static int evsel__init_tp_arg_scnprintf(struct evsel *evsel, bool *use_btf)struct syscall_arg_fmt *fmt =evsel__syscall_arg_fmt (evsel);if (fmt !=NULL ) { -syscall_arg_fmt__init_array (fmt, evsel->tp_format->format.fields, use_btf); -return 0 ; +const struct tep_event *tp_format =evsel__tp_format (evsel); + +if (tp_format) { +syscall_arg_fmt__init_array (fmt, tp_format->format.fields, use_btf); +return 0 ; + } }return -ENOMEM ;@@ -3026,7 +3035,8 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, {char bf[2048 ];size_t size =sizeof (bf); -struct tep_format_field *field = evsel->tp_format->format.fields; +const struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_format_field *field = tp_format ? tp_format->format.fields :NULL ;struct syscall_arg_fmt *arg =__evsel__syscall_arg_fmt (evsel);size_t printed =0 , btf_printed;
Quoted 8 lines
tools/perf/builtin-trace.c static int trace__event_handler(struct trace *trace, struct evsel *evsel, · line 3109
Quoted 6 lines
tools/perf/builtin-trace.c +1
-0unsigned long val;@@ -3096,6 +3106,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel, {struct thread *thread;int callchain_ret =0 ; +?
Removed, checkpatch.pl again iirc.
Quoted 64 lines
Quoted 30 lines
tools/perf/builtin-trace.c +9
-5/* * Check if we called perf_evsel__disable(evsel) due to, for instance, * this event's max_events having been hit and this is an entry coming @@ -3149,11 +3160,13 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,if (evsel__is_bpf_output (evsel)) {bpf_output__fprintf (trace, sample); - }else if (evsel->tp_format) { -if (strncmp (evsel->tp_format->name,"sys_enter_" ,10 ) || -trace__fprintf_sys_enter (trace, evsel, sample)) { + }else { +const struct tep_event *tp_format =evsel__tp_format (evsel); + +if (tp_format && (strncmp (tp_format->name,"sys_enter_" ,10 ) || +trace__fprintf_sys_enter (trace, evsel, sample))) {if (trace->libtraceevent_print) { -event_format__fprintf (evsel->tp_format, sample->cpu, +event_format__fprintf (tp_format, sample->cpu, sample->raw_data, sample->raw_size, trace->output); }else {@@ -4081,17 +4094,23 @@ static int ordered_events__deliver_event(struct ordered_events *oe,static struct syscall_arg_fmt *evsel__find_syscall_arg_fmt_by_name (struct evsel *evsel,char *arg,char **type) { -struct tep_format_field *field; +const struct tep_format_field *field;struct syscall_arg_fmt *fmt =__evsel__syscall_arg_fmt (evsel); +const struct tep_event *tp_format; +tools/perf/builtin-trace.c static int ordered_events__deliver_event(struct ordered_events *oe, · line 4108
Quoted 10 lines
tools/perf/builtin-trace.c +5
-2+if (!fmt) +return NULL ; -if (evsel->tp_format ==NULL || fmt ==NULL ) + tp_format =evsel__tp_format (evsel); +if (!tp_format)return NULL ; -for (field = evsel->tp_format->format.fields; field; field = field->next, ++fmt) +for (field = tp_format->format.fields; field; field = field->next, ++fmt) {Since you're touching above and constifying the 'field' variable, probably you could make it:
for (const struct tep_format_field *field = tp_format->format.fields; field; field = field->next, ++fmt) {?
Just tried this on top of your series, it builds:
tools/perf/builtin-trace.c +0
-1@@ -4094,7 +4094,6 @@ static int ordered_events__deliver_event(struct ordered_events *oe,static struct syscall_arg_fmt *evsel__find_syscall_arg_fmt_by_name (struct evsel *evsel,char *arg,char **type) { -const struct tep_format_field *field;struct syscall_arg_fmt *fmt =__evsel__syscall_arg_fmt (evsel);const struct tep_event *tp_format;
tools/perf/builtin-trace.c static struct syscall_arg_fmt *evsel__find_syscall_arg_fmt_by_name(struct evsel · line 4107
Quoted 5 lines
tools/perf/builtin-trace.c +1
-1@@ -4105,7 +4104,7 @@ static struct syscall_arg_fmt *evsel__find_syscall_arg_fmt_by_name(struct evselif (!tp_format)return NULL ; -for (field = tp_format->format.fields; field; field = field->next, ++fmt) { +for (const struct tep_format_field *field= tp_format->format.fields; field; field = field->next, ++fmt) {
This is 114 columns long, so I've applied it but wrapped it.
Quoted 90 lines
tools/perf/builtin-trace.c +0
-1if (strcmp (field->name, arg) ==0 ) { *type = field->type;return fmt; ------------------------------------------------------------Quoted 69 lines
tools/perf/builtin-trace.c +23
-10if (strcmp (field->name, arg) ==0 ) { *type = field->type;return fmt; } + }return NULL ; }@@ -4844,13 +4863,18 @@ static void evsel__set_syscall_arg_fmt(struct evsel *evsel, const char *name)const struct syscall_fmt *scfmt =syscall_fmt__find (name);if (scfmt) { -int skip =0 ; +const struct tep_event *tp_format =evsel__tp_format (evsel); + +if (tp_format) { +int skip =0 ; -if (strcmp (evsel->tp_format->format.fields->name,"__syscall_nr" ) ==0 || -strcmp (evsel->tp_format->format.fields->name,"nr" ) ==0 ) - ++skip; +if (strcmp (tp_format->format.fields->name,"__syscall_nr" ) ==0 || +strcmp (tp_format->format.fields->name,"nr" ) ==0 ) + ++skip; -memcpy (fmt + skip, scfmt->arg, (evsel->tp_format->format.nr_fields - skip) *sizeof (*fmt)); +memcpy (fmt + skip, scfmt->arg, + (tp_format->format.nr_fields - skip) *sizeof (*fmt)); + } } } }@@ -4860,10 +4884,16 @@ static int evlist__set_syscall_tp_fields(struct evlist *evlist, bool *use_btf)struct evsel *evsel;evlist__for_each_entry (evlist, evsel) { -if (evsel->priv || !evsel->tp_format) +const struct tep_event *tp_format; + +if (evsel->priv) +continue ; + + tp_format =evsel__tp_format (evsel); +if (!tp_format)continue ; -if (strcmp (evsel->tp_format->system,"syscalls" )) { +if (strcmp (tp_format->system,"syscalls" )) {evsel__init_tp_arg_scnprintf (evsel, use_btf);continue ; }@@ -4871,20 +4901,24 @@ static int evlist__set_syscall_tp_fields(struct evlist *evlist, bool *use_btf)if (evsel__init_syscall_tp (evsel))return -1 ; -if (!strncmp (evsel->tp_format->name,"sys_enter_" ,10 )) { +if (!strncmp (tp_format->name,"sys_enter_" ,10 )) {struct syscall_tp *sc =__evsel__syscall_tp (evsel);if (__tp_field__init_ptr (&sc->args, sc->id.offset +sizeof (u64)))return -1 ; -evsel__set_syscall_arg_fmt (evsel, evsel->tp_format->name +sizeof ("sys_enter_" ) -1 ); - }else if (!strncmp (evsel->tp_format->name,"sys_exit_" ,9 )) { +evsel__set_syscall_arg_fmt (evsel, + tp_format->name +sizeof ("sys_enter_" ) -1 ); + }else if (!strncmp (tp_format->name,"sys_exit_" ,9 )) {struct syscall_tp *sc =__evsel__syscall_tp (evsel);tools/perf/builtin-trace.c static int evlist__set_syscall_tp_fields(struct evlist *evlist, bool *use_btf) · line 4921
Quoted 10 lines
tools/perf/builtin-trace.c +5
-2-if (__tp_field__init_uint (&sc->ret,sizeof (u64), sc->id.offset +sizeof (u64), evsel->needs_swap)) +if (__tp_field__init_uint (&sc->ret,sizeof (u64), + sc->id.offset +sizeof (u64), + evsel->needs_swap))return -1 ; -evsel__set_syscall_arg_fmt (evsel, evsel->tp_format->name +sizeof ("sys_exit_" ) -1 ); +evsel__set_syscall_arg_fmt (evsel, + tp_format->name +sizeof ("sys_exit_" ) -1 );If you left it as
tools/perf/builtin-trace.c +1
-1-evsel__set_syscall_arg_fmt (evsel, evsel->tp_format->name +sizeof ("sys_exit_" ) -1 ); +evsel__set_syscall_arg_fmt (evsel, tp_format->name +sizeof ("sys_exit_" ) -1 );
Quoted 1 line
It would be shorter than before and slightly faster to visually decode.
101 columns.
Quoted 262 lines
Quoted 262 lines
tools/perf/builtin-trace.c +0
-0} }tools/perf/util/data-convert-bt.c +6
-4@@ -426,8 +426,9 @@ static int add_tracepoint_values(struct ctf_writer *cw,struct evsel *evsel, struct perf_sample *sample) { - struct tep_format_field *common_fields = evsel->tp_format->format.common_fields; -struct tep_format_field *fields = evsel->tp_format->format.fields; + const struct tep_event *tp_format = evsel__tp_format(evsel); +struct tep_format_field *common_fields = tp_format->format.common_fields; +struct tep_format_field *fields = tp_format->format.fields;int ret; ret = add_tracepoint_fields_values(cw, event_class, event,@@ -1064,8 +1065,9 @@ static int add_tracepoint_types(struct ctf_writer *cw,struct evsel *evsel, struct bt_ctf_event_class *class) { - struct tep_format_field *common_fields = evsel->tp_format->format.common_fields; -struct tep_format_field *fields = evsel->tp_format->format.fields; + const struct tep_event *tp_format = evsel__tp_format(evsel); +struct tep_format_field *common_fields = tp_format ? tp_format->format.common_fields :NULL ; +struct tep_format_field *fields = tp_format ? tp_format->format.fields :NULL ;int ret; ret =add_tracepoint_fields_types (cw, common_fields, class);tools/perf/util/data-convert-json.c +4
-4@@ -230,12 +230,12 @@ static int process_sample_event(const struct perf_tool *tool,#ifdef HAVE_LIBTRACEEVENT if (sample->raw_data) { -int i; -struct tep_format_field **fields; +struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_format_field **fields = tp_format ?tep_event_fields (tp_format) :NULL ; - fields =tep_event_fields (evsel->tp_format);if (fields) { - i =0 ; +int i =0 ; +while (fields[i]) {struct trace_seq s;tools/perf/util/evsel.c +7
-2@@ -570,6 +570,7 @@ struct evsel *evsel__newtp_idx(const char *sys, const char *name, int idx, bool evsel->tp_format =trace_event__tp_format (sys, name);if (IS_ERR (evsel->tp_format)) { err =PTR_ERR (evsel->tp_format); + evsel->tp_format =NULL ; goto out_free; } attr.config = evsel->tp_format->id;@@ -3209,12 +3210,16 @@ u16 evsel__id_hdr_size(const struct evsel *evsel)#ifdef HAVE_LIBTRACEEVENT struct tep_format_field *evsel__field (struct evsel *evsel,const char *name) { -return tep_find_field (evsel->tp_format, name); +struct tep_event *tp_format =evsel__tp_format (evsel); + +return tp_format ?tep_find_field (tp_format, name) :NULL ; }struct tep_format_field *evsel__common_field (struct evsel *evsel,const char *name) { -return tep_find_common_field (evsel->tp_format, name); +struct tep_event *tp_format =evsel__tp_format (evsel); + +return tp_format ?tep_find_common_field (tp_format, name) :NULL ; }void *evsel__rawptr (struct evsel *evsel,struct perf_sample *sample,const char *name)tools/perf/util/evsel.h +5
-0@@ -257,6 +257,11 @@ static inline struct evsel *evsel__newtp(const char *sys, const char *name) {return evsel__newtp_idx (sys, name,0 , true); } + +static inline struct tep_event *evsel__tp_format (struct evsel *evsel) +{ +return evsel->tp_format; +}#endif #ifdef HAVE_LIBTRACEEVENT tools/perf/util/evsel_fprintf.c +3
-1@@ -81,13 +81,15 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#ifdef HAVE_LIBTRACEEVENT if (details->trace_fields) {struct tep_format_field *field; +const struct tep_event *tp_format;if (evsel->core.attr.type !=PERF_TYPE_TRACEPOINT ) { printed +=comma_fprintf (fp, &first," (not a tracepoint)" ); goto out; } - field = evsel->tp_format->format.fields; + tp_format =evsel__tp_format (evsel); + field = tp_format ? tp_format->format.fields :NULL ;if (field ==NULL ) { printed +=comma_fprintf (fp, &first," (no trace field)" ); goto out;tools/perf/util/scripting-engines/trace-event-perl.c +2
-1@@ -344,7 +344,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, struct addr_location *al) {struct thread *thread = al->thread; -struct tep_event *event = evsel->tp_format; +struct tep_event *event;struct tep_format_field *field;static char handler[256 ];unsigned long long val;@@ -362,6 +362,7 @@ static void perl_process_tracepoint(struct perf_sample *sample,if (evsel->core.attr.type !=PERF_TYPE_TRACEPOINT )return ; + event =evsel__tp_format (evsel);if (!event) {pr_debug ("ug! no event found for type %" PRIu64, (u64 )evsel->core.attr.config);return ;tools/perf/util/scripting-engines/trace-event-python.c +2
-1@@ -946,7 +946,7 @@ static void python_process_tracepoint(struct perf_sample *sample,struct addr_location *al, struct addr_location *addr_al) { - struct tep_event *event = evsel->tp_format; + struct tep_event *event;PyObject *handler, *context, *t, *obj =NULL , *callchain;PyObject *dict =NULL , *all_entries_dict =NULL ;static char handler_name[256 ];@@ -963,6 +963,7 @@ static void python_process_tracepoint(struct perf_sample *sample,bitmap_zero (events_defined,TRACE_EVENT_TYPE_MAX ); + event =evsel__tp_format (evsel);if (!event) {snprintf (handler_name,sizeof (handler_name),"ug! no event found for type %" PRIu64, (u64 )evsel->core.attr.config);tools/perf/util/sort.c +21
-12@@ -1038,17 +1038,19 @@ static char *get_trace_output(struct hist_entry *he) .data = he->raw_data, .size = he->raw_size, }; +struct tep_event *tp_format; evsel =hists_to_evsel (he->hists);trace_seq_init (&seq); -if (symbol_conf.raw_trace) { -tep_print_fields (&seq, he->raw_data, he->raw_size, - evsel->tp_format); - }else { -tep_print_event (evsel->tp_format->tep, - &seq, &rec,"%s" ,TEP_PRINT_INFO ); + tp_format =evsel__tp_format (evsel); +if (tp_format) { +if (symbol_conf.raw_trace) +tep_print_fields (&seq, he->raw_data, he->raw_size, tp_format); +else +tep_print_event (tp_format->tep, &seq, &rec,"%s" ,TEP_PRINT_INFO ); } +/* * Trim the buffer, it starts at 4KB and we're not going to * add anything more to this buffer. @@ -3293,9 +3295,8 @@ static int __dynamic_dimension__add(struct evsel *evsel,static int add_evsel_fields (struct evsel *evsel,bool raw_trace,int level) {int ret; -struct tep_format_field *field; - - field = evsel->tp_format->format.fields; +struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_format_field *field = tp_format ? tp_format->format.fields :NULL ;while (field) { ret =__dynamic_dimension__add (evsel, field, raw_trace, level);if (ret <0 )@@ -3328,13 +3329,19 @@ static int add_all_matching_fields(struct evlist *evlist, {int ret = -ESRCH ;struct evsel *evsel; -struct tep_format_field *field;evlist__for_each_entry (evlist, evsel) { +struct tep_event *tp_format; +struct tep_format_field *field; +if (evsel->core.attr.type !=PERF_TYPE_TRACEPOINT )continue ; - field =tep_find_any_field (evsel->tp_format, field_name); + tp_format =evsel__tp_format (evsel); +if (tp_format ==NULL ) +continue ; + + field =tep_find_any_field (tp_format, field_name);if (field ==NULL )continue ;@@ -3416,7 +3423,9 @@ static int add_dynamic_entry(struct evlist *evlist, const char *tok,if (!strcmp (field_name,"*" )) { ret =add_evsel_fields (evsel, raw_trace, level); }else { -struct tep_format_field *field =tep_find_any_field (evsel->tp_format, field_name); +struct tep_event *tp_format =evsel__tp_format (evsel); +struct tep_format_field *field = + tp_format ?tep_find_any_field (tp_format, field_name) :NULL ;if (field ==NULL ) { pr_debug("Cannot find event field for %s.%s\n",tools/perf/util/trace-event-scripting.c +6
-5@@ -28,12 +28,14 @@ void scripting_context__update(struct scripting_context *c,struct addr_location *al, struct addr_location *addr_al) { - c->event_data = sample->raw_data; - c->pevent =NULL ; #ifdef HAVE_LIBTRACEEVENT -if (evsel->tp_format) - c->pevent = evsel->tp_format->tep; + const struct tep_event *tp_format = evsel__tp_format(evsel); + + c->pevent = tp_format ? tp_format->tep :NULL ; +#else + c->pevent =NULL ;#endif + c->event_data = sample->raw_data; c->event = event; c->sample = sample; c->evsel = evsel; --2.47.0.199.ga7371fff76-goog
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2 4/6] perf evsel: Add/use accessor for tp_format
Quoted 32 lines · Ian Rogers
Quoted 24 lines · Arnaldo Carvalho de Melo
Quoted 23 lines · Ian Rogers
Add an accessor function for
tp_format. Rather than search+replace uses try to use a variable and reuse it. Add additional NULL checks when accessing/using the value. Make sure thePTR_ERRis nulled out on error path inevsel__newtp_idx.Signed-off-by Ian Rogers <[email protected]>+++
b/tools/perf/builtin-kmem.c(quoted diff) +3
-2@@ -772,8 +773,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, } trace_seq_init(&seq); - tep_print_event(evsel->tp_format->tep, - &seq, &record, "%s", TEP_PRINT_INFO); + tp_format = evsel__tp_format(evsel); + if (tp_format) + tep_print_event(tp_format->tep, &seq, &record, "%s", TEP_PRINT_INFO); str = strtok_r(seq.buffer, " ", &pos); while (str) {@@ -2011,14 +2013,15 @@ int cmd_kmem(int argc, const char **argv) }Quoted 6 lines
Review int cmd_kmem(int argc, const char **argv) · line 2017
Quoted 4 lines
(quoted diff) +2
-1if (kmem_page) { - struct evsel *evsel = evlist__find_tracepoint_by_name(session->evlist, "kmem:mm_page_alloc"); + struct evsel *evsel = evlist__find_tracepoint_by_name(session->evlist, + "kmem:mm_page_alloc");Try to avoid these reflows to reduce patch size, please.
Quoted 2 lines
Agreed, in this case check
checkpatch.plis complaining that the line length is 109 columns.
Ok, but it was like that before, your patch is not touching that line for some other reason, so it is unrelated to what you're doing, causing a distraction.
Besides, even the documentation for checkpatch mentions that that is:
**LONG_LINE**
The line has exceeded the specified maximum length.
To use a different maximum line length, the --max-line-length=n option may be added while invoking checkpatch.
Earlier, the default line length was 80 columns. Commit bdc48fa11e46 ("checkpatch/coding-style: deprecate 80-column warning") increased the limit to 100 columns. This is not a hard limit either and it's preferable to stay within 80 columns whenever possible.
See: https://www.kernel.org/doc/html/latest/process/coding-style.html#breaking-long-lines-and-strings
----------------
So if it was there already, meaning the original author preferred it that way, its not touched by the feature that is being worked on in this patch, ends up being an extra hunk, just reflowing, a distraction.
- Arnaldo
Ian Rogers
reviewerRe: [PATCH v2 4/6] perf evsel: Add/use accessor for tp_format
Quoted 53 lines · Arnaldo Carvalho de Melo
Quoted 32 lines · Ian Rogers
Quoted 24 lines · Arnaldo Carvalho de Melo
Quoted 23 lines · Ian Rogers
Add an accessor function for
tp_format. Rather than search+replace uses try to use a variable and reuse it. Add additional NULL checks when accessing/using the value. Make sure thePTR_ERRis nulled out on error path inevsel__newtp_idx.Signed-off-by Ian Rogers <[email protected]>+++
b/tools/perf/builtin-kmem.c(quoted diff) +3
-2@@ -772,8 +773,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, } trace_seq_init(&seq); - tep_print_event(evsel->tp_format->tep, - &seq, &record, "%s", TEP_PRINT_INFO); + tp_format = evsel__tp_format(evsel); + if (tp_format) + tep_print_event(tp_format->tep, &seq, &record, "%s", TEP_PRINT_INFO); str = strtok_r(seq.buffer, " ", &pos); while (str) {@@ -2011,14 +2013,15 @@ int cmd_kmem(int argc, const char **argv) }Quoted 6 lines
Review int cmd_kmem(int argc, const char **argv) · line 2017
Quoted 4 lines
(quoted diff) +2
-1if (kmem_page) { - struct evsel *evsel = evlist__find_tracepoint_by_name(session->evlist, "kmem:mm_page_alloc"); + struct evsel *evsel = evlist__find_tracepoint_by_name(session->evlist, + "kmem:mm_page_alloc");Try to avoid these reflows to reduce patch size, please.
Quoted 2 lines
Agreed, in this case check
checkpatch.plis complaining that the line length is 109 columns.Ok, but it was like that before, your patch is not touching that line for some other reason, so it is unrelated to what you're doing, causing a distraction.
Besides, even the documentation for checkpatch mentions that that is:
**LONG_LINE**
The line has exceeded the specified maximum length.
To use a different maximum line length, the --max-line-length=n option may be added while invoking checkpatch.Earlier, the default line length was 80 columns. Commit
bdc48fa11e46("checkpatch/coding-style: deprecate 80-column warning") increased the limit to 100 columns. This is not a hard limit either and it's preferable to stay within 80 columns whenever possible.
Quoted 7 lines
See: https://www.kernel.org/doc/html/latest/process/coding-style.html#breaking-long-lines-and-strings
----------------
So if it was there already, meaning the original author preferred it that way, its not touched by the feature that is being worked on in this patch, ends up being an extra hunk, just reflowing, a distraction.
Wow, respecting the author's preferences, sounds like a good thing to be doing :-) Like I say it came up from checkpatch.pl as I changed the next line and it was over by quite a way so I felt it was innocuous to fix it. The variable on this line is used on the next line (the one I changed) so it isn't as if they are entirely unrelated. I agreed to put it back. Often reviews like this feel like you are saying arbitrary changes were made for no reason, which I have a long experience of avoiding doing. I also try to make sure I don't send patches upstream that checkpath.pl warns about, its a shame whoever authored the line didn't think similarly.
Thanks,
Ian
Ian Rogers
reviewerPATCH v2 5/6 perf evsel: Allow evsel__newtp without libtraceevent
In reply to Ian RogersSwitch from reading the tracepoint format to reading the id directly for the evsel config. This avoids the need to initialize libtraceevent, plugins, etc. It is sufficient for many tracepoint commands to work like:
$ perf stat -e sched:sched_switch true
To populate evsel->tp_format, do lazy initialization using libtraceevent in the evsel__tp_format function (the sys and name are saved in evsel__newtp_idx for this purpose). Reading the id should be indicative of the format failing to load, but if not an error is reported in evsel__tp_format. This could happen for a tracepoint with a format that fails to parse.
As tracepoints can be parsed without libtraceevent with this, remove the associated #ifdefs in parse-events.c.
By only lazily parsing the tracepoint format information it is hoped this will help improve the performance of code using tracepoints but not the format information. It also cuts down on the build and ifdef logic.
--- tools/perf/util/evsel.c | 103 ++++++++++++++++++++++++--------- tools/perf/util/evsel.h | 14 ++--- tools/perf/util/parse-events.c | 16 +---- 3 files changed, 82 insertions(+), 51 deletions(-)
tools/perf/util/evsel.c +77 -26
@@ -543,54 +543,101 @@ struct evsel *evsel__clone(struct evsel *orig)return NULL ; } +static int trace_event__id (const char *sys,const char *name) +{ +char *tp_dir =get_events_file (sys); +char path[PATH_MAX ]; +int id, err; + +if (!tp_dir) +return -1 ; + +scnprintf (path,PATH_MAX ,"%s/%s/id" , tp_dir, name); +put_events_file (tp_dir); + err =filename__read_int (path, &id); +if (err) +return err; + +return id; +} +/* * Returns pointer with encoded error via <linux/err.h> interface. */ -#ifdef HAVE_LIBTRACEEVENT struct evsel *evsel__newtp_idx (const char *sys,const char *name,int idx,bool format) { +struct perf_event_attr attr = { + .type =PERF_TYPE_TRACEPOINT , + .sample_type = (PERF_SAMPLE_RAW |PERF_SAMPLE_TIME | +PERF_SAMPLE_CPU |PERF_SAMPLE_PERIOD ), + };struct evsel *evsel =zalloc (perf_evsel__object.size); -int err = -ENOMEM ; +int err = -ENOMEM , id =-1 ; -if (evsel ==NULL ) { +if (evsel ==NULL ) goto out_err; - }else { -struct perf_event_attr attr = { - .type =PERF_TYPE_TRACEPOINT , - .sample_type = (PERF_SAMPLE_RAW |PERF_SAMPLE_TIME | -PERF_SAMPLE_CPU |PERF_SAMPLE_PERIOD ), - }; -if (asprintf (&evsel->name,"%s:%s" , sys, name) <0 ) - goto out_free; -event_attr_init (&attr); +if (asprintf (&evsel->name,"%s:%s" , sys, name) <0 ) + goto out_free; -if (format) { - evsel->tp_format =trace_event__tp_format (sys, name); -if (IS_ERR (evsel->tp_format)) { - err =PTR_ERR (evsel->tp_format); - evsel->tp_format =NULL ; - goto out_free; - } - attr.config = evsel->tp_format->id; - }else { - attr.config = (__u64) -1 ; - } +#ifdef HAVE_LIBTRACEEVENT + evsel->tp_sys =strdup (sys); +if (!evsel->tp_sys) + goto out_free; + evsel->tp_name =strdup (name); +if (!evsel->tp_name) + goto out_free; +#endif - attr.sample_period =1 ; -evsel__init (evsel, &attr, idx); - } +event_attr_init (&attr); +if (format) { + id =trace_event__id (sys, name); +if (id <0 ) { + err = id; + goto out_free; + } + } + attr.config = (__u64 )id; + attr.sample_period =1 ; +evsel__init (evsel, &attr, idx);return evsel; out_free:zfree (&evsel->name); +#ifdef HAVE_LIBTRACEEVENT +zfree (&evsel->tp_sys); +zfree (&evsel->tp_name); +#endif free (evsel); out_err:return ERR_PTR (err); } + +#ifdef HAVE_LIBTRACEEVENT +struct tep_event *evsel__tp_format (struct evsel *evsel) +{ +struct tep_event *tp_format = evsel->tp_format; + +if (tp_format) +return tp_format; + +if (evsel->core.attr.type !=PERF_TYPE_TRACEPOINT ) +return NULL ; + + tp_format =trace_event__tp_format (evsel->tp_sys, evsel->tp_name); +if (IS_ERR (tp_format)) { +int err = -PTR_ERR (evsel->tp_format); + +pr_err ("Error getting tracepoint format '%s' '%s'(%d)\n" , +evsel__name (evsel),strerror (err), err); +return NULL ; + } + evsel->tp_format = tp_format; +return evsel->tp_format; +}#endif const char *const evsel__hw_names[PERF_COUNT_HW_MAX ] = {
@@ -1587,6 +1634,10 @@ void evsel__exit(struct evsel *evsel)perf_thread_map__put (evsel->core.threads);zfree (&evsel->group_name);zfree (&evsel->name); +#ifdef HAVE_LIBTRACEEVENT +zfree (&evsel->tp_sys); +zfree (&evsel->tp_name); +#endif zfree (&evsel->filter);zfree (&evsel->group_pmu_name);zfree (&evsel->unit);
tools/perf/util/evsel.h +4 -10
@@ -59,6 +59,8 @@ struct evsel {char *group_name;const char *group_pmu_name;#ifdef HAVE_LIBTRACEEVENT +char *tp_sys; +char *tp_name;struct tep_event *tp_format;#endif char *filter;
@@ -247,25 +249,17 @@ int copy_config_terms(struct list_head *dst, struct list_head *src);void free_config_terms (struct list_head *config_terms); -#ifdef HAVE_LIBTRACEEVENT -struct evsel *evsel__newtp_idx (const char *sys,const char *name,int idx,bool format); -/* * Returns pointer with encoded error via <linux/err.h> interface. */ +struct evsel *evsel__newtp_idx (const char *sys,const char *name,int idx,bool format);static inline struct evsel *evsel__newtp (const char *sys,const char *name) {return evsel__newtp_idx (sys, name,0 , true); } -static inline struct tep_event *evsel__tp_format (struct evsel *evsel) -{ -return evsel->tp_format; -} -#endif -#ifdef HAVE_LIBTRACEEVENT -struct tep_event *event_format__new (const char *sys,const char *name); +struct tep_event *evsel__tp_format (struct evsel *evsel);#endif void evsel__init (struct evsel *evsel,struct perf_event_attr *attr,int idx);
tools/perf/util/parse-events.c +1 -15
@@ -489,7 +489,6 @@ int parse_events_add_cache(struct list_head *list, int *idx, const char *name,return found_supported ?0 : -EINVAL ; } -#ifdef HAVE_LIBTRACEEVENT static void tracepoint_error (struct parse_events_error *e,int err,const char *sys,const char *name,int column) {
@@ -644,7 +643,6 @@ static int add_tracepoint_multi_sys(struct parse_events_state *parse_state,closedir (events_dir);return ret; } -#endif /* HAVE_LIBTRACEEVENT */ size_t default_breakpoint_len (void ) {
@@ -1066,7 +1064,6 @@ static int config_term_pmu(struct perf_event_attr *attr,return config_term_common (attr, term, err); } -#ifdef HAVE_LIBTRACEEVENT static int config_term_tracepoint (struct perf_event_attr *attr,struct parse_events_term *term,struct parse_events_error *err)
@@ -1111,7 +1108,6 @@ static int config_term_tracepoint(struct perf_event_attr *attr,return 0 ; } -#endif static int config_attr(struct perf_event_attr *attr, const struct parse_events_terms *head,
@@ -1303,7 +1299,7 @@ int parse_events_add_tracepoint(struct parse_events_state *parse_state, struct parse_events_terms *head_config, void *loc_) { YYLTYPE *loc = loc_; -#ifdef HAVE_LIBTRACEEVENT +if (head_config) {struct perf_event_attr attr;
@@ -1318,16 +1314,6 @@ int parse_events_add_tracepoint(struct parse_events_state *parse_state,else return add_tracepoint_event (parse_state, list, sys, event, err, head_config, loc); -#else - (void )parse_state; - (void )list; - (void )sys; - (void )event; - (void )head_config; -parse_events_error__handle (err, loc->first_column,strdup ("unsupported tracepoint" ), -strdup ("libtraceevent is necessary for tracepoint support" )); -return -1 ; -#endif } static int __parse_events_add_numeric(struct parse_events_state *parse_state,
Signature · 1 line
2.47.0.199.ga7371fff76-goog
Re: [PATCH v2 5/6] perf evsel: Allow evsel__newtp without libtraceevent
Quoted 5 lines · Ian Rogers
Switch from reading the tracepoint format to reading the id directly for the evsel config. This avoids the need to initialize libtraceevent, plugins, etc. It is sufficient for many tracepoint commands to work like:
$ perf stat -e sched:sched_switch true
root@x1:~# perf check feature libtraceevent
libtraceevent: [ OFF ] # HAVE_LIBTRACEEVENT
root@x1:~# perf stat -e sched:sched_switch -I 1000
# time counts unit events
1.001071607 4,631 sched:sched_switch
2.004003548 5,138 sched:sched_switch
3.006847313 4,967 sched:sched_switch
^C 3.944095456 5,553 sched:sched_switch root@x1:~#
Works:
Quoted 271 lines
To populate
evsel->tp_format, do lazy initialization using libtraceevent in theevsel__tp_formatfunction (the sys and name are saved inevsel__newtp_idxfor this purpose). Reading the id should be indicative of the format failing to load, but if not an error is reported inevsel__tp_format. This could happen for a tracepoint with a format that fails to parse.As tracepoints can be parsed without libtraceevent with this, remove the associated #ifdefs in
parse-events.c.By only lazily parsing the tracepoint format information it is hoped this will help improve the performance of code using tracepoints but not the format information. It also cuts down on the build and ifdef logic.
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/evsel.c | 103 ++++++++++++++++++++++++--------- tools/perf/util/evsel.h | 14 ++--- tools/perf/util/parse-events.c | 16 +---- 3 files changed, 82 insertions(+), 51 deletions(-)tools/perf/util/evsel.c +77
-26@@ -543,54 +543,101 @@ struct evsel *evsel__clone(struct evsel *orig)return NULL ; } +static int trace_event__id (const char *sys,const char *name) +{ +char *tp_dir =get_events_file (sys); +char path[PATH_MAX ]; +int id, err; + +if (!tp_dir) +return -1 ; + +scnprintf (path,PATH_MAX ,"%s/%s/id" , tp_dir, name); +put_events_file (tp_dir); + err =filename__read_int (path, &id); +if (err) +return err; + +return id; +} +/* * Returns pointer with encoded error via <linux/err.h> interface. */ -#ifdef HAVE_LIBTRACEEVENT struct evsel *evsel__newtp_idx (const char *sys,const char *name,int idx,bool format) { +struct perf_event_attr attr = { + .type =PERF_TYPE_TRACEPOINT , + .sample_type = (PERF_SAMPLE_RAW |PERF_SAMPLE_TIME | +PERF_SAMPLE_CPU |PERF_SAMPLE_PERIOD ), + };struct evsel *evsel =zalloc (perf_evsel__object.size); -int err = -ENOMEM ; +int err = -ENOMEM , id =-1 ; -if (evsel ==NULL ) { +if (evsel ==NULL ) goto out_err; - }else { -struct perf_event_attr attr = { - .type =PERF_TYPE_TRACEPOINT , - .sample_type = (PERF_SAMPLE_RAW |PERF_SAMPLE_TIME | -PERF_SAMPLE_CPU |PERF_SAMPLE_PERIOD ), - }; -if (asprintf (&evsel->name,"%s:%s" , sys, name) <0 ) - goto out_free; -event_attr_init (&attr); +if (asprintf (&evsel->name,"%s:%s" , sys, name) <0 ) + goto out_free; -if (format) { - evsel->tp_format =trace_event__tp_format (sys, name); -if (IS_ERR (evsel->tp_format)) { - err =PTR_ERR (evsel->tp_format); - evsel->tp_format =NULL ; - goto out_free; - } - attr.config = evsel->tp_format->id; - }else { - attr.config = (__u64) -1 ; - } +#ifdef HAVE_LIBTRACEEVENT + evsel->tp_sys =strdup (sys); +if (!evsel->tp_sys) + goto out_free; + evsel->tp_name =strdup (name); +if (!evsel->tp_name) + goto out_free; +#endif - attr.sample_period =1 ; -evsel__init (evsel, &attr, idx); - } +event_attr_init (&attr); +if (format) { + id =trace_event__id (sys, name); +if (id <0 ) { + err = id; + goto out_free; + } + } + attr.config = (__u64 )id; + attr.sample_period =1 ; +evsel__init (evsel, &attr, idx);return evsel; out_free:zfree (&evsel->name); +#ifdef HAVE_LIBTRACEEVENT +zfree (&evsel->tp_sys); +zfree (&evsel->tp_name); +#endif free (evsel); out_err:return ERR_PTR (err); } + +#ifdef HAVE_LIBTRACEEVENT +struct tep_event *evsel__tp_format (struct evsel *evsel) +{ +struct tep_event *tp_format = evsel->tp_format; + +if (tp_format) +return tp_format; + +if (evsel->core.attr.type !=PERF_TYPE_TRACEPOINT ) +return NULL ; + + tp_format =trace_event__tp_format (evsel->tp_sys, evsel->tp_name); +if (IS_ERR (tp_format)) { +int err = -PTR_ERR (evsel->tp_format); + +pr_err ("Error getting tracepoint format '%s' '%s'(%d)\n" , +evsel__name (evsel),strerror (err), err); +return NULL ; + } + evsel->tp_format = tp_format; +return evsel->tp_format; +}#endif const char *const evsel__hw_names[PERF_COUNT_HW_MAX ] = {@@ -1587,6 +1634,10 @@ void evsel__exit(struct evsel *evsel)perf_thread_map__put (evsel->core.threads);zfree (&evsel->group_name);zfree (&evsel->name); +#ifdef HAVE_LIBTRACEEVENT +zfree (&evsel->tp_sys); +zfree (&evsel->tp_name); +#endif zfree (&evsel->filter);zfree (&evsel->group_pmu_name);zfree (&evsel->unit);tools/perf/util/evsel.h +4
-10@@ -59,6 +59,8 @@ struct evsel {char *group_name;const char *group_pmu_name;#ifdef HAVE_LIBTRACEEVENT +char *tp_sys; +char *tp_name;struct tep_event *tp_format;#endif char *filter;@@ -247,25 +249,17 @@ int copy_config_terms(struct list_head *dst, struct list_head *src);void free_config_terms (struct list_head *config_terms); -#ifdef HAVE_LIBTRACEEVENT -struct evsel *evsel__newtp_idx (const char *sys,const char *name,int idx,bool format); -/* * Returns pointer with encoded error via <linux/err.h> interface. */ +struct evsel *evsel__newtp_idx (const char *sys,const char *name,int idx,bool format);static inline struct evsel *evsel__newtp (const char *sys,const char *name) {return evsel__newtp_idx (sys, name,0 , true); } -static inline struct tep_event *evsel__tp_format (struct evsel *evsel) -{ -return evsel->tp_format; -} -#endif -#ifdef HAVE_LIBTRACEEVENT -struct tep_event *event_format__new (const char *sys,const char *name); +struct tep_event *evsel__tp_format (struct evsel *evsel);#endif void evsel__init (struct evsel *evsel,struct perf_event_attr *attr,int idx);tools/perf/util/parse-events.c +1
-15@@ -489,7 +489,6 @@ int parse_events_add_cache(struct list_head *list, int *idx, const char *name,return found_supported ?0 : -EINVAL ; } -#ifdef HAVE_LIBTRACEEVENT static void tracepoint_error (struct parse_events_error *e,int err,const char *sys,const char *name,int column) {@@ -644,7 +643,6 @@ static int add_tracepoint_multi_sys(struct parse_events_state *parse_state,closedir (events_dir);return ret; } -#endif /* HAVE_LIBTRACEEVENT */ size_t default_breakpoint_len (void ) {@@ -1066,7 +1064,6 @@ static int config_term_pmu(struct perf_event_attr *attr,return config_term_common (attr, term, err); } -#ifdef HAVE_LIBTRACEEVENT static int config_term_tracepoint (struct perf_event_attr *attr,struct parse_events_term *term,struct parse_events_error *err)@@ -1111,7 +1108,6 @@ static int config_term_tracepoint(struct perf_event_attr *attr,return 0 ; } -#endif static int config_attr(struct perf_event_attr *attr, const struct parse_events_terms *head,@@ -1303,7 +1299,7 @@ int parse_events_add_tracepoint(struct parse_events_state *parse_state, struct parse_events_terms *head_config, void *loc_) { YYLTYPE *loc = loc_; -#ifdef HAVE_LIBTRACEEVENT +if (head_config) {struct perf_event_attr attr;@@ -1318,16 +1314,6 @@ int parse_events_add_tracepoint(struct parse_events_state *parse_state,else return add_tracepoint_event (parse_state, list, sys, event, err, head_config, loc); -#else - (void )parse_state; - (void )list; - (void )sys; - (void )event; - (void )head_config; -parse_events_error__handle (err, loc->first_column,strdup ("unsupported tracepoint" ), -strdup ("libtraceevent is necessary for tracepoint support" )); -return -1 ; -#endif } static int __parse_events_add_numeric(struct parse_events_state *parse_state,Signature · 1 line
2.47.0.199.ga7371fff76-goog
Ian Rogers
reviewerPATCH v2 6/6 perf tests: Enable tests disabled due to tracepoint parsing
In reply to Ian RogersTracepoint parsing required libtraceevent but no longer does. Remove the Build logic and #ifdefs that caused the tests not to be run. Test code that directly uses libtraceevent is still guarded.
--- tools/perf/tests/Build | 6 +++--- tools/perf/tests/builtin-test.c | 2 -- tools/perf/tests/parse-events.c | 25 +------------------------ 3 files changed, 4 insertions(+), 29 deletions(-)
tools/perf/tests/Build +3 -3
@@ -5,10 +5,10 @@ perf-test-y += tests-scripts.o perf-test-y += parse-events.o perf-test-y += dso-data.o perf-test-y += vmlinux-kallsyms.o -perf-test-$(CONFIG_LIBTRACEEVENT) += openat-syscall.o -perf-test-$(CONFIG_LIBTRACEEVENT) += openat-syscall-all-cpus.o +perf-test-y += openat-syscall.o +perf-test-y += openat-syscall-all-cpus.o perf-test-$(CONFIG_LIBTRACEEVENT) += openat-syscall-tp-fields.o -perf-test-$(CONFIG_LIBTRACEEVENT) += mmap-basic.o +perf-test-y += mmap-basic.o perf-test-y += perf-record.o perf-test-y += evsel-roundtrip-name.o perf-test-$(CONFIG_LIBTRACEEVENT) += evsel-tp-sched.o
tools/perf/tests/builtin-test.c +0 -2
@@ -60,11 +60,9 @@ static struct test_suite *arch_tests[] = {static struct test_suite *generic_tests[] = { &suite__vmlinux_matches_kallsyms, -#ifdef HAVE_LIBTRACEEVENT &suite__openat_syscall_event, &suite__openat_syscall_event_on_all_cpus, &suite__basic_mmap, -#endif &suite__mem, &suite__parse_events, &suite__expr,
tools/perf/tests/parse-events.c +1 -24
@@ -54,8 +54,6 @@ static bool test_perf_config(const struct perf_evsel *evsel, __u64 expected_confreturn (evsel->attr.config &PERF_HW_EVENT_MASK ) == expected_config; } -#ifdef HAVE_LIBTRACEEVENT -#if defined(__s390x__)/* Return true if kvm module is available and loaded. Test this * and return success when trace point kvm_s390_create_vm
@@ -112,7 +110,6 @@ static int test__checkevent_tracepoint_multi(struct evlist *evlist) }return TEST_OK ; } -#endif /* HAVE_LIBTRACEEVENT */ static int test__checkevent_raw (struct evlist *evlist) {
@@ -311,7 +308,6 @@ static int test__checkevent_breakpoint_rw(struct evlist *evlist)return TEST_OK ; } -#ifdef HAVE_LIBTRACEEVENT static int test__checkevent_tracepoint_modifier (struct evlist *evlist) {struct evsel *evsel =evlist__first (evlist);
@@ -340,7 +336,6 @@ test__checkevent_tracepoint_multi_modifier(struct evlist *evlist)return test__checkevent_tracepoint_multi (evlist); } -#endif /* HAVE_LIBTRACEEVENT */ static int test__checkevent_raw_modifier (struct evlist *evlist) {
@@ -629,7 +624,6 @@ static int test__checkevent_pmu(struct evlist *evlist)return TEST_OK ; } -#ifdef HAVE_LIBTRACEEVENT static int test__checkevent_list (struct evlist *evlist) {struct evsel *evsel =evlist__first (evlist);
@@ -671,7 +665,6 @@ static int test__checkevent_list(struct evlist *evlist)return TEST_OK ; } -#endif static int test__checkevent_pmu_name (struct evlist *evlist) {
@@ -971,7 +964,6 @@ static int test__group2(struct evlist *evlist)return TEST_OK ; } -#ifdef HAVE_LIBTRACEEVENT static int test__group3 (struct evlist *evlist__maybe_unused ) {struct evsel *evsel, *group1_leader =NULL , *group2_leader =NULL ;
@@ -1078,7 +1070,6 @@ static int test__group3(struct evlist *evlist __maybe_unused) }return TEST_OK ; } -#endif static int test__group4 (struct evlist *evlist__maybe_unused ) {
@@ -1813,7 +1804,6 @@ static int test__term_equal_legacy(struct evlist *evlist)return TEST_OK ; } -#ifdef HAVE_LIBTRACEEVENT static int count_tracepoints (void ) {struct dirent *events_ent;
@@ -1867,7 +1857,6 @@ static int test__all_tracepoints(struct evlist *evlist)return test__checkevent_tracepoint_multi (evlist); } -#endif /* HAVE_LIBTRACEVENT */ struct evlist_test {const char *name;
@@ -1876,7 +1865,6 @@ struct evlist_test { };static const struct evlist_test test__events[] = { -#ifdef HAVE_LIBTRACEEVENT { .name ="syscalls:sys_enter_openat" , .check = test__checkevent_tracepoint,
@@ -1887,7 +1875,6 @@ static const struct evlist_test test__events[] = { .check = test__checkevent_tracepoint_multi, /* 1 */ }, -#endif { .name = "r1a", .check = test__checkevent_raw,
@@ -1938,7 +1925,6 @@ static const struct evlist_test test__events[] = { .check = test__checkevent_breakpoint_w, /* 1 */ }, -#ifdef HAVE_LIBTRACEEVENT { .name = "syscalls:sys_enter_openat:k", .check = test__checkevent_tracepoint_modifier,
@@ -1949,7 +1935,6 @@ static const struct evlist_test test__events[] = { .check = test__checkevent_tracepoint_multi_modifier, /* 3 */ }, -#endif { .name = "r1a:kp", .check = test__checkevent_raw_modifier,
@@ -1995,13 +1980,11 @@ static const struct evlist_test test__events[] = { .check = test__checkevent_breakpoint_w_modifier, /* 2 */ }, -#ifdef HAVE_LIBTRACEEVENT { .name = "r1,syscalls:sys_enter_openat:k,1:1:hp", .check = test__checkevent_list, /* 3 */ }, -#endif { .name = "instructions:G", .check = test__checkevent_exclude_host_modifier,
@@ -2032,13 +2015,11 @@ static const struct evlist_test test__events[] = { .check = test__group2, /* 9 */ }, -#ifdef HAVE_LIBTRACEEVENT { .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u", .check = test__group3, /* 0 */ }, -#endif { .name = "{cycles:u,instructions:kp}:p", .check = test__group4,
@@ -2049,13 +2030,11 @@ static const struct evlist_test test__events[] = { .check = test__group5, /* 2 */ }, -#ifdef HAVE_LIBTRACEEVENT { .name = "*:*", .check = test__all_tracepoints, /* 3 */ }, -#endif { .name = "{cycles,cache-misses:G}:H", .check = test__group_gh1,
@@ -2111,7 +2090,7 @@ static const struct evlist_test test__events[] = { .check = test__checkevent_breakpoint_len_rw_modifier, /* 4 */ }, -#if defined(__s390x__) && defined(HAVE_LIBTRACEEVENT ) +#if defined(__s390x__) { .name = "kvm-s390:kvm_s390_create_vm", .check = test__checkevent_tracepoint,
@@ -2265,13 +2244,11 @@ static const struct evlist_test test__events[] = { .check = test__checkevent_breakpoint_2_events, /* 3 */ }, -#ifdef HAVE_LIBTRACEEVENT { .name = "9p:9p_client_req", .check = test__checkevent_tracepoint, /* 4 */ }, -#endif };static const struct evlist_test test__events_pmu[] = {
Signature · 1 line
2.47.0.199.ga7371fff76-goog
Re: [PATCH v2 6/6] perf tests: Enable tests disabled due to tracepoint parsing
Quoted 3 lines · Ian Rogers
Tracepoint parsing required libtraceevent but no longer does. Remove the Build logic and #ifdefs that caused the tests not to be run. Test code that directly uses libtraceevent is still guarded.
- Arnaldo
root@x1:~# perf check feature libtraceevent
libtraceevent: [ OFF ] # HAVE_LIBTRACEEVENT
root@x1:~# perf test openat
2: Detect openat syscall event : Ok
3: Detect openat syscall event on all cpus : Ok
root@x1:~# perf test -vv openat
2: Detect openat syscall event:
--- start ---
test child forked, pid 820095
------------------------------------------------------------
perf_event_attr:
Using CPUID GenuineIntel-6-BA-3
type 2 (tracepoint)
size 136
config 0x2e6 (syscalls:sys_enter_openat)
{ sample_period, sample_freq } 1
sample_type TIME|CPU|PERIOD|RAW
------------------------------------------------------------
sys_perf_event_open: pid 820095 cpu -1 group_fd -1 flags 0x8 = 3
---- end(0) ----
2: Detect openat syscall event : Ok
3: Detect openat syscall event on all cpus:
--- start ---
test child forked, pid 820096
------------------------------------------------------------
perf_event_attr:
Using CPUID GenuineIntel-6-BA-3
type 2 (tracepoint)
size 136
config 0x2e6 (syscalls:sys_enter_openat)
{ sample_period, sample_freq } 1
sample_type TIME|CPU|PERIOD|RAW
------------------------------------------------------------
sys_perf_event_open: pid 820096 cpu 0 group_fd -1 flags 0x8 = 8
sys_perf_event_open: pid 820096 cpu 1 group_fd -1 flags 0x8 = 9
sys_perf_event_open: pid 820096 cpu 2 group_fd -1 flags 0x8 = 10
sys_perf_event_open: pid 820096 cpu 3 group_fd -1 flags 0x8 = 11
sys_perf_event_open: pid 820096 cpu 4 group_fd -1 flags 0x8 = 12
sys_perf_event_open: pid 820096 cpu 5 group_fd -1 flags 0x8 = 13
sys_perf_event_open: pid 820096 cpu 6 group_fd -1 flags 0x8 = 14
sys_perf_event_open: pid 820096 cpu 7 group_fd -1 flags 0x8 = 15
sys_perf_event_open: pid 820096 cpu 8 group_fd -1 flags 0x8 = 16
sys_perf_event_open: pid 820096 cpu 9 group_fd -1 flags 0x8 = 17
sys_perf_event_open: pid 820096 cpu 10 group_fd -1 flags 0x8 = 18
sys_perf_event_open: pid 820096 cpu 11 group_fd -1 flags 0x8 = 19
---- end(0) ----
3: Detect openat syscall event on all cpus : Ok
root@x1:~#