]>
Commit | Line | Data |
---|---|---|
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" |
7f7c536f | 15 | #include <linux/zalloc.h> |
82d156cd TZ |
16 | |
17 | struct scripting_context *scripting_context; | |
18 | ||
d445dd2a AH |
19 | static int flush_script_unsupported(void) |
20 | { | |
21 | return 0; | |
22 | } | |
23 | ||
82d156cd TZ |
24 | static int stop_script_unsupported(void) |
25 | { | |
26 | return 0; | |
27 | } | |
28 | ||
1d037ca1 IT |
29 | static void process_event_unsupported(union perf_event *event __maybe_unused, |
30 | struct perf_sample *sample __maybe_unused, | |
32dcd021 | 31 | struct evsel *evsel __maybe_unused, |
cc22e575 | 32 | struct addr_location *al __maybe_unused) |
82d156cd TZ |
33 | { |
34 | } | |
35 | ||
7e4b21b8 TZ |
36 | static 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 | ||
1d037ca1 IT |
45 | static int python_start_script_unsupported(const char *script __maybe_unused, |
46 | int argc __maybe_unused, | |
47 | const char **argv __maybe_unused) | |
7e4b21b8 TZ |
48 | { |
49 | print_python_unsupported_msg(); | |
50 | ||
51 | return -1; | |
52 | } | |
53 | ||
096177a8 | 54 | static int python_generate_script_unsupported(struct tep_handle *pevent |
1d037ca1 IT |
55 | __maybe_unused, |
56 | const char *outfile | |
57 | __maybe_unused) | |
7e4b21b8 TZ |
58 | { |
59 | print_python_unsupported_msg(); | |
60 | ||
61 | return -1; | |
62 | } | |
63 | ||
64 | struct scripting_ops python_scripting_unsupported_ops = { | |
65 | .name = "Python", | |
66 | .start_script = python_start_script_unsupported, | |
d445dd2a | 67 | .flush_script = flush_script_unsupported, |
7e4b21b8 TZ |
68 | .stop_script = stop_script_unsupported, |
69 | .process_event = process_event_unsupported, | |
70 | .generate_script = python_generate_script_unsupported, | |
71 | }; | |
72 | ||
73 | static void register_python_scripting(struct scripting_ops *scripting_ops) | |
74 | { | |
cf346d5b ACM |
75 | if (scripting_context == NULL) |
76 | scripting_context = malloc(sizeof(*scripting_context)); | |
9a8860bb ACM |
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 | } | |
7e4b21b8 TZ |
84 | } |
85 | ||
90ce61b9 | 86 | #ifndef HAVE_LIBPYTHON_SUPPORT |
7e4b21b8 TZ |
87 | void setup_python_scripting(void) |
88 | { | |
89 | register_python_scripting(&python_scripting_unsupported_ops); | |
90 | } | |
91 | #else | |
0f940cb7 | 92 | extern struct scripting_ops python_scripting_ops; |
7e4b21b8 TZ |
93 | |
94 | void setup_python_scripting(void) | |
95 | { | |
96 | register_python_scripting(&python_scripting_ops); | |
97 | } | |
98 | #endif | |
99 | ||
82d156cd TZ |
100 | static 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 | ||
1d037ca1 IT |
109 | static int perl_start_script_unsupported(const char *script __maybe_unused, |
110 | int argc __maybe_unused, | |
111 | const char **argv __maybe_unused) | |
82d156cd TZ |
112 | { |
113 | print_perl_unsupported_msg(); | |
114 | ||
115 | return -1; | |
116 | } | |
117 | ||
096177a8 | 118 | static int perl_generate_script_unsupported(struct tep_handle *pevent |
1d037ca1 IT |
119 | __maybe_unused, |
120 | const char *outfile __maybe_unused) | |
82d156cd TZ |
121 | { |
122 | print_perl_unsupported_msg(); | |
123 | ||
124 | return -1; | |
125 | } | |
126 | ||
127 | struct scripting_ops perl_scripting_unsupported_ops = { | |
128 | .name = "Perl", | |
129 | .start_script = perl_start_script_unsupported, | |
d445dd2a | 130 | .flush_script = flush_script_unsupported, |
82d156cd TZ |
131 | .stop_script = stop_script_unsupported, |
132 | .process_event = process_event_unsupported, | |
133 | .generate_script = perl_generate_script_unsupported, | |
134 | }; | |
135 | ||
136 | static void register_perl_scripting(struct scripting_ops *scripting_ops) | |
137 | { | |
cf346d5b ACM |
138 | if (scripting_context == NULL) |
139 | scripting_context = malloc(sizeof(*scripting_context)); | |
9a8860bb ACM |
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 | } | |
82d156cd TZ |
147 | } |
148 | ||
90ce61b9 | 149 | #ifndef HAVE_LIBPERL_SUPPORT |
82d156cd TZ |
150 | void setup_perl_scripting(void) |
151 | { | |
152 | register_perl_scripting(&perl_scripting_unsupported_ops); | |
153 | } | |
154 | #else | |
0f940cb7 | 155 | extern struct scripting_ops perl_scripting_ops; |
82d156cd TZ |
156 | |
157 | void setup_perl_scripting(void) | |
158 | { | |
159 | register_perl_scripting(&perl_scripting_ops); | |
160 | } | |
161 | #endif |