Initialize all stack variables to zero, fix uninitialized loglevel variables
[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,
679b4943 51 OPT_LIST_OPTIONS,
d0254c7c
MD
52};
53
cd80958d
DG
54static struct lttng_handle *handle;
55
d0254c7c
MD
56static struct poptOption long_options[] = {
57 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
58 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
59 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
d78d6610
DG
60#if 0
61 /* Not implemented yet */
6caa2bcc 62 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
d0254c7c
MD
63 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
64 {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0},
65 {"marker", 0, POPT_ARG_NONE, 0, OPT_MARKER, 0, 0},
66 {"probe", 0, POPT_ARG_NONE, 0, OPT_PROBE, 0, 0},
4466912f
DG
67#else
68 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
d0254c7c 69 {"function", 0, POPT_ARG_NONE, 0, OPT_FUNCTION, 0, 0},
4466912f 70#endif
b213d387
MD
71#if 0
72 /*
73 * Removed from options to discourage its use. Not in kernel
74 * tracer anymore.
75 */
d0254c7c 76 {"function:entry", 0, POPT_ARG_NONE, 0, OPT_FUNCTION_ENTRY, 0, 0},
b213d387 77#endif
a54bd42d 78 {"syscall", 0, POPT_ARG_NONE, 0, OPT_SYSCALL, 0, 0},
679b4943 79 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
d0254c7c
MD
80 {0, 0, 0, 0, 0, 0, 0}
81};
82
83/*
84 * usage
85 */
86static void usage(FILE *ofp)
87{
88 fprintf(ofp, "usage: lttng calibrate [options] [calibrate_options]\n");
89 fprintf(ofp, "\n");
90 fprintf(ofp, " -h, --help Show this help\n");
679b4943 91 fprintf(ofp, " --list-options Simple listing of options\n");
af87c45a 92 fprintf(ofp, " -k, --kernel Apply to the kernel tracer\n");
d78d6610 93#if 0
af87c45a
DG
94 fprintf(ofp, " -u, --userspace [CMD] Apply to the user-space tracer (domain: UST\n");
95 fprintf(ofp, " EXEC_NAME). If no CMD, the domain is UST global.\n";
96 fprintf(ofp, " (-k preempts -u)\n");
d78d6610
DG
97 fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
98#else
af87c45a 99 fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
d78d6610 100#endif
d0254c7c
MD
101 fprintf(ofp, "\n");
102 fprintf(ofp, "Calibrate options:\n");
4466912f 103#if 0
d0254c7c
MD
104 fprintf(ofp, " --tracepoint Tracepoint event (default)\n");
105 fprintf(ofp, " --probe\n");
106 fprintf(ofp, " Dynamic probe.\n");
b213d387 107#if 0
d0254c7c
MD
108 fprintf(ofp, " --function:entry symbol\n");
109 fprintf(ofp, " Function tracer event\n");
b213d387 110#endif
a54bd42d 111 fprintf(ofp, " --syscall System call eventl\n");
d0254c7c 112 fprintf(ofp, " --marker User-space marker (deprecated)\n");
4466912f
DG
113#else
114 fprintf(ofp, " --function Dynamic function entry/return probe (default)\n");
115#endif
d0254c7c
MD
116 fprintf(ofp, "\n");
117}
118
119/*
af87c45a 120 * Calibrate LTTng.
d0254c7c 121 *
af87c45a 122 * Returns a CMD_* error.
d0254c7c
MD
123 */
124static int calibrate_lttng(void)
125{
126 int ret = CMD_SUCCESS;
127 struct lttng_domain dom;
128 struct lttng_calibrate calibrate;
129
441c16a7
MD
130 memset(&dom, 0, sizeof(dom));
131 memset(&calibrate, 0, sizeof(calibrate));
132
d0254c7c
MD
133 /* Create lttng domain */
134 if (opt_kernel) {
135 dom.type = LTTNG_DOMAIN_KERNEL;
4466912f
DG
136 } else if (opt_userspace) {
137 dom.type = LTTNG_DOMAIN_UST;
138 } else {
139 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
d16c1a4c 140 ret = CMD_ERROR;
4466912f 141 goto error;
d0254c7c
MD
142 }
143
cd80958d
DG
144 handle = lttng_create_handle(NULL, &dom);
145 if (handle == NULL) {
af87c45a 146 ret = CMD_ERROR;
4466912f 147 goto error;
cd80958d
DG
148 }
149
4466912f
DG
150 switch (opt_event_type) {
151 case LTTNG_EVENT_TRACEPOINT:
152 DBG("Calibrating kernel tracepoints");
153 break;
154 case LTTNG_EVENT_PROBE:
155 DBG("Calibrating kernel probes");
156 break;
157 case LTTNG_EVENT_FUNCTION:
158 DBG("Calibrating kernel functions");
159 calibrate.type = LTTNG_CALIBRATE_FUNCTION;
160 ret = lttng_calibrate(handle, &calibrate);
161 if (ret < 0) {
162 goto error;
d0254c7c 163 }
4466912f
DG
164 MSG("%s calibration done", opt_kernel ? "Kernel" : "UST");
165 break;
166 case LTTNG_EVENT_FUNCTION_ENTRY:
167 DBG("Calibrating kernel function entry");
168 break;
169 case LTTNG_EVENT_SYSCALL:
170 DBG("Calibrating kernel syscall");
171 break;
172 default:
1ab1ea0b 173 ret = CMD_UNDEFINED;
4466912f 174 goto error;
d0254c7c 175 }
4466912f 176
af87c45a
DG
177 ret = CMD_SUCCESS;
178
4466912f 179error:
cd80958d
DG
180 lttng_destroy_handle(handle);
181
d0254c7c
MD
182 return ret;
183}
184
185/*
af87c45a 186 * Calibrate LTTng tracer.
1c8d13c8
TD
187 *
188 * Returns a CMD_* error.
d0254c7c
MD
189 */
190int cmd_calibrate(int argc, const char **argv)
191{
ca1c3607 192 int opt, ret = CMD_SUCCESS;
d0254c7c
MD
193 static poptContext pc;
194
195 pc = poptGetContext(NULL, argc, argv, long_options, 0);
196 poptReadDefaultConfig(pc, 0);
197
198 /* Default event type */
4466912f 199 opt_event_type = LTTNG_EVENT_FUNCTION;
d0254c7c
MD
200
201 while ((opt = poptGetNextOpt(pc)) != -1) {
202 switch (opt) {
203 case OPT_HELP:
af87c45a 204 usage(stdout);
d0254c7c 205 goto end;
d0254c7c 206 case OPT_TRACEPOINT:
1ab1ea0b 207 ret = CMD_UNDEFINED;
4466912f 208 goto end;
d0254c7c 209 case OPT_MARKER:
1ab1ea0b 210 ret = CMD_UNDEFINED;
d0254c7c
MD
211 goto end;
212 case OPT_PROBE:
1ab1ea0b 213 ret = CMD_UNDEFINED;
d0254c7c
MD
214 break;
215 case OPT_FUNCTION:
216 opt_event_type = LTTNG_EVENT_FUNCTION;
217 break;
218 case OPT_FUNCTION_ENTRY:
1ab1ea0b 219 ret = CMD_UNDEFINED;
4466912f 220 goto end;
a54bd42d 221 case OPT_SYSCALL:
1ab1ea0b 222 ret = CMD_UNDEFINED;
4466912f 223 goto end;
eeac7d46
MD
224 case OPT_USERSPACE:
225 opt_userspace = 1;
eeac7d46 226 break;
679b4943
SM
227 case OPT_LIST_OPTIONS:
228 list_cmd_options(stdout, long_options);
679b4943 229 goto end;
d0254c7c
MD
230 default:
231 usage(stderr);
232 ret = CMD_UNDEFINED;
233 goto end;
234 }
235 }
236
237 ret = calibrate_lttng();
238
239end:
ca1c3607 240 poptFreeContext(pc);
d0254c7c
MD
241 return ret;
242}
This page took 0.035751 seconds and 4 git commands to generate.