OSDN Git Service

perf trace: Reduce #ifdefs for TEP_FIELD_IS_RELATIVE
authorIan Rogers <irogers@google.com>
Wed, 11 Jan 2023 07:06:40 +0000 (23:06 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 19 Jan 2023 16:26:28 +0000 (13:26 -0300)
Add a helper function that applies the mask to test, or returns false
if libtraceevent is too old or not present.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Eelco Chaudron <echaudro@redhat.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Link: https://lore.kernel.org/r/20230111070641.1728726-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
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
tools/perf/util/trace-event.h

index 46944ea..610fb60 100644 (file)
@@ -2731,10 +2731,8 @@ 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;
-#if LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
-                               if (field->flags & TEP_FIELD_IS_RELATIVE)
+                               if (tep_field_is_relative(field->flags))
                                        offset += field->offset + field->size;
-#endif
                        }
 
                        val = (uintptr_t)(sample->raw_data + offset);
index 98454f7..2b732bc 100644 (file)
@@ -322,10 +322,8 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
                offset = tmp_val;
                len = offset >> 16;
                offset &= 0xffff;
-#if LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
-               if (flags & TEP_FIELD_IS_RELATIVE)
+               if (tep_field_is_relative(flags))
                        offset += fmtf->offset + fmtf->size;
-#endif
        }
 
        if (flags & TEP_FIELD_IS_ARRAY) {
index 296292f..8550638 100644 (file)
@@ -2784,10 +2784,8 @@ 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;
-#if LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
-               if (field->flags & TEP_FIELD_IS_RELATIVE)
+               if (tep_field_is_relative(field->flags))
                        offset += field->offset + field->size;
-#endif
        }
 
        return sample->raw_data + offset;
index 25a2767..d948455 100644 (file)
@@ -442,10 +442,8 @@ tracepoint_field(struct pyrf_event *pe, struct tep_format_field *field)
                        offset  = val;
                        len     = offset >> 16;
                        offset &= 0xffff;
-#if LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
-                       if (field->flags & TEP_FIELD_IS_RELATIVE)
+                       if (tep_field_is_relative(field->flags))
                                offset += field->offset + field->size;
-#endif
                }
                if (field->flags & TEP_FIELD_IS_STRING &&
                    is_printable_array(data + offset, len)) {
index 5bcec51..83fd2fd 100644 (file)
@@ -393,10 +393,8 @@ static void perl_process_tracepoint(struct perf_sample *sample,
                        if (field->flags & TEP_FIELD_IS_DYNAMIC) {
                                offset = *(int *)(data + field->offset);
                                offset &= 0xffff;
-#if LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
-                               if (field->flags & TEP_FIELD_IS_RELATIVE)
+                               if (tep_field_is_relative(field->flags))
                                        offset += field->offset + field->size;
-#endif
                        } else
                                offset = field->offset;
                        XPUSHs(sv_2mortal(newSVpv((char *)data + offset, 0)));
index 759ed6e..2c2697c 100644 (file)
@@ -994,10 +994,8 @@ static void python_process_tracepoint(struct perf_sample *sample,
                                offset  = val;
                                len     = offset >> 16;
                                offset &= 0xffff;
-#if LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
-                               if (field->flags & TEP_FIELD_IS_RELATIVE)
+                               if (tep_field_is_relative(field->flags))
                                        offset += field->offset + field->size;
-#endif
                        }
                        if (field->flags & TEP_FIELD_IS_STRING &&
                            is_printable_array(data + offset, len)) {
index 3673912..d7d0f99 100644 (file)
@@ -2668,10 +2668,8 @@ 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;
-#if LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
-               if (field->flags & TEP_FIELD_IS_RELATIVE)
+               if (tep_field_is_relative(field->flags))
                        offset += field->offset + field->size;
-#endif
                /* record max width for output */
                if (size > hde->dynamic_len)
                        hde->dynamic_len = size;
index 2e1b864..a0cff18 100644 (file)
@@ -140,4 +140,20 @@ int common_lock_depth(struct scripting_context *context);
 #define SAMPLE_FLAGS_BUF_SIZE 64
 int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz);
 
+#if defined(LIBTRACEEVENT_VERSION) &&  LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
+#include <traceevent/event-parse.h>
+
+static inline bool tep_field_is_relative(unsigned long flags)
+{
+       return (flags & TEP_FIELD_IS_RELATIVE) != 0;
+}
+#else
+#include <linux/compiler.h>
+
+static inline bool tep_field_is_relative(unsigned long flags __maybe_unused)
+{
+       return false;
+}
+#endif
+
 #endif /* _PERF_UTIL_TRACE_EVENT_H */