]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - tools/perf/util/trace-event-scripting.c
UBUNTU: Ubuntu-5.15.0-39.42
[mirror_ubuntu-jammy-kernel.git] / tools / perf / util / trace-event-scripting.c
CommitLineData
1a59d1b8 1// SPDX-License-Identifier: GPL-2.0-or-later
82d156cd
TZ
2/*
3 * trace-event-scripting. Scripting engine common and initialization code.
4 *
5 * Copyright (C) 2009-2010 Tom Zanussi <tzanussi@gmail.com>
82d156cd
TZ
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
82d156cd
TZ
11#include <errno.h>
12
9a8860bb 13#include "debug.h"
82d156cd 14#include "trace-event.h"
cac30400
AH
15#include "event.h"
16#include "evsel.h"
7f7c536f 17#include <linux/zalloc.h>
82d156cd
TZ
18
19struct scripting_context *scripting_context;
20
cac30400
AH
21void scripting_context__update(struct scripting_context *c,
22 union perf_event *event,
23 struct perf_sample *sample,
24 struct evsel *evsel,
25 struct addr_location *al,
26 struct addr_location *addr_al)
27{
28 c->event_data = sample->raw_data;
29 if (evsel->tp_format)
30 c->pevent = evsel->tp_format->tep;
31 else
32 c->pevent = NULL;
33 c->event = event;
34 c->sample = sample;
35 c->evsel = evsel;
36 c->al = al;
37 c->addr_al = addr_al;
38}
39
d445dd2a
AH
40static int flush_script_unsupported(void)
41{
42 return 0;
43}
44
82d156cd
TZ
45static int stop_script_unsupported(void)
46{
47 return 0;
48}
49
1d037ca1
IT
50static void process_event_unsupported(union perf_event *event __maybe_unused,
51 struct perf_sample *sample __maybe_unused,
32dcd021 52 struct evsel *evsel __maybe_unused,
3f8e009e
AH
53 struct addr_location *al __maybe_unused,
54 struct addr_location *addr_al __maybe_unused)
82d156cd
TZ
55{
56}
57
7e4b21b8
TZ
58static void print_python_unsupported_msg(void)
59{
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)"
64 "\n etc.\n");
65}
66
1d037ca1
IT
67static int python_start_script_unsupported(const char *script __maybe_unused,
68 int argc __maybe_unused,
67e50ce0
AH
69 const char **argv __maybe_unused,
70 struct perf_session *session __maybe_unused)
7e4b21b8
TZ
71{
72 print_python_unsupported_msg();
73
74 return -1;
75}
76
096177a8 77static int python_generate_script_unsupported(struct tep_handle *pevent
1d037ca1
IT
78 __maybe_unused,
79 const char *outfile
80 __maybe_unused)
7e4b21b8
TZ
81{
82 print_python_unsupported_msg();
83
84 return -1;
85}
86
87struct scripting_ops python_scripting_unsupported_ops = {
88 .name = "Python",
6ea4b5db 89 .dirname = "python",
7e4b21b8 90 .start_script = python_start_script_unsupported,
d445dd2a 91 .flush_script = flush_script_unsupported,
7e4b21b8
TZ
92 .stop_script = stop_script_unsupported,
93 .process_event = process_event_unsupported,
94 .generate_script = python_generate_script_unsupported,
95};
96
97static void register_python_scripting(struct scripting_ops *scripting_ops)
98{
cf346d5b
ACM
99 if (scripting_context == NULL)
100 scripting_context = malloc(sizeof(*scripting_context));
9a8860bb
ACM
101
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);
107 }
7e4b21b8
TZ
108}
109
90ce61b9 110#ifndef HAVE_LIBPYTHON_SUPPORT
7e4b21b8
TZ
111void setup_python_scripting(void)
112{
113 register_python_scripting(&python_scripting_unsupported_ops);
114}
115#else
0f940cb7 116extern struct scripting_ops python_scripting_ops;
7e4b21b8
TZ
117
118void setup_python_scripting(void)
119{
120 register_python_scripting(&python_scripting_ops);
121}
122#endif
123
82d156cd
TZ
124static void print_perl_unsupported_msg(void)
125{
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)"
130 "\n etc.\n");
131}
132
1d037ca1
IT
133static int perl_start_script_unsupported(const char *script __maybe_unused,
134 int argc __maybe_unused,
67e50ce0
AH
135 const char **argv __maybe_unused,
136 struct perf_session *session __maybe_unused)
82d156cd
TZ
137{
138 print_perl_unsupported_msg();
139
140 return -1;
141}
142
096177a8 143static int perl_generate_script_unsupported(struct tep_handle *pevent
1d037ca1
IT
144 __maybe_unused,
145 const char *outfile __maybe_unused)
82d156cd
TZ
146{
147 print_perl_unsupported_msg();
148
149 return -1;
150}
151
152struct scripting_ops perl_scripting_unsupported_ops = {
153 .name = "Perl",
6ea4b5db 154 .dirname = "perl",
82d156cd 155 .start_script = perl_start_script_unsupported,
d445dd2a 156 .flush_script = flush_script_unsupported,
82d156cd
TZ
157 .stop_script = stop_script_unsupported,
158 .process_event = process_event_unsupported,
159 .generate_script = perl_generate_script_unsupported,
160};
161
162static void register_perl_scripting(struct scripting_ops *scripting_ops)
163{
cf346d5b
ACM
164 if (scripting_context == NULL)
165 scripting_context = malloc(sizeof(*scripting_context));
9a8860bb
ACM
166
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);
172 }
82d156cd
TZ
173}
174
90ce61b9 175#ifndef HAVE_LIBPERL_SUPPORT
82d156cd
TZ
176void setup_perl_scripting(void)
177{
178 register_perl_scripting(&perl_scripting_unsupported_ops);
179}
180#else
0f940cb7 181extern struct scripting_ops perl_scripting_ops;
82d156cd
TZ
182
183void setup_perl_scripting(void)
184{
185 register_perl_scripting(&perl_scripting_ops);
186}
187#endif