perf tools: Check if libtracevent has TEP_FIELD_IS_RELATIVE
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 8 Dec 2022 22:28:58 +0000 (19:28 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 14 Dec 2022 14:16:12 +0000 (11:16 -0300)
Some distros have older versions of libtraceevent where
TEP_FIELD_IS_RELATIVE and its associated semantics are not present, so
we need to check if the version has it, it was introduced in
libtraceevent 1.5.0.

Reported-by: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Tested-by: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Cc: Stephane Eranian <eranian@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Makefile.config
tools/perf/builtin-trace.c
tools/perf/util/data-convert-bt.c
tools/perf/util/evsel.c
tools/perf/util/python.c
tools/perf/util/scripting-engines/trace-event-perl.c
tools/perf/util/scripting-engines/trace-event-python.c
tools/perf/util/sort.c

index 680228e19c1aabdbc5aa09ff8cf247a4934a7c7d..52a4dc029111c1e2d867d159b5db8324c45ecc05 100644 (file)
@@ -1197,6 +1197,10 @@ ifneq ($(NO_LIBTRACEEVENT),1)
     LIBTRACEEVENT_VERSION_CPP := $(shell expr $(LIBTRACEEVENT_VERSION_1) \* 255 \* 255 + $(LIBTRACEEVENT_VERSION_2) \* 255 + $(LIBTRACEEVENT_VERSION_3))
     CFLAGS += -DLIBTRACEEVENT_VERSION=$(LIBTRACEEVENT_VERSION_CPP)
     $(call detected,CONFIG_LIBTRACEEVENT)
+    LIBTRACEEVENT_VERSION_WITH_TEP_FIELD_IS_RELATIVE := $(shell expr 1 \* 255 \* 255 + 5 \* 255 + 0) # 1.5.0
+    ifeq ($(shell test $(LIBTRACEEVENT_VERSION_CPP) -gt $(LIBTRACEEVENT_VERSION_WITH_TEP_FIELD_IS_RELATIVE); echo $$?),0)
+      CFLAGS += -DHAVE_LIBTRACEEVENT_TEP_FIELD_IS_RELATIVE
+    endif
   else
     dummy := $(warning Warning: libtraceevent is missing limiting functionality, please install libtraceevent-dev/libtraceevent-devel)
   endif
index 6909cd9f48d11644f1766ea7d2a342abe6669029..c9802ab549d7782f57d7265eab0055dc20b15aeb 100644 (file)
@@ -2729,8 +2729,10 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel,
                                offset = format_field__intval(field, sample, evsel->needs_swap);
                                syscall_arg.len = offset >> 16;
                                offset &= 0xffff;
+#ifdef HAVE_LIBTRACEEVENT_TEP_FIELD_IS_RELATIVE
                                if (field->flags & TEP_FIELD_IS_RELATIVE)
                                        offset += field->offset + field->size;
+#endif
                        }
 
                        val = (uintptr_t)(sample->raw_data + offset);
index 8031b586e81384e70e51c0476de7e1222e670ee5..b842273458b862bd1ab67e32495b8e1da3878e4b 100644 (file)
@@ -322,8 +322,10 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
                offset = tmp_val;
                len = offset >> 16;
                offset &= 0xffff;
+#ifdef HAVE_LIBTRACEEVENT_TEP_FIELD_IS_RELATIVE
                if (flags & TEP_FIELD_IS_RELATIVE)
                        offset += fmtf->offset + fmtf->size;
+#endif
        }
 
        if (flags & TEP_FIELD_IS_ARRAY) {
index ca911856c4b1d3c8f663bc9a65c1d8a16aa2fd0a..77b2cf5a214ec1e4d11213e3ce2cdfae21ce8252 100644 (file)
@@ -2784,8 +2784,10 @@ void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char
        if (field->flags & TEP_FIELD_IS_DYNAMIC) {
                offset = *(int *)(sample->raw_data + field->offset);
                offset &= 0xffff;
+#ifdef HAVE_LIBTRACEEVENT_TEP_FIELD_IS_RELATIVE
                if (field->flags & TEP_FIELD_IS_RELATIVE)
                        offset += field->offset + field->size;
+#endif
        }
 
        return sample->raw_data + offset;
index 6fb84b7455b8392dec628a3b004ffb7fe4546609..7320f7f777fe0e56f78080048835a359dcf17d4b 100644 (file)
@@ -442,8 +442,10 @@ tracepoint_field(struct pyrf_event *pe, struct tep_format_field *field)
                        offset  = val;
                        len     = offset >> 16;
                        offset &= 0xffff;
+#ifdef HAVE_LIBTRACEEVENT_TEP_FIELD_IS_RELATIVE
                        if (field->flags & TEP_FIELD_IS_RELATIVE)
                                offset += field->offset + field->size;
+#endif
                }
                if (field->flags & TEP_FIELD_IS_STRING &&
                    is_printable_array(data + offset, len)) {
index 0bacb49408f84adf7933cacd8ad27c0af3a80d7d..c097b7934fd4ebe92024cc076bfd69a3dcb276f3 100644 (file)
@@ -393,8 +393,10 @@ static void perl_process_tracepoint(struct perf_sample *sample,
                        if (field->flags & TEP_FIELD_IS_DYNAMIC) {
                                offset = *(int *)(data + field->offset);
                                offset &= 0xffff;
+#ifdef HAVE_LIBTRACEEVENT_TEP_FIELD_IS_RELATIVE
                                if (field->flags & TEP_FIELD_IS_RELATIVE)
                                        offset += field->offset + field->size;
+#endif
                        } else
                                offset = field->offset;
                        XPUSHs(sv_2mortal(newSVpv((char *)data + offset, 0)));
index fabba21919b8fa51fb933622569ded47ef298f52..e930f5f1f36d2831860d142143e4fc802bc3e46d 100644 (file)
@@ -994,8 +994,10 @@ static void python_process_tracepoint(struct perf_sample *sample,
                                offset  = val;
                                len     = offset >> 16;
                                offset &= 0xffff;
+#ifdef HAVE_LIBTRACEEVENT_TEP_FIELD_IS_RELATIVE
                                if (field->flags & TEP_FIELD_IS_RELATIVE)
                                        offset += field->offset + field->size;
+#endif
                        }
                        if (field->flags & TEP_FIELD_IS_STRING &&
                            is_printable_array(data + offset, len)) {
index c7a97b33e13477e16e8cc8472900cc2031db0c8e..0ecc2cb137920d2d88e15ac746c4a96c23503b3e 100644 (file)
@@ -2568,9 +2568,10 @@ static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt,
                tep_read_number_field(field, a->raw_data, &dyn);
                offset = dyn & 0xffff;
                size = (dyn >> 16) & 0xffff;
+#ifdef HAVE_LIBTRACEEVENT_TEP_FIELD_IS_RELATIVE
                if (field->flags & TEP_FIELD_IS_RELATIVE)
                        offset += field->offset + field->size;
-
+#endif
                /* record max width for output */
                if (size > hde->dynamic_len)
                        hde->dynamic_len = size;