perf scripting: Add scripting_context__update()
authorAdrian Hunter <adrian.hunter@intel.com>
Sun, 30 May 2021 19:22:58 +0000 (22:22 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 1 Jun 2021 13:03:02 +0000 (10:03 -0300)
Move scripting_context update to a separate function and add
the arguments of ->process_event() to it.

This prepares the way for adding more methods to the perf_trace_context
module, by providing the context information that they will need.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20210530192308.7382-4-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/scripting-engines/trace-event-perl.c
tools/perf/util/scripting-engines/trace-event-python.c
tools/perf/util/trace-event-scripting.c
tools/perf/util/trace-event.h

index a837aee..5bbf00c 100644 (file)
@@ -371,9 +371,6 @@ static void perl_process_tracepoint(struct perf_sample *sample,
        s = nsecs / NSEC_PER_SEC;
        ns = nsecs - s * NSEC_PER_SEC;
 
-       scripting_context->event_data = data;
-       scripting_context->pevent = evsel->tp_format->tep;
-
        ENTER;
        SAVETMPS;
        PUSHMARK(SP);
@@ -457,8 +454,9 @@ static void perl_process_event(union perf_event *event,
                               struct perf_sample *sample,
                               struct evsel *evsel,
                               struct addr_location *al,
-                              struct addr_location *addr_al __maybe_unused)
+                              struct addr_location *addr_al)
 {
+       scripting_context__update(scripting_context, event, sample, evsel, al, addr_al);
        perl_process_tracepoint(sample, evsel, al);
        perl_process_event_generic(event, sample, evsel);
 }
index ffc5f4c..d99f719 100644 (file)
@@ -897,9 +897,6 @@ static void python_process_tracepoint(struct perf_sample *sample,
        s = nsecs / NSEC_PER_SEC;
        ns = nsecs - s * NSEC_PER_SEC;
 
-       scripting_context->event_data = data;
-       scripting_context->pevent = evsel->tp_format->tep;
-
        context = _PyCapsule_New(scripting_context, NULL, NULL);
 
        PyTuple_SetItem(t, n++, _PyUnicode_FromString(handler_name));
@@ -1403,6 +1400,8 @@ static void python_process_event(union perf_event *event,
 {
        struct tables *tables = &tables_global;
 
+       scripting_context__update(scripting_context, event, sample, evsel, al, addr_al);
+
        switch (evsel->core.attr.type) {
        case PERF_TYPE_TRACEPOINT:
                python_process_tracepoint(sample, evsel, al, addr_al);
index 6c51fba..a2f0c1e 100644 (file)
 
 #include "debug.h"
 #include "trace-event.h"
+#include "event.h"
+#include "evsel.h"
 #include <linux/zalloc.h>
 
 struct scripting_context *scripting_context;
 
+void scripting_context__update(struct scripting_context *c,
+                              union perf_event *event,
+                              struct perf_sample *sample,
+                              struct evsel *evsel,
+                              struct addr_location *al,
+                              struct addr_location *addr_al)
+{
+       c->event_data = sample->raw_data;
+       if (evsel->tp_format)
+               c->pevent = evsel->tp_format->tep;
+       else
+               c->pevent = NULL;
+       c->event = event;
+       c->sample = sample;
+       c->evsel = evsel;
+       c->al = al;
+       c->addr_al = addr_al;
+}
+
 static int flush_script_unsupported(void)
 {
        return 0;
index 35c354a..a939318 100644 (file)
@@ -11,6 +11,7 @@ union perf_event;
 struct perf_tool;
 struct thread;
 struct tep_plugin_list;
+struct evsel;
 
 struct trace_event {
        struct tep_handle       *pevent;
@@ -101,8 +102,20 @@ void setup_python_scripting(void);
 struct scripting_context {
        struct tep_handle *pevent;
        void *event_data;
+       union perf_event *event;
+       struct perf_sample *sample;
+       struct evsel *evsel;
+       struct addr_location *al;
+       struct addr_location *addr_al;
 };
 
+void scripting_context__update(struct scripting_context *scripting_context,
+                              union perf_event *event,
+                              struct perf_sample *sample,
+                              struct evsel *evsel,
+                              struct addr_location *al,
+                              struct addr_location *addr_al);
+
 int common_pc(struct scripting_context *context);
 int common_flags(struct scripting_context *context);
 int common_lock_depth(struct scripting_context *context);