Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 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> |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 25 | #include <errno.h> |
| 26 | |
| 27 | #include "../perf.h" |
Arnaldo Carvalho de Melo | 9a8860b | 2016-10-25 17:30:05 -0300 | [diff] [blame] | 28 | #include "debug.h" |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 29 | #include "util.h" |
| 30 | #include "trace-event.h" |
| 31 | |
| 32 | struct scripting_context *scripting_context; |
| 33 | |
Adrian Hunter | d445dd2 | 2014-08-15 22:08:37 +0300 | [diff] [blame] | 34 | static int flush_script_unsupported(void) |
| 35 | { |
| 36 | return 0; |
| 37 | } |
| 38 | |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 39 | static int stop_script_unsupported(void) |
| 40 | { |
| 41 | return 0; |
| 42 | } |
| 43 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 44 | static void process_event_unsupported(union perf_event *event __maybe_unused, |
| 45 | struct perf_sample *sample __maybe_unused, |
| 46 | struct perf_evsel *evsel __maybe_unused, |
Arnaldo Carvalho de Melo | cc22e57 | 2013-12-19 17:20:06 -0300 | [diff] [blame] | 47 | struct addr_location *al __maybe_unused) |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 48 | { |
| 49 | } |
| 50 | |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 51 | static 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 Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 60 | static int python_start_script_unsupported(const char *script __maybe_unused, |
| 61 | int argc __maybe_unused, |
| 62 | const char **argv __maybe_unused) |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 63 | { |
| 64 | print_python_unsupported_msg(); |
| 65 | |
| 66 | return -1; |
| 67 | } |
| 68 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 69 | static int python_generate_script_unsupported(struct pevent *pevent |
| 70 | __maybe_unused, |
| 71 | const char *outfile |
| 72 | __maybe_unused) |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 73 | { |
| 74 | print_python_unsupported_msg(); |
| 75 | |
| 76 | return -1; |
| 77 | } |
| 78 | |
| 79 | struct scripting_ops python_scripting_unsupported_ops = { |
| 80 | .name = "Python", |
| 81 | .start_script = python_start_script_unsupported, |
Adrian Hunter | d445dd2 | 2014-08-15 22:08:37 +0300 | [diff] [blame] | 82 | .flush_script = flush_script_unsupported, |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 83 | .stop_script = stop_script_unsupported, |
| 84 | .process_event = process_event_unsupported, |
| 85 | .generate_script = python_generate_script_unsupported, |
| 86 | }; |
| 87 | |
| 88 | static void register_python_scripting(struct scripting_ops *scripting_ops) |
| 89 | { |
Arnaldo Carvalho de Melo | cf346d5 | 2016-10-25 17:20:47 -0300 | [diff] [blame] | 90 | if (scripting_context == NULL) |
| 91 | scripting_context = malloc(sizeof(*scripting_context)); |
Arnaldo Carvalho de Melo | 9a8860b | 2016-10-25 17:30:05 -0300 | [diff] [blame] | 92 | |
| 93 | if (scripting_context == NULL || |
| 94 | script_spec_register("Python", scripting_ops) || |
| 95 | script_spec_register("py", scripting_ops)) { |
| 96 | pr_err("Error registering Python script extension: disabling it\n"); |
| 97 | zfree(&scripting_context); |
| 98 | } |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 99 | } |
| 100 | |
Jin Yao | 90ce61b | 2018-04-09 18:26:47 +0800 | [diff] [blame] | 101 | #ifndef HAVE_LIBPYTHON_SUPPORT |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 102 | void setup_python_scripting(void) |
| 103 | { |
| 104 | register_python_scripting(&python_scripting_unsupported_ops); |
| 105 | } |
| 106 | #else |
Stephane Eranian | 0f940cb | 2010-09-21 00:45:01 +0200 | [diff] [blame] | 107 | extern struct scripting_ops python_scripting_ops; |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 108 | |
| 109 | void setup_python_scripting(void) |
| 110 | { |
| 111 | register_python_scripting(&python_scripting_ops); |
| 112 | } |
| 113 | #endif |
| 114 | |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 115 | static 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 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 124 | static int perl_start_script_unsupported(const char *script __maybe_unused, |
| 125 | int argc __maybe_unused, |
| 126 | const char **argv __maybe_unused) |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 127 | { |
| 128 | print_perl_unsupported_msg(); |
| 129 | |
| 130 | return -1; |
| 131 | } |
| 132 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 133 | static int perl_generate_script_unsupported(struct pevent *pevent |
| 134 | __maybe_unused, |
| 135 | const char *outfile __maybe_unused) |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 136 | { |
| 137 | print_perl_unsupported_msg(); |
| 138 | |
| 139 | return -1; |
| 140 | } |
| 141 | |
| 142 | struct scripting_ops perl_scripting_unsupported_ops = { |
| 143 | .name = "Perl", |
| 144 | .start_script = perl_start_script_unsupported, |
Adrian Hunter | d445dd2 | 2014-08-15 22:08:37 +0300 | [diff] [blame] | 145 | .flush_script = flush_script_unsupported, |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 146 | .stop_script = stop_script_unsupported, |
| 147 | .process_event = process_event_unsupported, |
| 148 | .generate_script = perl_generate_script_unsupported, |
| 149 | }; |
| 150 | |
| 151 | static void register_perl_scripting(struct scripting_ops *scripting_ops) |
| 152 | { |
Arnaldo Carvalho de Melo | cf346d5 | 2016-10-25 17:20:47 -0300 | [diff] [blame] | 153 | if (scripting_context == NULL) |
| 154 | scripting_context = malloc(sizeof(*scripting_context)); |
Arnaldo Carvalho de Melo | 9a8860b | 2016-10-25 17:30:05 -0300 | [diff] [blame] | 155 | |
| 156 | if (scripting_context == NULL || |
| 157 | script_spec_register("Perl", scripting_ops) || |
| 158 | script_spec_register("pl", scripting_ops)) { |
| 159 | pr_err("Error registering Perl script extension: disabling it\n"); |
| 160 | zfree(&scripting_context); |
| 161 | } |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 162 | } |
| 163 | |
Jin Yao | 90ce61b | 2018-04-09 18:26:47 +0800 | [diff] [blame] | 164 | #ifndef HAVE_LIBPERL_SUPPORT |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 165 | void setup_perl_scripting(void) |
| 166 | { |
| 167 | register_perl_scripting(&perl_scripting_unsupported_ops); |
| 168 | } |
| 169 | #else |
Stephane Eranian | 0f940cb | 2010-09-21 00:45:01 +0200 | [diff] [blame] | 170 | extern struct scripting_ops perl_scripting_ops; |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 171 | |
| 172 | void setup_perl_scripting(void) |
| 173 | { |
| 174 | register_perl_scripting(&perl_scripting_ops); |
| 175 | } |
| 176 | #endif |