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>
12 #include <traceevent/event-parse.h>
15 #include "trace-event.h"
17 #include <linux/zalloc.h>
18 #include "util/sample.h"
20 struct scripting_context *scripting_context;
22 void scripting_context__update(struct scripting_context *c,
23 union perf_event *event,
24 struct perf_sample *sample,
26 struct addr_location *al,
27 struct addr_location *addr_al)
29 c->event_data = sample->raw_data;
31 c->pevent = evsel->tp_format->tep;
41 static int flush_script_unsupported(void)
46 static int stop_script_unsupported(void)
51 static void process_event_unsupported(union perf_event *event __maybe_unused,
52 struct perf_sample *sample __maybe_unused,
53 struct evsel *evsel __maybe_unused,
54 struct addr_location *al __maybe_unused,
55 struct addr_location *addr_al __maybe_unused)
59 static void print_python_unsupported_msg(void)
61 fprintf(stderr, "Python scripting not supported."
62 " Install libpython and rebuild perf to enable it.\n"
63 "For example:\n # apt-get install python-dev (ubuntu)"
64 "\n # yum install python-devel (Fedora)"
68 static int python_start_script_unsupported(const char *script __maybe_unused,
69 int argc __maybe_unused,
70 const char **argv __maybe_unused,
71 struct perf_session *session __maybe_unused)
73 print_python_unsupported_msg();
78 static int python_generate_script_unsupported(struct tep_handle *pevent
83 print_python_unsupported_msg();
88 struct scripting_ops python_scripting_unsupported_ops = {
91 .start_script = python_start_script_unsupported,
92 .flush_script = flush_script_unsupported,
93 .stop_script = stop_script_unsupported,
94 .process_event = process_event_unsupported,
95 .generate_script = python_generate_script_unsupported,
98 static void register_python_scripting(struct scripting_ops *scripting_ops)
100 if (scripting_context == NULL)
101 scripting_context = malloc(sizeof(*scripting_context));
103 if (scripting_context == NULL ||
104 script_spec_register("Python", scripting_ops) ||
105 script_spec_register("py", scripting_ops)) {
106 pr_err("Error registering Python script extension: disabling it\n");
107 zfree(&scripting_context);
111 #ifndef HAVE_LIBPYTHON_SUPPORT
112 void setup_python_scripting(void)
114 register_python_scripting(&python_scripting_unsupported_ops);
117 extern struct scripting_ops python_scripting_ops;
119 void setup_python_scripting(void)
121 register_python_scripting(&python_scripting_ops);
125 static void print_perl_unsupported_msg(void)
127 fprintf(stderr, "Perl scripting not supported."
128 " Install libperl and rebuild perf to enable it.\n"
129 "For example:\n # apt-get install libperl-dev (ubuntu)"
130 "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
134 static int perl_start_script_unsupported(const char *script __maybe_unused,
135 int argc __maybe_unused,
136 const char **argv __maybe_unused,
137 struct perf_session *session __maybe_unused)
139 print_perl_unsupported_msg();
144 static int perl_generate_script_unsupported(struct tep_handle *pevent
146 const char *outfile __maybe_unused)
148 print_perl_unsupported_msg();
153 struct scripting_ops perl_scripting_unsupported_ops = {
156 .start_script = perl_start_script_unsupported,
157 .flush_script = flush_script_unsupported,
158 .stop_script = stop_script_unsupported,
159 .process_event = process_event_unsupported,
160 .generate_script = perl_generate_script_unsupported,
163 static void register_perl_scripting(struct scripting_ops *scripting_ops)
165 if (scripting_context == NULL)
166 scripting_context = malloc(sizeof(*scripting_context));
168 if (scripting_context == NULL ||
169 script_spec_register("Perl", scripting_ops) ||
170 script_spec_register("pl", scripting_ops)) {
171 pr_err("Error registering Perl script extension: disabling it\n");
172 zfree(&scripting_context);
176 #ifndef HAVE_LIBPERL_SUPPORT
177 void setup_perl_scripting(void)
179 register_perl_scripting(&perl_scripting_unsupported_ops);
182 extern struct scripting_ops perl_scripting_ops;
184 void setup_perl_scripting(void)
186 register_perl_scripting(&perl_scripting_ops);