1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * trace-event-scripting. Scripting engine common and initialization code.
15 #include "trace-event.h"
16 #include <linux/zalloc.h>
18 struct scripting_context *scripting_context;
20 static int flush_script_unsupported(void)
25 static int stop_script_unsupported(void)
30 static void process_event_unsupported(union perf_event *event __maybe_unused,
31 struct perf_sample *sample __maybe_unused,
32 struct evsel *evsel __maybe_unused,
33 struct addr_location *al __maybe_unused)
37 static void print_python_unsupported_msg(void)
39 fprintf(stderr, "Python scripting not supported."
40 " Install libpython and rebuild perf to enable it.\n"
41 "For example:\n # apt-get install python-dev (ubuntu)"
42 "\n # yum install python-devel (Fedora)"
46 static int python_start_script_unsupported(const char *script __maybe_unused,
47 int argc __maybe_unused,
48 const char **argv __maybe_unused)
50 print_python_unsupported_msg();
55 static int python_generate_script_unsupported(struct tep_handle *pevent
60 print_python_unsupported_msg();
65 struct scripting_ops python_scripting_unsupported_ops = {
67 .start_script = python_start_script_unsupported,
68 .flush_script = flush_script_unsupported,
69 .stop_script = stop_script_unsupported,
70 .process_event = process_event_unsupported,
71 .generate_script = python_generate_script_unsupported,
74 static void register_python_scripting(struct scripting_ops *scripting_ops)
76 if (scripting_context == NULL)
77 scripting_context = malloc(sizeof(*scripting_context));
79 if (scripting_context == NULL ||
80 script_spec_register("Python", scripting_ops) ||
81 script_spec_register("py", scripting_ops)) {
82 pr_err("Error registering Python script extension: disabling it\n");
83 zfree(&scripting_context);
87 #ifndef HAVE_LIBPYTHON_SUPPORT
88 void setup_python_scripting(void)
90 register_python_scripting(&python_scripting_unsupported_ops);
93 extern struct scripting_ops python_scripting_ops;
95 void setup_python_scripting(void)
97 register_python_scripting(&python_scripting_ops);
101 static void print_perl_unsupported_msg(void)
103 fprintf(stderr, "Perl scripting not supported."
104 " Install libperl and rebuild perf to enable it.\n"
105 "For example:\n # apt-get install libperl-dev (ubuntu)"
106 "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
110 static int perl_start_script_unsupported(const char *script __maybe_unused,
111 int argc __maybe_unused,
112 const char **argv __maybe_unused)
114 print_perl_unsupported_msg();
119 static int perl_generate_script_unsupported(struct tep_handle *pevent
121 const char *outfile __maybe_unused)
123 print_perl_unsupported_msg();
128 struct scripting_ops perl_scripting_unsupported_ops = {
130 .start_script = perl_start_script_unsupported,
131 .flush_script = flush_script_unsupported,
132 .stop_script = stop_script_unsupported,
133 .process_event = process_event_unsupported,
134 .generate_script = perl_generate_script_unsupported,
137 static void register_perl_scripting(struct scripting_ops *scripting_ops)
139 if (scripting_context == NULL)
140 scripting_context = malloc(sizeof(*scripting_context));
142 if (scripting_context == NULL ||
143 script_spec_register("Perl", scripting_ops) ||
144 script_spec_register("pl", scripting_ops)) {
145 pr_err("Error registering Perl script extension: disabling it\n");
146 zfree(&scripting_context);
150 #ifndef HAVE_LIBPERL_SUPPORT
151 void setup_perl_scripting(void)
153 register_perl_scripting(&perl_scripting_unsupported_ops);
156 extern struct scripting_ops perl_scripting_ops;
158 void setup_perl_scripting(void)
160 register_perl_scripting(&perl_scripting_ops);