Disable lttng ust domain not implemented
[lttng-tools.git] / src / bin / lttng / commands / calibrate.c
CommitLineData
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
33static int opt_event_type;
34static char *opt_kernel;
d0254c7c 35static int opt_userspace;
d78d6610
DG
36#if 0
37/* Not implemented yet */
eeac7d46 38static char *opt_cmd_name;
d0254c7c 39static pid_t opt_pid;
d78d6610 40#endif
d0254c7c
MD
41
42enum {
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
53static struct lttng_handle *handle;
54
d0254c7c
MD
55static 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 62 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
d78d6610
DG
63#else
64 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
65#endif
d0254c7c
MD
66 {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0},
67 {"marker", 0, POPT_ARG_NONE, 0, OPT_MARKER, 0, 0},
68 {"probe", 0, POPT_ARG_NONE, 0, OPT_PROBE, 0, 0},
69 {"function", 0, POPT_ARG_NONE, 0, OPT_FUNCTION, 0, 0},
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 */
84static 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");
100 fprintf(ofp, " --tracepoint Tracepoint event (default)\n");
101 fprintf(ofp, " --probe\n");
102 fprintf(ofp, " Dynamic probe.\n");
103 fprintf(ofp, " --function\n");
104 fprintf(ofp, " Dynamic function entry/return probe.\n");
b213d387 105#if 0
d0254c7c
MD
106 fprintf(ofp, " --function:entry symbol\n");
107 fprintf(ofp, " Function tracer event\n");
b213d387 108#endif
a54bd42d 109 fprintf(ofp, " --syscall System call eventl\n");
d0254c7c
MD
110 fprintf(ofp, " --marker User-space marker (deprecated)\n");
111 fprintf(ofp, "\n");
112}
113
114/*
115 * calibrate_lttng
116 *
117 * Calibrate LTTng.
118 */
119static int calibrate_lttng(void)
120{
121 int ret = CMD_SUCCESS;
122 struct lttng_domain dom;
123 struct lttng_calibrate calibrate;
124
125 /* Create lttng domain */
126 if (opt_kernel) {
127 dom.type = LTTNG_DOMAIN_KERNEL;
128 }
129
cd80958d
DG
130 handle = lttng_create_handle(NULL, &dom);
131 if (handle == NULL) {
132 ret = -1;
133 goto end;
134 }
135
d0254c7c
MD
136 /* Kernel tracer action */
137 if (opt_kernel) {
138 switch (opt_event_type) {
139 case LTTNG_EVENT_TRACEPOINT:
140 DBG("Calibrating kernel tracepoints");
141 break;
142 case LTTNG_EVENT_PROBE:
143 DBG("Calibrating kernel probes");
144 break;
145 case LTTNG_EVENT_FUNCTION:
146 DBG("Calibrating kernel functions");
147 calibrate.type = LTTNG_CALIBRATE_FUNCTION;
cd80958d 148 ret = lttng_calibrate(handle, &calibrate);
d0254c7c
MD
149 break;
150 case LTTNG_EVENT_FUNCTION_ENTRY:
151 DBG("Calibrating kernel function entry");
152 break;
a54bd42d
MD
153 case LTTNG_EVENT_SYSCALL:
154 DBG("Calibrating kernel syscall");
0133c199 155 break;
d0254c7c
MD
156 default:
157 ret = CMD_NOT_IMPLEMENTED;
158 goto end;
159 }
160 } else if (opt_userspace) { /* User-space tracer action */
d0254c7c
MD
161 ret = CMD_NOT_IMPLEMENTED;
162 goto end;
163 } else {
048e2159 164 ERR("Please specify a tracer (--kernel or --userspace)");
d0254c7c
MD
165 goto end;
166 }
167end:
cd80958d
DG
168 lttng_destroy_handle(handle);
169
d0254c7c
MD
170 return ret;
171}
172
173/*
174 * cmd_calibrate
175 *
176 * Calibrate LTTng tracer.
177 */
178int cmd_calibrate(int argc, const char **argv)
179{
180 int opt, ret;
181 static poptContext pc;
182
183 pc = poptGetContext(NULL, argc, argv, long_options, 0);
184 poptReadDefaultConfig(pc, 0);
185
186 /* Default event type */
187 opt_event_type = LTTNG_EVENT_TRACEPOINT;
188
189 while ((opt = poptGetNextOpt(pc)) != -1) {
190 switch (opt) {
191 case OPT_HELP:
192 usage(stderr);
193 ret = CMD_SUCCESS;
194 goto end;
d0254c7c
MD
195 case OPT_TRACEPOINT:
196 ret = CMD_NOT_IMPLEMENTED;
197 break;
198 case OPT_MARKER:
199 ret = CMD_NOT_IMPLEMENTED;
200 goto end;
201 case OPT_PROBE:
202 ret = CMD_NOT_IMPLEMENTED;
203 break;
204 case OPT_FUNCTION:
205 opt_event_type = LTTNG_EVENT_FUNCTION;
206 break;
207 case OPT_FUNCTION_ENTRY:
208 ret = CMD_NOT_IMPLEMENTED;
209 break;
a54bd42d 210 case OPT_SYSCALL:
0133c199
MD
211 ret = CMD_NOT_IMPLEMENTED;
212 break;
eeac7d46
MD
213 case OPT_USERSPACE:
214 opt_userspace = 1;
eeac7d46 215 break;
d0254c7c
MD
216 default:
217 usage(stderr);
218 ret = CMD_UNDEFINED;
219 goto end;
220 }
221 }
222
223 ret = calibrate_lttng();
224
225end:
226 return ret;
227}
This page took 0.032924 seconds and 4 git commands to generate.