0001
0002
0003
0004
0005
0006
0007
0008 #include <stdio.h>
0009 #include <stdlib.h>
0010 #include <string.h>
0011 #include <errno.h>
0012
0013 #include "debug.h"
0014 #include "trace-event.h"
0015 #include "event.h"
0016 #include "evsel.h"
0017 #include <linux/zalloc.h>
0018
0019 struct scripting_context *scripting_context;
0020
0021 void scripting_context__update(struct scripting_context *c,
0022 union perf_event *event,
0023 struct perf_sample *sample,
0024 struct evsel *evsel,
0025 struct addr_location *al,
0026 struct addr_location *addr_al)
0027 {
0028 c->event_data = sample->raw_data;
0029 if (evsel->tp_format)
0030 c->pevent = evsel->tp_format->tep;
0031 else
0032 c->pevent = NULL;
0033 c->event = event;
0034 c->sample = sample;
0035 c->evsel = evsel;
0036 c->al = al;
0037 c->addr_al = addr_al;
0038 }
0039
0040 static int flush_script_unsupported(void)
0041 {
0042 return 0;
0043 }
0044
0045 static int stop_script_unsupported(void)
0046 {
0047 return 0;
0048 }
0049
0050 static void process_event_unsupported(union perf_event *event __maybe_unused,
0051 struct perf_sample *sample __maybe_unused,
0052 struct evsel *evsel __maybe_unused,
0053 struct addr_location *al __maybe_unused,
0054 struct addr_location *addr_al __maybe_unused)
0055 {
0056 }
0057
0058 static void print_python_unsupported_msg(void)
0059 {
0060 fprintf(stderr, "Python scripting not supported."
0061 " Install libpython and rebuild perf to enable it.\n"
0062 "For example:\n # apt-get install python-dev (ubuntu)"
0063 "\n # yum install python-devel (Fedora)"
0064 "\n etc.\n");
0065 }
0066
0067 static int python_start_script_unsupported(const char *script __maybe_unused,
0068 int argc __maybe_unused,
0069 const char **argv __maybe_unused,
0070 struct perf_session *session __maybe_unused)
0071 {
0072 print_python_unsupported_msg();
0073
0074 return -1;
0075 }
0076
0077 static int python_generate_script_unsupported(struct tep_handle *pevent
0078 __maybe_unused,
0079 const char *outfile
0080 __maybe_unused)
0081 {
0082 print_python_unsupported_msg();
0083
0084 return -1;
0085 }
0086
0087 struct scripting_ops python_scripting_unsupported_ops = {
0088 .name = "Python",
0089 .dirname = "python",
0090 .start_script = python_start_script_unsupported,
0091 .flush_script = flush_script_unsupported,
0092 .stop_script = stop_script_unsupported,
0093 .process_event = process_event_unsupported,
0094 .generate_script = python_generate_script_unsupported,
0095 };
0096
0097 static void register_python_scripting(struct scripting_ops *scripting_ops)
0098 {
0099 if (scripting_context == NULL)
0100 scripting_context = malloc(sizeof(*scripting_context));
0101
0102 if (scripting_context == NULL ||
0103 script_spec_register("Python", scripting_ops) ||
0104 script_spec_register("py", scripting_ops)) {
0105 pr_err("Error registering Python script extension: disabling it\n");
0106 zfree(&scripting_context);
0107 }
0108 }
0109
0110 #ifndef HAVE_LIBPYTHON_SUPPORT
0111 void setup_python_scripting(void)
0112 {
0113 register_python_scripting(&python_scripting_unsupported_ops);
0114 }
0115 #else
0116 extern struct scripting_ops python_scripting_ops;
0117
0118 void setup_python_scripting(void)
0119 {
0120 register_python_scripting(&python_scripting_ops);
0121 }
0122 #endif
0123
0124 static void print_perl_unsupported_msg(void)
0125 {
0126 fprintf(stderr, "Perl scripting not supported."
0127 " Install libperl and rebuild perf to enable it.\n"
0128 "For example:\n # apt-get install libperl-dev (ubuntu)"
0129 "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
0130 "\n etc.\n");
0131 }
0132
0133 static int perl_start_script_unsupported(const char *script __maybe_unused,
0134 int argc __maybe_unused,
0135 const char **argv __maybe_unused,
0136 struct perf_session *session __maybe_unused)
0137 {
0138 print_perl_unsupported_msg();
0139
0140 return -1;
0141 }
0142
0143 static int perl_generate_script_unsupported(struct tep_handle *pevent
0144 __maybe_unused,
0145 const char *outfile __maybe_unused)
0146 {
0147 print_perl_unsupported_msg();
0148
0149 return -1;
0150 }
0151
0152 struct scripting_ops perl_scripting_unsupported_ops = {
0153 .name = "Perl",
0154 .dirname = "perl",
0155 .start_script = perl_start_script_unsupported,
0156 .flush_script = flush_script_unsupported,
0157 .stop_script = stop_script_unsupported,
0158 .process_event = process_event_unsupported,
0159 .generate_script = perl_generate_script_unsupported,
0160 };
0161
0162 static void register_perl_scripting(struct scripting_ops *scripting_ops)
0163 {
0164 if (scripting_context == NULL)
0165 scripting_context = malloc(sizeof(*scripting_context));
0166
0167 if (scripting_context == NULL ||
0168 script_spec_register("Perl", scripting_ops) ||
0169 script_spec_register("pl", scripting_ops)) {
0170 pr_err("Error registering Perl script extension: disabling it\n");
0171 zfree(&scripting_context);
0172 }
0173 }
0174
0175 #ifndef HAVE_LIBPERL_SUPPORT
0176 void setup_perl_scripting(void)
0177 {
0178 register_perl_scripting(&perl_scripting_unsupported_ops);
0179 }
0180 #else
0181 extern struct scripting_ops perl_scripting_ops;
0182
0183 void setup_perl_scripting(void)
0184 {
0185 register_perl_scripting(&perl_scripting_ops);
0186 }
0187 #endif