blob: 95199e4eea978c3961a86e5e2439e61b6a3ef8a1 [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
33static int stop_script_unsupported(void)
34{
35 return 0;
36}
37
Irina Tirdea1d037ca2012-09-11 01:15:03 +030038static void process_event_unsupported(union perf_event *event __maybe_unused,
39 struct perf_sample *sample __maybe_unused,
40 struct perf_evsel *evsel __maybe_unused,
41 struct machine *machine __maybe_unused,
David Ahern2eaa1b42013-07-18 16:06:15 -060042 struct thread *thread __maybe_unused,
43 struct addr_location *al __maybe_unused)
Tom Zanussi82d156c2010-01-27 02:27:55 -060044{
45}
46
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060047static void print_python_unsupported_msg(void)
48{
49 fprintf(stderr, "Python scripting not supported."
50 " Install libpython and rebuild perf to enable it.\n"
51 "For example:\n # apt-get install python-dev (ubuntu)"
52 "\n # yum install python-devel (Fedora)"
53 "\n etc.\n");
54}
55
Irina Tirdea1d037ca2012-09-11 01:15:03 +030056static int python_start_script_unsupported(const char *script __maybe_unused,
57 int argc __maybe_unused,
58 const char **argv __maybe_unused)
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060059{
60 print_python_unsupported_msg();
61
62 return -1;
63}
64
Irina Tirdea1d037ca2012-09-11 01:15:03 +030065static int python_generate_script_unsupported(struct pevent *pevent
66 __maybe_unused,
67 const char *outfile
68 __maybe_unused)
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060069{
70 print_python_unsupported_msg();
71
72 return -1;
73}
74
75struct scripting_ops python_scripting_unsupported_ops = {
76 .name = "Python",
77 .start_script = python_start_script_unsupported,
78 .stop_script = stop_script_unsupported,
79 .process_event = process_event_unsupported,
80 .generate_script = python_generate_script_unsupported,
81};
82
83static void register_python_scripting(struct scripting_ops *scripting_ops)
84{
85 int err;
86 err = script_spec_register("Python", scripting_ops);
87 if (err)
88 die("error registering Python script extension");
89
90 err = script_spec_register("py", scripting_ops);
91 if (err)
92 die("error registering py script extension");
93
94 scripting_context = malloc(sizeof(struct scripting_context));
95}
96
97#ifdef NO_LIBPYTHON
98void setup_python_scripting(void)
99{
100 register_python_scripting(&python_scripting_unsupported_ops);
101}
102#else
Stephane Eranian0f940cb2010-09-21 00:45:01 +0200103extern struct scripting_ops python_scripting_ops;
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600104
105void setup_python_scripting(void)
106{
107 register_python_scripting(&python_scripting_ops);
108}
109#endif
110
Tom Zanussi82d156c2010-01-27 02:27:55 -0600111static void print_perl_unsupported_msg(void)
112{
113 fprintf(stderr, "Perl scripting not supported."
114 " Install libperl and rebuild perf to enable it.\n"
115 "For example:\n # apt-get install libperl-dev (ubuntu)"
116 "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
117 "\n etc.\n");
118}
119
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300120static int perl_start_script_unsupported(const char *script __maybe_unused,
121 int argc __maybe_unused,
122 const char **argv __maybe_unused)
Tom Zanussi82d156c2010-01-27 02:27:55 -0600123{
124 print_perl_unsupported_msg();
125
126 return -1;
127}
128
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300129static int perl_generate_script_unsupported(struct pevent *pevent
130 __maybe_unused,
131 const char *outfile __maybe_unused)
Tom Zanussi82d156c2010-01-27 02:27:55 -0600132{
133 print_perl_unsupported_msg();
134
135 return -1;
136}
137
138struct scripting_ops perl_scripting_unsupported_ops = {
139 .name = "Perl",
140 .start_script = perl_start_script_unsupported,
141 .stop_script = stop_script_unsupported,
142 .process_event = process_event_unsupported,
143 .generate_script = perl_generate_script_unsupported,
144};
145
146static void register_perl_scripting(struct scripting_ops *scripting_ops)
147{
148 int err;
149 err = script_spec_register("Perl", scripting_ops);
150 if (err)
151 die("error registering Perl script extension");
152
153 err = script_spec_register("pl", scripting_ops);
154 if (err)
155 die("error registering pl script extension");
156
157 scripting_context = malloc(sizeof(struct scripting_context));
158}
159
160#ifdef NO_LIBPERL
161void setup_perl_scripting(void)
162{
163 register_perl_scripting(&perl_scripting_unsupported_ops);
164}
165#else
Stephane Eranian0f940cb2010-09-21 00:45:01 +0200166extern struct scripting_ops perl_scripting_ops;
Tom Zanussi82d156c2010-01-27 02:27:55 -0600167
168void setup_perl_scripting(void)
169{
170 register_perl_scripting(&perl_scripting_ops);
171}
172#endif