1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * trace-event-scripting. Scripting engine common and initialization code.
5 * Copyright (C) 2009-2010 Tom Zanussi <tzanussi@gmail.com>
14 #include "trace-event.h"
17 #include <linux/zalloc.h>
19 struct scripting_context *scripting_context;
21 void scripting_context__update(struct scripting_context *c,
22 union perf_event *event,
23 struct perf_sample *sample,
25 struct addr_location *al,
26 struct addr_location *addr_al)
28 c->event_data = sample->raw_data;
30 c->pevent = evsel->tp_format->tep;
40 static int flush_script_unsupported(void)
45 static int stop_script_unsupported(void)
50 static void process_event_unsupported(union perf_event *event __maybe_unused,
51 struct perf_sample *sample __maybe_unused,
52 struct evsel *evsel __maybe_unused,
53 struct addr_location *al __maybe_unused,
54 struct addr_location *addr_al __maybe_unused)
58 static void print_python_unsupported_msg(void)
60 fprintf(stderr, "Python scripting not supported."
61 " Install libpython and rebuild perf to enable it.\n"
62 "For example:\n # apt-get install python-dev (ubuntu)"
63 "\n # yum install python-devel (Fedora)"
67 static int python_start_script_unsupported(const char *script __maybe_unused,
68 int argc __maybe_unused,
69 const char **argv __maybe_unused,
70 struct perf_session *session __maybe_unused)
72 print_python_unsupported_msg();
77 static int python_generate_script_unsupported(struct tep_handle *pevent
82 print_python_unsupported_msg();
87 struct scripting_ops python_scripting_unsupported_ops = {
90 .start_script = python_start_script_unsupported,
91 .flush_script = flush_script_unsupported,
92 .stop_script = stop_script_unsupported,
93 .process_event = process_event_unsupported,
94 .generate_script = python_generate_script_unsupported,
97 static void register_python_scripting(struct scripting_ops *scripting_ops)
99 if (scripting_context == NULL)
100 scripting_context = malloc(sizeof(*scripting_context));
102 if (scripting_context == NULL ||
103 script_spec_register("Python", scripting_ops) ||
104 script_spec_register("py", scripting_ops)) {
105 pr_err("Error registering Python script extension: disabling it\n");
106 zfree(&scripting_context);
110 #ifndef HAVE_LIBPYTHON_SUPPORT
111 void setup_python_scripting(void)
113 register_python_scripting(&python_scripting_unsupported_ops);
116 extern struct scripting_ops python_scripting_ops;
118 void setup_python_scripting(void)
120 register_python_scripting(&python_scripting_ops);
124 static void print_perl_unsupported_msg(void)
126 fprintf(stderr, "Perl scripting not supported."
127 " Install libperl and rebuild perf to enable it.\n"
128 "For example:\n # apt-get install libperl-dev (ubuntu)"
129 "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
133 static int perl_start_script_unsupported(const char *script __maybe_unused,
134 int argc __maybe_unused,
135 const char **argv __maybe_unused,
136 struct perf_session *session __maybe_unused)
138 print_perl_unsupported_msg();
143 static int perl_generate_script_unsupported(struct tep_handle *pevent
145 const char *outfile __maybe_unused)
147 print_perl_unsupported_msg();
152 struct scripting_ops perl_scripting_unsupported_ops = {
155 .start_script = perl_start_script_unsupported,
156 .flush_script = flush_script_unsupported,
157 .stop_script = stop_script_unsupported,
158 .process_event = process_event_unsupported,
159 .generate_script = perl_generate_script_unsupported,
162 static void register_perl_scripting(struct scripting_ops *scripting_ops)
164 if (scripting_context == NULL)
165 scripting_context = malloc(sizeof(*scripting_context));
167 if (scripting_context == NULL ||
168 script_spec_register("Perl", scripting_ops) ||
169 script_spec_register("pl", scripting_ops)) {
170 pr_err("Error registering Perl script extension: disabling it\n");
171 zfree(&scripting_context);
175 #ifndef HAVE_LIBPERL_SUPPORT
176 void setup_perl_scripting(void)
178 register_perl_scripting(&perl_scripting_unsupported_ops);
181 extern struct scripting_ops perl_scripting_ops;
183 void setup_perl_scripting(void)
185 register_perl_scripting(&perl_scripting_ops);