]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf script: Move script_spec code to trace-event-scripting.c
authorIan Rogers <irogers@google.com>
Tue, 19 Nov 2024 01:16:31 +0000 (17:16 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 18 Dec 2024 19:24:32 +0000 (16:24 -0300)
The script_spec code is referenced in util/trace-event-scripting but
the list was in builtin-script, accessed via a function that required
a stub function in python.c. Move all the logic to
trace-event-scripting, with lookup and foreach functions exposed for
builtin-script's benefit.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Veronika Molnarova <vmolnaro@redhat.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Link: https://lore.kernel.org/r/20241119011644.971342-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-script.c
tools/perf/util/python.c
tools/perf/util/trace-event-scripting.c
tools/perf/util/trace-event.h

index 7d21a52ad94ecffd0568914e9a95994363804fab..7158669239da68c24f16d2996e7d00469eca3598 100644 (file)
@@ -2961,79 +2961,18 @@ static int __cmd_script(struct perf_script *script)
        return ret;
 }
 
-struct script_spec {
-       struct list_head        node;
-       struct scripting_ops    *ops;
-       char                    spec[];
-};
-
-static LIST_HEAD(script_specs);
-
-static struct script_spec *script_spec__new(const char *spec,
-                                           struct scripting_ops *ops)
+static int list_available_languages_cb(struct scripting_ops *ops, const char *spec)
 {
-       struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1);
-
-       if (s != NULL) {
-               strcpy(s->spec, spec);
-               s->ops = ops;
-       }
-
-       return s;
-}
-
-static void script_spec__add(struct script_spec *s)
-{
-       list_add_tail(&s->node, &script_specs);
-}
-
-static struct script_spec *script_spec__find(const char *spec)
-{
-       struct script_spec *s;
-
-       list_for_each_entry(s, &script_specs, node)
-               if (strcasecmp(s->spec, spec) == 0)
-                       return s;
-       return NULL;
-}
-
-int script_spec_register(const char *spec, struct scripting_ops *ops)
-{
-       struct script_spec *s;
-
-       s = script_spec__find(spec);
-       if (s)
-               return -1;
-
-       s = script_spec__new(spec, ops);
-       if (!s)
-               return -1;
-       else
-               script_spec__add(s);
-
+       fprintf(stderr, "  %-42s [%s]\n", spec, ops->name);
        return 0;
 }
 
-static struct scripting_ops *script_spec__lookup(const char *spec)
-{
-       struct script_spec *s = script_spec__find(spec);
-       if (!s)
-               return NULL;
-
-       return s->ops;
-}
-
 static void list_available_languages(void)
 {
-       struct script_spec *s;
-
        fprintf(stderr, "\n");
        fprintf(stderr, "Scripting language extensions (used in "
                "perf script -s [spec:]script.[spec]):\n\n");
-
-       list_for_each_entry(s, &script_specs, node)
-               fprintf(stderr, "  %-42s [%s]\n", s->spec, s->ops->name);
-
+       script_spec__for_each(&list_available_languages_cb);
        fprintf(stderr, "\n");
 }
 
index 7fc3ec5684c3eb54bef3979679f87a70fc84e149..d157aaa4bb53c0ce825e28de1966b5987d6c97bc 100644 (file)
@@ -1305,11 +1305,6 @@ error:
 /* The following are stubs to avoid dragging in builtin-* objects. */
 /* TODO: move the code out of the builtin-* file into util. */
 
-int script_spec_register(const char *spec __maybe_unused, struct scripting_ops *ops __maybe_unused)
-{
-       return -1;
-}
-
 arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *arch __maybe_unused)
 {
        return NULL;
index a7f0a14c05b6071b9aff471fb306ede662950f01..d8f4b5bce4ad5daa8e70a2d572715feef0d55327 100644 (file)
@@ -24,6 +24,81 @@ unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH;
 
 struct scripting_context *scripting_context;
 
+struct script_spec {
+       struct list_head        node;
+       struct scripting_ops    *ops;
+       char                    spec[];
+};
+
+static LIST_HEAD(script_specs);
+
+static struct script_spec *script_spec__new(const char *spec,
+                                           struct scripting_ops *ops)
+{
+       struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1);
+
+       if (s != NULL) {
+               strcpy(s->spec, spec);
+               s->ops = ops;
+       }
+
+       return s;
+}
+
+static void script_spec__add(struct script_spec *s)
+{
+       list_add_tail(&s->node, &script_specs);
+}
+
+static struct script_spec *script_spec__find(const char *spec)
+{
+       struct script_spec *s;
+
+       list_for_each_entry(s, &script_specs, node)
+               if (strcasecmp(s->spec, spec) == 0)
+                       return s;
+       return NULL;
+}
+
+static int script_spec_register(const char *spec, struct scripting_ops *ops)
+{
+       struct script_spec *s;
+
+       s = script_spec__find(spec);
+       if (s)
+               return -1;
+
+       s = script_spec__new(spec, ops);
+       if (!s)
+               return -1;
+
+       script_spec__add(s);
+       return 0;
+}
+
+struct scripting_ops *script_spec__lookup(const char *spec)
+{
+       struct script_spec *s = script_spec__find(spec);
+
+       if (!s)
+               return NULL;
+
+       return s->ops;
+}
+
+int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec))
+{
+       struct script_spec *s;
+       int ret = 0;
+
+       list_for_each_entry(s, &script_specs, node) {
+               ret = cb(s->ops, s->spec);
+               if (ret)
+                       break;
+       }
+       return ret;
+}
+
 void scripting_context__update(struct scripting_context *c,
                               union perf_event *event,
                               struct perf_sample *sample,
index 2543bf969fddf8be0cdba4efbcd7d667d5841795..4eacf802c65588ad58b99d4e4352f81b78d707c2 100644 (file)
@@ -113,7 +113,8 @@ struct scripting_ops {
 
 extern unsigned int scripting_max_stack;
 
-int script_spec_register(const char *spec, struct scripting_ops *ops);
+struct scripting_ops *script_spec__lookup(const char *spec);
+int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec));
 
 void script_fetch_insn(struct perf_sample *sample, struct thread *thread,
                       struct machine *machine);