Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf script: Move script_spec code to trace-event-scripting.c

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>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
04051b4a 9557d156

+80 -70
+3 -64
tools/perf/builtin-script.c
··· 2961 2961 return ret; 2962 2962 } 2963 2963 2964 - struct script_spec { 2965 - struct list_head node; 2966 - struct scripting_ops *ops; 2967 - char spec[]; 2968 - }; 2969 - 2970 - static LIST_HEAD(script_specs); 2971 - 2972 - static struct script_spec *script_spec__new(const char *spec, 2973 - struct scripting_ops *ops) 2964 + static int list_available_languages_cb(struct scripting_ops *ops, const char *spec) 2974 2965 { 2975 - struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1); 2976 - 2977 - if (s != NULL) { 2978 - strcpy(s->spec, spec); 2979 - s->ops = ops; 2980 - } 2981 - 2982 - return s; 2983 - } 2984 - 2985 - static void script_spec__add(struct script_spec *s) 2986 - { 2987 - list_add_tail(&s->node, &script_specs); 2988 - } 2989 - 2990 - static struct script_spec *script_spec__find(const char *spec) 2991 - { 2992 - struct script_spec *s; 2993 - 2994 - list_for_each_entry(s, &script_specs, node) 2995 - if (strcasecmp(s->spec, spec) == 0) 2996 - return s; 2997 - return NULL; 2998 - } 2999 - 3000 - int script_spec_register(const char *spec, struct scripting_ops *ops) 3001 - { 3002 - struct script_spec *s; 3003 - 3004 - s = script_spec__find(spec); 3005 - if (s) 3006 - return -1; 3007 - 3008 - s = script_spec__new(spec, ops); 3009 - if (!s) 3010 - return -1; 3011 - else 3012 - script_spec__add(s); 3013 - 2966 + fprintf(stderr, " %-42s [%s]\n", spec, ops->name); 3014 2967 return 0; 3015 - } 3016 - 3017 - static struct scripting_ops *script_spec__lookup(const char *spec) 3018 - { 3019 - struct script_spec *s = script_spec__find(spec); 3020 - if (!s) 3021 - return NULL; 3022 - 3023 - return s->ops; 3024 2968 } 3025 2969 3026 2970 static void list_available_languages(void) 3027 2971 { 3028 - struct script_spec *s; 3029 - 3030 2972 fprintf(stderr, "\n"); 3031 2973 fprintf(stderr, "Scripting language extensions (used in " 3032 2974 "perf script -s [spec:]script.[spec]):\n\n"); 3033 - 3034 - list_for_each_entry(s, &script_specs, node) 3035 - fprintf(stderr, " %-42s [%s]\n", s->spec, s->ops->name); 3036 - 2975 + script_spec__for_each(&list_available_languages_cb); 3037 2976 fprintf(stderr, "\n"); 3038 2977 } 3039 2978
-5
tools/perf/util/python.c
··· 1305 1305 /* The following are stubs to avoid dragging in builtin-* objects. */ 1306 1306 /* TODO: move the code out of the builtin-* file into util. */ 1307 1307 1308 - int script_spec_register(const char *spec __maybe_unused, struct scripting_ops *ops __maybe_unused) 1309 - { 1310 - return -1; 1311 - } 1312 - 1313 1308 arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *arch __maybe_unused) 1314 1309 { 1315 1310 return NULL;
+75
tools/perf/util/trace-event-scripting.c
··· 24 24 25 25 struct scripting_context *scripting_context; 26 26 27 + struct script_spec { 28 + struct list_head node; 29 + struct scripting_ops *ops; 30 + char spec[]; 31 + }; 32 + 33 + static LIST_HEAD(script_specs); 34 + 35 + static struct script_spec *script_spec__new(const char *spec, 36 + struct scripting_ops *ops) 37 + { 38 + struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1); 39 + 40 + if (s != NULL) { 41 + strcpy(s->spec, spec); 42 + s->ops = ops; 43 + } 44 + 45 + return s; 46 + } 47 + 48 + static void script_spec__add(struct script_spec *s) 49 + { 50 + list_add_tail(&s->node, &script_specs); 51 + } 52 + 53 + static struct script_spec *script_spec__find(const char *spec) 54 + { 55 + struct script_spec *s; 56 + 57 + list_for_each_entry(s, &script_specs, node) 58 + if (strcasecmp(s->spec, spec) == 0) 59 + return s; 60 + return NULL; 61 + } 62 + 63 + static int script_spec_register(const char *spec, struct scripting_ops *ops) 64 + { 65 + struct script_spec *s; 66 + 67 + s = script_spec__find(spec); 68 + if (s) 69 + return -1; 70 + 71 + s = script_spec__new(spec, ops); 72 + if (!s) 73 + return -1; 74 + 75 + script_spec__add(s); 76 + return 0; 77 + } 78 + 79 + struct scripting_ops *script_spec__lookup(const char *spec) 80 + { 81 + struct script_spec *s = script_spec__find(spec); 82 + 83 + if (!s) 84 + return NULL; 85 + 86 + return s->ops; 87 + } 88 + 89 + int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec)) 90 + { 91 + struct script_spec *s; 92 + int ret = 0; 93 + 94 + list_for_each_entry(s, &script_specs, node) { 95 + ret = cb(s->ops, s->spec); 96 + if (ret) 97 + break; 98 + } 99 + return ret; 100 + } 101 + 27 102 void scripting_context__update(struct scripting_context *c, 28 103 union perf_event *event, 29 104 struct perf_sample *sample,
+2 -1
tools/perf/util/trace-event.h
··· 113 113 114 114 extern unsigned int scripting_max_stack; 115 115 116 - int script_spec_register(const char *spec, struct scripting_ops *ops); 116 + struct scripting_ops *script_spec__lookup(const char *spec); 117 + int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec)); 117 118 118 119 void script_fetch_insn(struct perf_sample *sample, struct thread *thread, 119 120 struct machine *machine);