Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * trace-event-scripting. Scripting engine common and initialization code.
4 *
5 * Copyright (C) 2009-2010 Tom Zanussi <tzanussi@gmail.com>
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <errno.h>
12
13#include "debug.h"
14#include "trace-event.h"
15#include <linux/zalloc.h>
16
17struct scripting_context *scripting_context;
18
19static int flush_script_unsupported(void)
20{
21 return 0;
22}
23
24static int stop_script_unsupported(void)
25{
26 return 0;
27}
28
29static void process_event_unsupported(union perf_event *event __maybe_unused,
30 struct perf_sample *sample __maybe_unused,
31 struct evsel *evsel __maybe_unused,
32 struct addr_location *al __maybe_unused)
33{
34}
35
36static void print_python_unsupported_msg(void)
37{
38 fprintf(stderr, "Python scripting not supported."
39 " Install libpython and rebuild perf to enable it.\n"
40 "For example:\n # apt-get install python-dev (ubuntu)"
41 "\n # yum install python-devel (Fedora)"
42 "\n etc.\n");
43}
44
45static int python_start_script_unsupported(const char *script __maybe_unused,
46 int argc __maybe_unused,
47 const char **argv __maybe_unused)
48{
49 print_python_unsupported_msg();
50
51 return -1;
52}
53
54static int python_generate_script_unsupported(struct tep_handle *pevent
55 __maybe_unused,
56 const char *outfile
57 __maybe_unused)
58{
59 print_python_unsupported_msg();
60
61 return -1;
62}
63
64struct scripting_ops python_scripting_unsupported_ops = {
65 .name = "Python",
66 .start_script = python_start_script_unsupported,
67 .flush_script = flush_script_unsupported,
68 .stop_script = stop_script_unsupported,
69 .process_event = process_event_unsupported,
70 .generate_script = python_generate_script_unsupported,
71};
72
73static void register_python_scripting(struct scripting_ops *scripting_ops)
74{
75 if (scripting_context == NULL)
76 scripting_context = malloc(sizeof(*scripting_context));
77
78 if (scripting_context == NULL ||
79 script_spec_register("Python", scripting_ops) ||
80 script_spec_register("py", scripting_ops)) {
81 pr_err("Error registering Python script extension: disabling it\n");
82 zfree(&scripting_context);
83 }
84}
85
86#ifndef HAVE_LIBPYTHON_SUPPORT
87void setup_python_scripting(void)
88{
89 register_python_scripting(&python_scripting_unsupported_ops);
90}
91#else
92extern struct scripting_ops python_scripting_ops;
93
94void setup_python_scripting(void)
95{
96 register_python_scripting(&python_scripting_ops);
97}
98#endif
99
100static void print_perl_unsupported_msg(void)
101{
102 fprintf(stderr, "Perl scripting not supported."
103 " Install libperl and rebuild perf to enable it.\n"
104 "For example:\n # apt-get install libperl-dev (ubuntu)"
105 "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
106 "\n etc.\n");
107}
108
109static int perl_start_script_unsupported(const char *script __maybe_unused,
110 int argc __maybe_unused,
111 const char **argv __maybe_unused)
112{
113 print_perl_unsupported_msg();
114
115 return -1;
116}
117
118static int perl_generate_script_unsupported(struct tep_handle *pevent
119 __maybe_unused,
120 const char *outfile __maybe_unused)
121{
122 print_perl_unsupported_msg();
123
124 return -1;
125}
126
127struct scripting_ops perl_scripting_unsupported_ops = {
128 .name = "Perl",
129 .start_script = perl_start_script_unsupported,
130 .flush_script = flush_script_unsupported,
131 .stop_script = stop_script_unsupported,
132 .process_event = process_event_unsupported,
133 .generate_script = perl_generate_script_unsupported,
134};
135
136static void register_perl_scripting(struct scripting_ops *scripting_ops)
137{
138 if (scripting_context == NULL)
139 scripting_context = malloc(sizeof(*scripting_context));
140
141 if (scripting_context == NULL ||
142 script_spec_register("Perl", scripting_ops) ||
143 script_spec_register("pl", scripting_ops)) {
144 pr_err("Error registering Perl script extension: disabling it\n");
145 zfree(&scripting_context);
146 }
147}
148
149#ifndef HAVE_LIBPERL_SUPPORT
150void setup_perl_scripting(void)
151{
152 register_perl_scripting(&perl_scripting_unsupported_ops);
153}
154#else
155extern struct scripting_ops perl_scripting_ops;
156
157void setup_perl_scripting(void)
158{
159 register_perl_scripting(&perl_scripting_ops);
160}
161#endif
1/*
2 * trace-event-scripting. Scripting engine common and initialization code.
3 *
4 * Copyright (C) 2009-2010 Tom Zanussi <tzanussi@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <errno.h>
26
27#include "../perf.h"
28#include "util.h"
29#include "trace-event.h"
30
31struct scripting_context *scripting_context;
32
33static int stop_script_unsupported(void)
34{
35 return 0;
36}
37
38static void process_event_unsupported(union perf_event *event __unused,
39 struct perf_sample *sample __unused,
40 struct perf_evsel *evsel __unused,
41 struct machine *machine __unused,
42 struct thread *thread __unused)
43{
44}
45
46static void print_python_unsupported_msg(void)
47{
48 fprintf(stderr, "Python scripting not supported."
49 " Install libpython and rebuild perf to enable it.\n"
50 "For example:\n # apt-get install python-dev (ubuntu)"
51 "\n # yum install python-devel (Fedora)"
52 "\n etc.\n");
53}
54
55static int python_start_script_unsupported(const char *script __unused,
56 int argc __unused,
57 const char **argv __unused)
58{
59 print_python_unsupported_msg();
60
61 return -1;
62}
63
64static int python_generate_script_unsupported(const char *outfile __unused)
65{
66 print_python_unsupported_msg();
67
68 return -1;
69}
70
71struct scripting_ops python_scripting_unsupported_ops = {
72 .name = "Python",
73 .start_script = python_start_script_unsupported,
74 .stop_script = stop_script_unsupported,
75 .process_event = process_event_unsupported,
76 .generate_script = python_generate_script_unsupported,
77};
78
79static void register_python_scripting(struct scripting_ops *scripting_ops)
80{
81 int err;
82 err = script_spec_register("Python", scripting_ops);
83 if (err)
84 die("error registering Python script extension");
85
86 err = script_spec_register("py", scripting_ops);
87 if (err)
88 die("error registering py script extension");
89
90 scripting_context = malloc(sizeof(struct scripting_context));
91}
92
93#ifdef NO_LIBPYTHON
94void setup_python_scripting(void)
95{
96 register_python_scripting(&python_scripting_unsupported_ops);
97}
98#else
99extern struct scripting_ops python_scripting_ops;
100
101void setup_python_scripting(void)
102{
103 register_python_scripting(&python_scripting_ops);
104}
105#endif
106
107static void print_perl_unsupported_msg(void)
108{
109 fprintf(stderr, "Perl scripting not supported."
110 " Install libperl and rebuild perf to enable it.\n"
111 "For example:\n # apt-get install libperl-dev (ubuntu)"
112 "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
113 "\n etc.\n");
114}
115
116static int perl_start_script_unsupported(const char *script __unused,
117 int argc __unused,
118 const char **argv __unused)
119{
120 print_perl_unsupported_msg();
121
122 return -1;
123}
124
125static int perl_generate_script_unsupported(const char *outfile __unused)
126{
127 print_perl_unsupported_msg();
128
129 return -1;
130}
131
132struct scripting_ops perl_scripting_unsupported_ops = {
133 .name = "Perl",
134 .start_script = perl_start_script_unsupported,
135 .stop_script = stop_script_unsupported,
136 .process_event = process_event_unsupported,
137 .generate_script = perl_generate_script_unsupported,
138};
139
140static void register_perl_scripting(struct scripting_ops *scripting_ops)
141{
142 int err;
143 err = script_spec_register("Perl", scripting_ops);
144 if (err)
145 die("error registering Perl script extension");
146
147 err = script_spec_register("pl", scripting_ops);
148 if (err)
149 die("error registering pl script extension");
150
151 scripting_context = malloc(sizeof(struct scripting_context));
152}
153
154#ifdef NO_LIBPERL
155void setup_perl_scripting(void)
156{
157 register_perl_scripting(&perl_scripting_unsupported_ops);
158}
159#else
160extern struct scripting_ops perl_scripting_ops;
161
162void setup_perl_scripting(void)
163{
164 register_perl_scripting(&perl_scripting_ops);
165}
166#endif