tools/perf: Add '__rel_loc' event field parsing support
authorMasami Hiramatsu <mhiramat@kernel.org>
Mon, 22 Nov 2021 09:30:48 +0000 (18:30 +0900)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Mon, 6 Dec 2021 20:37:22 +0000 (15:37 -0500)
Add new '__rel_loc' dynamic data location attribute support.
This type attribute is similar to the '__data_loc' but records the
offset from the field itself.
The libtraceevent adds TEP_FIELD_IS_RELATIVE to the
'tep_format_field::flags' with TEP_FIELD_IS_DYNAMIC for'__rel_loc'.

Link: https://lkml.kernel.org/r/163757344810.510314.12449413842136229871.stgit@devnote2
Cc: Beau Belgrave <beaub@linux.microsoft.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Tom Zanussi <zanussi@kernel.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
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 0b52e08..ea51776 100644 (file)
@@ -2726,6 +2726,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 (field->flags & TEP_FIELD_IS_RELATIVE)
+                                       offset += field->offset + field->size;
                        }
 
                        val = (uintptr_t)(sample->raw_data + offset);
index 8f7705b..9e0aee2 100644 (file)
@@ -318,6 +318,8 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
                offset = tmp_val;
                len = offset >> 16;
                offset &= 0xffff;
+               if (flags & TEP_FIELD_IS_RELATIVE)
+                       offset += fmtf->offset + fmtf->size;
        }
 
        if (flags & TEP_FIELD_IS_ARRAY) {
index ac0127b..f29d370 100644 (file)
@@ -2706,6 +2706,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 (field->flags & TEP_FIELD_IS_RELATIVE)
+                       offset += field->offset + field->size;
        }
 
        return sample->raw_data + offset;
index 563a9ba..3e7538d 100644 (file)
@@ -428,6 +428,8 @@ tracepoint_field(struct pyrf_event *pe, struct tep_format_field *field)
                        offset  = val;
                        len     = offset >> 16;
                        offset &= 0xffff;
+                       if (field->flags & TEP_FIELD_IS_RELATIVE)
+                               offset += field->offset + field->size;
                }
                if (field->flags & TEP_FIELD_IS_STRING &&
                    is_printable_array(data + offset, len)) {
index 32a721b..a5d9454 100644 (file)
@@ -392,6 +392,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 (field->flags & TEP_FIELD_IS_RELATIVE)
+                                       offset += field->offset + field->size;
                        } else
                                offset = field->offset;
                        XPUSHs(sv_2mortal(newSVpv((char *)data + offset, 0)));
index c0c0103..d1f1501 100644 (file)
@@ -942,6 +942,8 @@ static void python_process_tracepoint(struct perf_sample *sample,
                                offset  = val;
                                len     = offset >> 16;
                                offset &= 0xffff;
+                               if (field->flags & TEP_FIELD_IS_RELATIVE)
+                                       offset += field->offset + field->size;
                        }
                        if (field->flags & TEP_FIELD_IS_STRING &&
                            is_printable_array(data + offset, len)) {
index a111065..d9a106f 100644 (file)
@@ -2365,6 +2365,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 (field->flags & TEP_FIELD_IS_RELATIVE)
+                       offset += field->offset + field->size;
 
                /* record max width for output */
                if (size > hde->dynamic_len)