Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 2 | /* |
| 3 | * trace-event-scripting. Scripting engine common and initialization code. |
| 4 | * |
| 5 | * Copyright (C) 2009-2010 Tom Zanussi <tzanussi@gmail.com> |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <string.h> |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 11 | #include <errno.h> |
| 12 | |
| 13 | #include "../perf.h" |
Arnaldo Carvalho de Melo | 9a8860b | 2016-10-25 17:30:05 -0300 | [diff] [blame] | 14 | #include "debug.h" |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 15 | #include "util.h" |
| 16 | #include "trace-event.h" |
| 17 | |
| 18 | struct scripting_context *scripting_context; |
| 19 | |
Adrian Hunter | d445dd2 | 2014-08-15 22:08:37 +0300 | [diff] [blame] | 20 | static int flush_script_unsupported(void) |
| 21 | { |
| 22 | return 0; |
| 23 | } |
| 24 | |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 25 | static int stop_script_unsupported(void) |
| 26 | { |
| 27 | return 0; |
| 28 | } |
| 29 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 30 | static void process_event_unsupported(union perf_event *event __maybe_unused, |
| 31 | struct perf_sample *sample __maybe_unused, |
| 32 | struct perf_evsel *evsel __maybe_unused, |
Arnaldo Carvalho de Melo | cc22e57 | 2013-12-19 17:20:06 -0300 | [diff] [blame] | 33 | struct addr_location *al __maybe_unused) |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 34 | { |
| 35 | } |
| 36 | |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 37 | static void print_python_unsupported_msg(void) |
| 38 | { |
| 39 | fprintf(stderr, "Python scripting not supported." |
| 40 | " Install libpython and rebuild perf to enable it.\n" |
| 41 | "For example:\n # apt-get install python-dev (ubuntu)" |
| 42 | "\n # yum install python-devel (Fedora)" |
| 43 | "\n etc.\n"); |
| 44 | } |
| 45 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 46 | static int python_start_script_unsupported(const char *script __maybe_unused, |
| 47 | int argc __maybe_unused, |
| 48 | const char **argv __maybe_unused) |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 49 | { |
| 50 | print_python_unsupported_msg(); |
| 51 | |
| 52 | return -1; |
| 53 | } |
| 54 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 55 | static int python_generate_script_unsupported(struct tep_handle *pevent |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 56 | __maybe_unused, |
| 57 | const char *outfile |
| 58 | __maybe_unused) |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 59 | { |
| 60 | print_python_unsupported_msg(); |
| 61 | |
| 62 | return -1; |
| 63 | } |
| 64 | |
| 65 | struct scripting_ops python_scripting_unsupported_ops = { |
| 66 | .name = "Python", |
| 67 | .start_script = python_start_script_unsupported, |
Adrian Hunter | d445dd2 | 2014-08-15 22:08:37 +0300 | [diff] [blame] | 68 | .flush_script = flush_script_unsupported, |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 69 | .stop_script = stop_script_unsupported, |
| 70 | .process_event = process_event_unsupported, |
| 71 | .generate_script = python_generate_script_unsupported, |
| 72 | }; |
| 73 | |
| 74 | static void register_python_scripting(struct scripting_ops *scripting_ops) |
| 75 | { |
Arnaldo Carvalho de Melo | cf346d5 | 2016-10-25 17:20:47 -0300 | [diff] [blame] | 76 | if (scripting_context == NULL) |
| 77 | scripting_context = malloc(sizeof(*scripting_context)); |
Arnaldo Carvalho de Melo | 9a8860b | 2016-10-25 17:30:05 -0300 | [diff] [blame] | 78 | |
| 79 | if (scripting_context == NULL || |
| 80 | script_spec_register("Python", scripting_ops) || |
| 81 | script_spec_register("py", scripting_ops)) { |
| 82 | pr_err("Error registering Python script extension: disabling it\n"); |
| 83 | zfree(&scripting_context); |
| 84 | } |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 85 | } |
| 86 | |
Jin Yao | 90ce61b | 2018-04-09 18:26:47 +0800 | [diff] [blame] | 87 | #ifndef HAVE_LIBPYTHON_SUPPORT |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 88 | void setup_python_scripting(void) |
| 89 | { |
| 90 | register_python_scripting(&python_scripting_unsupported_ops); |
| 91 | } |
| 92 | #else |
Stephane Eranian | 0f940cb | 2010-09-21 00:45:01 +0200 | [diff] [blame] | 93 | extern struct scripting_ops python_scripting_ops; |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 94 | |
| 95 | void setup_python_scripting(void) |
| 96 | { |
| 97 | register_python_scripting(&python_scripting_ops); |
| 98 | } |
| 99 | #endif |
| 100 | |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 101 | static void print_perl_unsupported_msg(void) |
| 102 | { |
| 103 | fprintf(stderr, "Perl scripting not supported." |
| 104 | " Install libperl and rebuild perf to enable it.\n" |
| 105 | "For example:\n # apt-get install libperl-dev (ubuntu)" |
| 106 | "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)" |
| 107 | "\n etc.\n"); |
| 108 | } |
| 109 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 110 | static int perl_start_script_unsupported(const char *script __maybe_unused, |
| 111 | int argc __maybe_unused, |
| 112 | const char **argv __maybe_unused) |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 113 | { |
| 114 | print_perl_unsupported_msg(); |
| 115 | |
| 116 | return -1; |
| 117 | } |
| 118 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 119 | static int perl_generate_script_unsupported(struct tep_handle *pevent |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 120 | __maybe_unused, |
| 121 | const char *outfile __maybe_unused) |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 122 | { |
| 123 | print_perl_unsupported_msg(); |
| 124 | |
| 125 | return -1; |
| 126 | } |
| 127 | |
| 128 | struct scripting_ops perl_scripting_unsupported_ops = { |
| 129 | .name = "Perl", |
| 130 | .start_script = perl_start_script_unsupported, |
Adrian Hunter | d445dd2 | 2014-08-15 22:08:37 +0300 | [diff] [blame] | 131 | .flush_script = flush_script_unsupported, |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 132 | .stop_script = stop_script_unsupported, |
| 133 | .process_event = process_event_unsupported, |
| 134 | .generate_script = perl_generate_script_unsupported, |
| 135 | }; |
| 136 | |
| 137 | static void register_perl_scripting(struct scripting_ops *scripting_ops) |
| 138 | { |
Arnaldo Carvalho de Melo | cf346d5 | 2016-10-25 17:20:47 -0300 | [diff] [blame] | 139 | if (scripting_context == NULL) |
| 140 | scripting_context = malloc(sizeof(*scripting_context)); |
Arnaldo Carvalho de Melo | 9a8860b | 2016-10-25 17:30:05 -0300 | [diff] [blame] | 141 | |
| 142 | if (scripting_context == NULL || |
| 143 | script_spec_register("Perl", scripting_ops) || |
| 144 | script_spec_register("pl", scripting_ops)) { |
| 145 | pr_err("Error registering Perl script extension: disabling it\n"); |
| 146 | zfree(&scripting_context); |
| 147 | } |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 148 | } |
| 149 | |
Jin Yao | 90ce61b | 2018-04-09 18:26:47 +0800 | [diff] [blame] | 150 | #ifndef HAVE_LIBPERL_SUPPORT |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 151 | void setup_perl_scripting(void) |
| 152 | { |
| 153 | register_perl_scripting(&perl_scripting_unsupported_ops); |
| 154 | } |
| 155 | #else |
Stephane Eranian | 0f940cb | 2010-09-21 00:45:01 +0200 | [diff] [blame] | 156 | extern struct scripting_ops perl_scripting_ops; |
Tom Zanussi | 82d156c | 2010-01-27 02:27:55 -0600 | [diff] [blame] | 157 | |
| 158 | void setup_perl_scripting(void) |
| 159 | { |
| 160 | register_perl_scripting(&perl_scripting_ops); |
| 161 | } |
| 162 | #endif |