Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
trace-event-scripting.c
Go to the documentation of this file.
1 /*
2  * trace-event-scripting. Scripting engine common and initialization code.
3  *
4  * Copyright (C) 2009-2010 Tom Zanussi <[email protected]>
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 
32 
33 static int stop_script_unsupported(void)
34 {
35  return 0;
36 }
37 
38 static void process_event_unsupported(union perf_event *event __maybe_unused,
39  struct perf_sample *sample __maybe_unused,
40  struct perf_evsel *evsel __maybe_unused,
41  struct machine *machine __maybe_unused,
42  struct addr_location *al __maybe_unused)
43 {
44 }
45 
46 static void print_python_unsupported_msg(void)
47 {
48  fprintf(stderr, "Python scripting not supported."
49  " Install libpython and rebuild perf to enable it.\n"
50  "For example:\n # apt-get install python-dev (ubuntu)"
51  "\n # yum install python-devel (Fedora)"
52  "\n etc.\n");
53 }
54 
55 static int python_start_script_unsupported(const char *script __maybe_unused,
56  int argc __maybe_unused,
57  const char **argv __maybe_unused)
58 {
59  print_python_unsupported_msg();
60 
61  return -1;
62 }
63 
64 static int python_generate_script_unsupported(struct pevent *pevent
66  const char *outfile
67  __maybe_unused)
68 {
69  print_python_unsupported_msg();
70 
71  return -1;
72 }
73 
75  .name = "Python",
76  .start_script = python_start_script_unsupported,
77  .stop_script = stop_script_unsupported,
78  .process_event = process_event_unsupported,
79  .generate_script = python_generate_script_unsupported,
80 };
81 
82 static void register_python_scripting(struct scripting_ops *scripting_ops)
83 {
84  int err;
85  err = script_spec_register("Python", scripting_ops);
86  if (err)
87  die("error registering Python script extension");
88 
89  err = script_spec_register("py", scripting_ops);
90  if (err)
91  die("error registering py script extension");
92 
93  scripting_context = malloc(sizeof(struct scripting_context));
94 }
95 
96 #ifdef NO_LIBPYTHON
97 void setup_python_scripting(void)
98 {
99  register_python_scripting(&python_scripting_unsupported_ops);
100 }
101 #else
102 extern struct scripting_ops python_scripting_ops;
103 
105 {
106  register_python_scripting(&python_scripting_ops);
107 }
108 #endif
109 
110 static void print_perl_unsupported_msg(void)
111 {
112  fprintf(stderr, "Perl scripting not supported."
113  " Install libperl and rebuild perf to enable it.\n"
114  "For example:\n # apt-get install libperl-dev (ubuntu)"
115  "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
116  "\n etc.\n");
117 }
118 
119 static int perl_start_script_unsupported(const char *script __maybe_unused,
120  int argc __maybe_unused,
121  const char **argv __maybe_unused)
122 {
123  print_perl_unsupported_msg();
124 
125  return -1;
126 }
127 
128 static int perl_generate_script_unsupported(struct pevent *pevent
130  const char *outfile __maybe_unused)
131 {
132  print_perl_unsupported_msg();
133 
134  return -1;
135 }
136 
137 struct scripting_ops perl_scripting_unsupported_ops = {
138  .name = "Perl",
139  .start_script = perl_start_script_unsupported,
140  .stop_script = stop_script_unsupported,
141  .process_event = process_event_unsupported,
142  .generate_script = perl_generate_script_unsupported,
143 };
144 
145 static void register_perl_scripting(struct scripting_ops *scripting_ops)
146 {
147  int err;
148  err = script_spec_register("Perl", scripting_ops);
149  if (err)
150  die("error registering Perl script extension");
151 
152  err = script_spec_register("pl", scripting_ops);
153  if (err)
154  die("error registering pl script extension");
155 
156  scripting_context = malloc(sizeof(struct scripting_context));
157 }
158 
159 #ifdef NO_LIBPERL
160 void setup_perl_scripting(void)
161 {
162  register_perl_scripting(&perl_scripting_unsupported_ops);
163 }
164 #else
165 extern struct scripting_ops perl_scripting_ops;
166 
168 {
169  register_perl_scripting(&perl_scripting_ops);
170 }
171 #endif