blob: 5c9bdd1591a975c2d1f7f028701504f228da70a0 [file] [log] [blame]
Tom Zanussi82d156c2010-01-27 02:27:55 -06001/*
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>
Tom Zanussi82d156c2010-01-27 02:27:55 -060025#include <errno.h>
26
27#include "../perf.h"
28#include "util.h"
29#include "trace-event.h"
30
31struct scripting_context *scripting_context;
32
Adrian Hunterd445dd22014-08-15 22:08:37 +030033static int flush_script_unsupported(void)
34{
35 return 0;
36}
37
Tom Zanussi82d156c2010-01-27 02:27:55 -060038static int stop_script_unsupported(void)
39{
40 return 0;
41}
42
Irina Tirdea1d037ca2012-09-11 01:15:03 +030043static void process_event_unsupported(union perf_event *event __maybe_unused,
44 struct perf_sample *sample __maybe_unused,
45 struct perf_evsel *evsel __maybe_unused,
David Ahern2eaa1b42013-07-18 16:06:15 -060046 struct thread *thread __maybe_unused,
Arnaldo Carvalho de Melocc22e572013-12-19 17:20:06 -030047 struct addr_location *al __maybe_unused)
Tom Zanussi82d156c2010-01-27 02:27:55 -060048{
49}
50
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060051static void print_python_unsupported_msg(void)
52{
53 fprintf(stderr, "Python scripting not supported."
54 " Install libpython and rebuild perf to enable it.\n"
55 "For example:\n # apt-get install python-dev (ubuntu)"
56 "\n # yum install python-devel (Fedora)"
57 "\n etc.\n");
58}
59
Irina Tirdea1d037ca2012-09-11 01:15:03 +030060static int python_start_script_unsupported(const char *script __maybe_unused,
61 int argc __maybe_unused,
62 const char **argv __maybe_unused)
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060063{
64 print_python_unsupported_msg();
65
66 return -1;
67}
68
Irina Tirdea1d037ca2012-09-11 01:15:03 +030069static int python_generate_script_unsupported(struct pevent *pevent
70 __maybe_unused,
71 const char *outfile
72 __maybe_unused)
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060073{
74 print_python_unsupported_msg();
75
76 return -1;
77}
78
79struct scripting_ops python_scripting_unsupported_ops = {
80 .name = "Python",
81 .start_script = python_start_script_unsupported,
Adrian Hunterd445dd22014-08-15 22:08:37 +030082 .flush_script = flush_script_unsupported,
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060083 .stop_script = stop_script_unsupported,
84 .process_event = process_event_unsupported,
85 .generate_script = python_generate_script_unsupported,
86};
87
88static void register_python_scripting(struct scripting_ops *scripting_ops)
89{
90 int err;
91 err = script_spec_register("Python", scripting_ops);
92 if (err)
93 die("error registering Python script extension");
94
95 err = script_spec_register("py", scripting_ops);
96 if (err)
97 die("error registering py script extension");
98
99 scripting_context = malloc(sizeof(struct scripting_context));
100}
101
102#ifdef NO_LIBPYTHON
103void setup_python_scripting(void)
104{
105 register_python_scripting(&python_scripting_unsupported_ops);
106}
107#else
Stephane Eranian0f940cb2010-09-21 00:45:01 +0200108extern struct scripting_ops python_scripting_ops;
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600109
110void setup_python_scripting(void)
111{
112 register_python_scripting(&python_scripting_ops);
113}
114#endif
115
Tom Zanussi82d156c2010-01-27 02:27:55 -0600116static void print_perl_unsupported_msg(void)
117{
118 fprintf(stderr, "Perl scripting not supported."
119 " Install libperl and rebuild perf to enable it.\n"
120 "For example:\n # apt-get install libperl-dev (ubuntu)"
121 "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
122 "\n etc.\n");
123}
124
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300125static int perl_start_script_unsupported(const char *script __maybe_unused,
126 int argc __maybe_unused,
127 const char **argv __maybe_unused)
Tom Zanussi82d156c2010-01-27 02:27:55 -0600128{
129 print_perl_unsupported_msg();
130
131 return -1;
132}
133
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300134static int perl_generate_script_unsupported(struct pevent *pevent
135 __maybe_unused,
136 const char *outfile __maybe_unused)
Tom Zanussi82d156c2010-01-27 02:27:55 -0600137{
138 print_perl_unsupported_msg();
139
140 return -1;
141}
142
143struct scripting_ops perl_scripting_unsupported_ops = {
144 .name = "Perl",
145 .start_script = perl_start_script_unsupported,
Adrian Hunterd445dd22014-08-15 22:08:37 +0300146 .flush_script = flush_script_unsupported,
Tom Zanussi82d156c2010-01-27 02:27:55 -0600147 .stop_script = stop_script_unsupported,
148 .process_event = process_event_unsupported,
149 .generate_script = perl_generate_script_unsupported,
150};
151
152static void register_perl_scripting(struct scripting_ops *scripting_ops)
153{
154 int err;
155 err = script_spec_register("Perl", scripting_ops);
156 if (err)
157 die("error registering Perl script extension");
158
159 err = script_spec_register("pl", scripting_ops);
160 if (err)
161 die("error registering pl script extension");
162
163 scripting_context = malloc(sizeof(struct scripting_context));
164}
165
166#ifdef NO_LIBPERL
167void setup_perl_scripting(void)
168{
169 register_perl_scripting(&perl_scripting_unsupported_ops);
170}
171#else
Stephane Eranian0f940cb2010-09-21 00:45:01 +0200172extern struct scripting_ops perl_scripting_ops;
Tom Zanussi82d156c2010-01-27 02:27:55 -0600173
174void setup_perl_scripting(void)
175{
176 register_perl_scripting(&perl_scripting_ops);
177}
178#endif