Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / perf / util / trace-event-scripting.c
blob5596fcda2c1083b3dfcf001f9810c99af64a16a3
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * trace-event-scripting. Scripting engine common and initialization code.
5 * Copyright (C) 2009-2010 Tom Zanussi <tzanussi@gmail.com>
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <errno.h>
12 #ifdef HAVE_LIBTRACEEVENT
13 #include <event-parse.h>
14 #endif
16 #include "debug.h"
17 #include "trace-event.h"
18 #include "evsel.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,
27 struct evsel *evsel,
28 struct addr_location *al,
29 struct addr_location *addr_al)
31 c->event_data = sample->raw_data;
32 c->pevent = NULL;
33 #ifdef HAVE_LIBTRACEEVENT
34 if (evsel->tp_format)
35 c->pevent = evsel->tp_format->tep;
36 #endif
37 c->event = event;
38 c->sample = sample;
39 c->evsel = evsel;
40 c->al = al;
41 c->addr_al = addr_al;
44 static int flush_script_unsupported(void)
46 return 0;
49 static int stop_script_unsupported(void)
51 return 0;
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)"
68 "\n etc.\n");
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();
78 return -1;
81 static int python_generate_script_unsupported(struct tep_handle *pevent
82 __maybe_unused,
83 const char *outfile
84 __maybe_unused)
86 print_python_unsupported_msg();
88 return -1;
91 struct scripting_ops python_scripting_unsupported_ops = {
92 .name = "Python",
93 .dirname = "python",
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);
119 #else
120 extern struct scripting_ops python_scripting_ops;
122 void setup_python_scripting(void)
124 register_python_scripting(&python_scripting_ops);
126 #endif
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)"
135 "\n etc.\n");
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();
145 return -1;
148 static int perl_generate_script_unsupported(struct tep_handle *pevent
149 __maybe_unused,
150 const char *outfile __maybe_unused)
152 print_perl_unsupported_msg();
154 return -1;
157 struct scripting_ops perl_scripting_unsupported_ops = {
158 .name = "Perl",
159 .dirname = "perl",
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);
185 #else
186 extern struct scripting_ops perl_scripting_ops;
188 void setup_perl_scripting(void)
190 register_perl_scripting(&perl_scripting_ops);
192 #endif
193 #endif