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 "event.h"
16#include "evsel.h"
17#include <linux/zalloc.h>
18
19struct scripting_context *scripting_context;
20
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
40static int flush_script_unsupported(void)
41{
42 return 0;
43}
44
45static int stop_script_unsupported(void)
46{
47 return 0;
48}
49
50static void process_event_unsupported(union perf_event *event __maybe_unused,
51 struct perf_sample *sample __maybe_unused,
52 struct evsel *evsel __maybe_unused,
53 struct addr_location *al __maybe_unused,
54 struct addr_location *addr_al __maybe_unused)
55{
56}
57
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
67static int python_start_script_unsupported(const char *script __maybe_unused,
68 int argc __maybe_unused,
69 const char **argv __maybe_unused,
70 struct perf_session *session __maybe_unused)
71{
72 print_python_unsupported_msg();
73
74 return -1;
75}
76
77static int python_generate_script_unsupported(struct tep_handle *pevent
78 __maybe_unused,
79 const char *outfile
80 __maybe_unused)
81{
82 print_python_unsupported_msg();
83
84 return -1;
85}
86
87struct scripting_ops python_scripting_unsupported_ops = {
88 .name = "Python",
89 .dirname = "python",
90 .start_script = python_start_script_unsupported,
91 .flush_script = flush_script_unsupported,
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{
99 if (scripting_context == NULL)
100 scripting_context = malloc(sizeof(*scripting_context));
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 }
108}
109
110#ifndef HAVE_LIBPYTHON_SUPPORT
111void setup_python_scripting(void)
112{
113 register_python_scripting(&python_scripting_unsupported_ops);
114}
115#else
116extern struct scripting_ops python_scripting_ops;
117
118void setup_python_scripting(void)
119{
120 register_python_scripting(&python_scripting_ops);
121}
122#endif
123
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
133static int perl_start_script_unsupported(const char *script __maybe_unused,
134 int argc __maybe_unused,
135 const char **argv __maybe_unused,
136 struct perf_session *session __maybe_unused)
137{
138 print_perl_unsupported_msg();
139
140 return -1;
141}
142
143static int perl_generate_script_unsupported(struct tep_handle *pevent
144 __maybe_unused,
145 const char *outfile __maybe_unused)
146{
147 print_perl_unsupported_msg();
148
149 return -1;
150}
151
152struct scripting_ops perl_scripting_unsupported_ops = {
153 .name = "Perl",
154 .dirname = "perl",
155 .start_script = perl_start_script_unsupported,
156 .flush_script = flush_script_unsupported,
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{
164 if (scripting_context == NULL)
165 scripting_context = malloc(sizeof(*scripting_context));
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 }
173}
174
175#ifndef HAVE_LIBPERL_SUPPORT
176void setup_perl_scripting(void)
177{
178 register_perl_scripting(&perl_scripting_unsupported_ops);
179}
180#else
181extern struct scripting_ops perl_scripting_ops;
182
183void setup_perl_scripting(void)
184{
185 register_perl_scripting(&perl_scripting_ops);
186}
187#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 flush_script_unsupported(void)
34{
35 return 0;
36}
37
38static int stop_script_unsupported(void)
39{
40 return 0;
41}
42
43static void process_event_unsupported(union perf_event *event __maybe_unused,
44 struct perf_sample *sample __maybe_unused,
45 struct perf_evsel *evsel __maybe_unused,
46 struct addr_location *al __maybe_unused)
47{
48}
49
50static void print_python_unsupported_msg(void)
51{
52 fprintf(stderr, "Python scripting not supported."
53 " Install libpython and rebuild perf to enable it.\n"
54 "For example:\n # apt-get install python-dev (ubuntu)"
55 "\n # yum install python-devel (Fedora)"
56 "\n etc.\n");
57}
58
59static int python_start_script_unsupported(const char *script __maybe_unused,
60 int argc __maybe_unused,
61 const char **argv __maybe_unused)
62{
63 print_python_unsupported_msg();
64
65 return -1;
66}
67
68static int python_generate_script_unsupported(struct pevent *pevent
69 __maybe_unused,
70 const char *outfile
71 __maybe_unused)
72{
73 print_python_unsupported_msg();
74
75 return -1;
76}
77
78struct scripting_ops python_scripting_unsupported_ops = {
79 .name = "Python",
80 .start_script = python_start_script_unsupported,
81 .flush_script = flush_script_unsupported,
82 .stop_script = stop_script_unsupported,
83 .process_event = process_event_unsupported,
84 .generate_script = python_generate_script_unsupported,
85};
86
87static void register_python_scripting(struct scripting_ops *scripting_ops)
88{
89 int err;
90 err = script_spec_register("Python", scripting_ops);
91 if (err)
92 die("error registering Python script extension");
93
94 err = script_spec_register("py", scripting_ops);
95 if (err)
96 die("error registering py script extension");
97
98 scripting_context = malloc(sizeof(struct scripting_context));
99}
100
101#ifdef NO_LIBPYTHON
102void setup_python_scripting(void)
103{
104 register_python_scripting(&python_scripting_unsupported_ops);
105}
106#else
107extern struct scripting_ops python_scripting_ops;
108
109void setup_python_scripting(void)
110{
111 register_python_scripting(&python_scripting_ops);
112}
113#endif
114
115static void print_perl_unsupported_msg(void)
116{
117 fprintf(stderr, "Perl scripting not supported."
118 " Install libperl and rebuild perf to enable it.\n"
119 "For example:\n # apt-get install libperl-dev (ubuntu)"
120 "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
121 "\n etc.\n");
122}
123
124static int perl_start_script_unsupported(const char *script __maybe_unused,
125 int argc __maybe_unused,
126 const char **argv __maybe_unused)
127{
128 print_perl_unsupported_msg();
129
130 return -1;
131}
132
133static int perl_generate_script_unsupported(struct pevent *pevent
134 __maybe_unused,
135 const char *outfile __maybe_unused)
136{
137 print_perl_unsupported_msg();
138
139 return -1;
140}
141
142struct scripting_ops perl_scripting_unsupported_ops = {
143 .name = "Perl",
144 .start_script = perl_start_script_unsupported,
145 .flush_script = flush_script_unsupported,
146 .stop_script = stop_script_unsupported,
147 .process_event = process_event_unsupported,
148 .generate_script = perl_generate_script_unsupported,
149};
150
151static void register_perl_scripting(struct scripting_ops *scripting_ops)
152{
153 int err;
154 err = script_spec_register("Perl", scripting_ops);
155 if (err)
156 die("error registering Perl script extension");
157
158 err = script_spec_register("pl", scripting_ops);
159 if (err)
160 die("error registering pl script extension");
161
162 scripting_context = malloc(sizeof(struct scripting_context));
163}
164
165#ifdef NO_LIBPERL
166void setup_perl_scripting(void)
167{
168 register_perl_scripting(&perl_scripting_unsupported_ops);
169}
170#else
171extern struct scripting_ops perl_scripting_ops;
172
173void setup_perl_scripting(void)
174{
175 register_perl_scripting(&perl_scripting_ops);
176}
177#endif