Commit | Line | Data |
---|---|---|
d0254c7c MD |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * Copyright (C) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU General Public License | |
7 | * as published by the Free Software Foundation; only version 2 | |
8 | * of the License. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | */ | |
19 | ||
20 | #define _GNU_SOURCE | |
21 | #include <popt.h> | |
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
25 | #include <sys/stat.h> | |
26 | #include <sys/types.h> | |
27 | #include <unistd.h> | |
28 | #include <inttypes.h> | |
29 | #include <ctype.h> | |
30 | ||
c399183f | 31 | #include "../command.h" |
d0254c7c MD |
32 | |
33 | static int opt_event_type; | |
34 | static char *opt_kernel; | |
d0254c7c | 35 | static int opt_userspace; |
d78d6610 DG |
36 | #if 0 |
37 | /* Not implemented yet */ | |
eeac7d46 | 38 | static char *opt_cmd_name; |
d0254c7c | 39 | static pid_t opt_pid; |
d78d6610 | 40 | #endif |
d0254c7c MD |
41 | |
42 | enum { | |
43 | OPT_HELP = 1, | |
d0254c7c MD |
44 | OPT_TRACEPOINT, |
45 | OPT_MARKER, | |
46 | OPT_PROBE, | |
47 | OPT_FUNCTION, | |
48 | OPT_FUNCTION_ENTRY, | |
a54bd42d | 49 | OPT_SYSCALL, |
eeac7d46 | 50 | OPT_USERSPACE, |
d0254c7c MD |
51 | }; |
52 | ||
cd80958d DG |
53 | static struct lttng_handle *handle; |
54 | ||
d0254c7c MD |
55 | static struct poptOption long_options[] = { |
56 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
57 | {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, | |
58 | {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, | |
d78d6610 DG |
59 | #if 0 |
60 | /* Not implemented yet */ | |
6caa2bcc | 61 | {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, |
d0254c7c MD |
62 | {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, |
63 | {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0}, | |
64 | {"marker", 0, POPT_ARG_NONE, 0, OPT_MARKER, 0, 0}, | |
65 | {"probe", 0, POPT_ARG_NONE, 0, OPT_PROBE, 0, 0}, | |
4466912f DG |
66 | #else |
67 | {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, | |
d0254c7c | 68 | {"function", 0, POPT_ARG_NONE, 0, OPT_FUNCTION, 0, 0}, |
4466912f | 69 | #endif |
b213d387 MD |
70 | #if 0 |
71 | /* | |
72 | * Removed from options to discourage its use. Not in kernel | |
73 | * tracer anymore. | |
74 | */ | |
d0254c7c | 75 | {"function:entry", 0, POPT_ARG_NONE, 0, OPT_FUNCTION_ENTRY, 0, 0}, |
b213d387 | 76 | #endif |
a54bd42d | 77 | {"syscall", 0, POPT_ARG_NONE, 0, OPT_SYSCALL, 0, 0}, |
d0254c7c MD |
78 | {0, 0, 0, 0, 0, 0, 0} |
79 | }; | |
80 | ||
81 | /* | |
82 | * usage | |
83 | */ | |
84 | static void usage(FILE *ofp) | |
85 | { | |
86 | fprintf(ofp, "usage: lttng calibrate [options] [calibrate_options]\n"); | |
87 | fprintf(ofp, "\n"); | |
88 | fprintf(ofp, " -h, --help Show this help\n"); | |
89 | fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); | |
d78d6610 | 90 | #if 0 |
d0254c7c | 91 | fprintf(ofp, " -u, --userspace [CMD] Apply for the user-space tracer\n"); |
d78d6610 DG |
92 | fprintf(ofp, " If no CMD, the domain used is UST global\n"); |
93 | fprintf(ofp, " or else the domain is UST EXEC_NAME\n"); | |
94 | fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n"); | |
95 | #else | |
96 | fprintf(ofp, " -u, --userspace Apply for the user-space tracer\n"); | |
97 | #endif | |
d0254c7c MD |
98 | fprintf(ofp, "\n"); |
99 | fprintf(ofp, "Calibrate options:\n"); | |
4466912f | 100 | #if 0 |
d0254c7c MD |
101 | fprintf(ofp, " --tracepoint Tracepoint event (default)\n"); |
102 | fprintf(ofp, " --probe\n"); | |
103 | fprintf(ofp, " Dynamic probe.\n"); | |
b213d387 | 104 | #if 0 |
d0254c7c MD |
105 | fprintf(ofp, " --function:entry symbol\n"); |
106 | fprintf(ofp, " Function tracer event\n"); | |
b213d387 | 107 | #endif |
a54bd42d | 108 | fprintf(ofp, " --syscall System call eventl\n"); |
d0254c7c | 109 | fprintf(ofp, " --marker User-space marker (deprecated)\n"); |
4466912f DG |
110 | #else |
111 | fprintf(ofp, " --function Dynamic function entry/return probe (default)\n"); | |
112 | #endif | |
d0254c7c MD |
113 | fprintf(ofp, "\n"); |
114 | } | |
115 | ||
116 | /* | |
117 | * calibrate_lttng | |
118 | * | |
119 | * Calibrate LTTng. | |
120 | */ | |
121 | static int calibrate_lttng(void) | |
122 | { | |
123 | int ret = CMD_SUCCESS; | |
124 | struct lttng_domain dom; | |
125 | struct lttng_calibrate calibrate; | |
126 | ||
127 | /* Create lttng domain */ | |
128 | if (opt_kernel) { | |
129 | dom.type = LTTNG_DOMAIN_KERNEL; | |
4466912f DG |
130 | } else if (opt_userspace) { |
131 | dom.type = LTTNG_DOMAIN_UST; | |
132 | } else { | |
133 | ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); | |
134 | ret = CMD_UNDEFINED; | |
135 | goto error; | |
d0254c7c MD |
136 | } |
137 | ||
cd80958d DG |
138 | handle = lttng_create_handle(NULL, &dom); |
139 | if (handle == NULL) { | |
140 | ret = -1; | |
4466912f | 141 | goto error; |
cd80958d DG |
142 | } |
143 | ||
4466912f DG |
144 | switch (opt_event_type) { |
145 | case LTTNG_EVENT_TRACEPOINT: | |
146 | DBG("Calibrating kernel tracepoints"); | |
147 | break; | |
148 | case LTTNG_EVENT_PROBE: | |
149 | DBG("Calibrating kernel probes"); | |
150 | break; | |
151 | case LTTNG_EVENT_FUNCTION: | |
152 | DBG("Calibrating kernel functions"); | |
153 | calibrate.type = LTTNG_CALIBRATE_FUNCTION; | |
154 | ret = lttng_calibrate(handle, &calibrate); | |
155 | if (ret < 0) { | |
156 | goto error; | |
d0254c7c | 157 | } |
4466912f DG |
158 | MSG("%s calibration done", opt_kernel ? "Kernel" : "UST"); |
159 | break; | |
160 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
161 | DBG("Calibrating kernel function entry"); | |
162 | break; | |
163 | case LTTNG_EVENT_SYSCALL: | |
164 | DBG("Calibrating kernel syscall"); | |
165 | break; | |
166 | default: | |
1ab1ea0b | 167 | ret = CMD_UNDEFINED; |
4466912f | 168 | goto error; |
d0254c7c | 169 | } |
4466912f DG |
170 | |
171 | error: | |
cd80958d DG |
172 | lttng_destroy_handle(handle); |
173 | ||
d0254c7c MD |
174 | return ret; |
175 | } | |
176 | ||
177 | /* | |
178 | * cmd_calibrate | |
179 | * | |
180 | * Calibrate LTTng tracer. | |
181 | */ | |
182 | int cmd_calibrate(int argc, const char **argv) | |
183 | { | |
184 | int opt, ret; | |
185 | static poptContext pc; | |
186 | ||
187 | pc = poptGetContext(NULL, argc, argv, long_options, 0); | |
188 | poptReadDefaultConfig(pc, 0); | |
189 | ||
190 | /* Default event type */ | |
4466912f | 191 | opt_event_type = LTTNG_EVENT_FUNCTION; |
d0254c7c MD |
192 | |
193 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
194 | switch (opt) { | |
195 | case OPT_HELP: | |
196 | usage(stderr); | |
197 | ret = CMD_SUCCESS; | |
198 | goto end; | |
d0254c7c | 199 | case OPT_TRACEPOINT: |
1ab1ea0b | 200 | ret = CMD_UNDEFINED; |
4466912f | 201 | goto end; |
d0254c7c | 202 | case OPT_MARKER: |
1ab1ea0b | 203 | ret = CMD_UNDEFINED; |
d0254c7c MD |
204 | goto end; |
205 | case OPT_PROBE: | |
1ab1ea0b | 206 | ret = CMD_UNDEFINED; |
d0254c7c MD |
207 | break; |
208 | case OPT_FUNCTION: | |
209 | opt_event_type = LTTNG_EVENT_FUNCTION; | |
210 | break; | |
211 | case OPT_FUNCTION_ENTRY: | |
1ab1ea0b | 212 | ret = CMD_UNDEFINED; |
4466912f | 213 | goto end; |
a54bd42d | 214 | case OPT_SYSCALL: |
1ab1ea0b | 215 | ret = CMD_UNDEFINED; |
4466912f | 216 | goto end; |
eeac7d46 MD |
217 | case OPT_USERSPACE: |
218 | opt_userspace = 1; | |
eeac7d46 | 219 | break; |
d0254c7c MD |
220 | default: |
221 | usage(stderr); | |
222 | ret = CMD_UNDEFINED; | |
223 | goto end; | |
224 | } | |
225 | } | |
226 | ||
227 | ret = calibrate_lttng(); | |
228 | ||
229 | end: | |
230 | return ret; | |
231 | } |