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 #ifdef HAVE_LIBTRACEEVENT
13 #include <traceevent/event-parse.h>
17 #include "trace-event.h"
19 #include <linux/zalloc.h>
20 #include "util/sample.h"
22 struct scripting_context *scripting_context;
24 void scripting_context__update(struct scripting_context *c,
25 union perf_event *event,
26 struct perf_sample *sample,
28 struct addr_location *al,
29 struct addr_location *addr_al)
31 c->event_data = sample->raw_data;
33 #ifdef HAVE_LIBTRACEEVENT
35 c->pevent = evsel->tp_format->tep;
44 static int flush_script_unsupported(void)
49 static int stop_script_unsupported(void)
54 static void process_event_unsupported(union perf_event *event __maybe_unused,
55 struct perf_sample *sample __maybe_unused,
56 struct evsel *evsel __maybe_unused,
57 struct addr_location *al __maybe_unused,
58 struct addr_location *addr_al __maybe_unused)
62 static void print_python_unsupported_msg(void)
64 fprintf(stderr, "Python scripting not supported."
65 " Install libpython and rebuild perf to enable it.\n"
66 "For example:\n # apt-get install python-dev (ubuntu)"
67 "\n # yum install python-devel (Fedora)"
71 static int python_start_script_unsupported(const char *script __maybe_unused,
72 int argc __maybe_unused,
73 const char **argv __maybe_unused,
74 struct perf_session *session __maybe_unused)
76 print_python_unsupported_msg();
81 static int python_generate_script_unsupported(struct tep_handle *pevent
86 print_python_unsupported_msg();
91 struct scripting_ops python_scripting_unsupported_ops = {
94 .start_script = python_start_script_unsupported,
95 .flush_script = flush_script_unsupported,
96 .stop_script = stop_script_unsupported,
97 .process_event = process_event_unsupported,
98 .generate_script = python_generate_script_unsupported,
101 static void register_python_scripting(struct scripting_ops *scripting_ops)
103 if (scripting_context == NULL)
104 scripting_context = malloc(sizeof(*scripting_context));
106 if (scripting_context == NULL ||
107 script_spec_register("Python", scripting_ops) ||
108 script_spec_register("py", scripting_ops)) {
109 pr_err("Error registering Python script extension: disabling it\n");
110 zfree(&scripting_context);
114 #ifndef HAVE_LIBPYTHON_SUPPORT
115 void setup_python_scripting(void)
117 register_python_scripting(&python_scripting_unsupported_ops);
120 extern struct scripting_ops python_scripting_ops;
122 void setup_python_scripting(void)
124 register_python_scripting(&python_scripting_ops);
128 #ifdef HAVE_LIBTRACEEVENT
129 static void print_perl_unsupported_msg(void)
131 fprintf(stderr, "Perl scripting not supported."
132 " Install libperl and rebuild perf to enable it.\n"
133 "For example:\n # apt-get install libperl-dev (ubuntu)"
134 "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
138 static int perl_start_script_unsupported(const char *script __maybe_unused,
139 int argc __maybe_unused,
140 const char **argv __maybe_unused,
141 struct perf_session *session __maybe_unused)
143 print_perl_unsupported_msg();
148 static int perl_generate_script_unsupported(struct tep_handle *pevent
150 const char *outfile __maybe_unused)
152 print_perl_unsupported_msg();
157 struct scripting_ops perl_scripting_unsupported_ops = {
160 .start_script = perl_start_script_unsupported,
161 .flush_script = flush_script_unsupported,
162 .stop_script = stop_script_unsupported,
163 .process_event = process_event_unsupported,
164 .generate_script = perl_generate_script_unsupported,
167 static void register_perl_scripting(struct scripting_ops *scripting_ops)
169 if (scripting_context == NULL)
170 scripting_context = malloc(sizeof(*scripting_context));
172 if (scripting_context == NULL ||
173 script_spec_register("Perl", scripting_ops) ||
174 script_spec_register("pl", scripting_ops)) {
175 pr_err("Error registering Perl script extension: disabling it\n");
176 zfree(&scripting_context);
180 #ifndef HAVE_LIBPERL_SUPPORT
181 void setup_perl_scripting(void)
183 register_perl_scripting(&perl_scripting_unsupported_ops);
186 extern struct scripting_ops perl_scripting_ops;
188 void setup_perl_scripting(void)
190 register_perl_scripting(&perl_scripting_ops);