Update version to 2.0-pre18
[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
MD
35static int opt_pid_all;
36static int opt_userspace;
eeac7d46 37static char *opt_cmd_name;
d0254c7c
MD
38static pid_t opt_pid;
39
40enum {
41 OPT_HELP = 1,
d0254c7c
MD
42 OPT_TRACEPOINT,
43 OPT_MARKER,
44 OPT_PROBE,
45 OPT_FUNCTION,
46 OPT_FUNCTION_ENTRY,
a54bd42d 47 OPT_SYSCALL,
eeac7d46 48 OPT_USERSPACE,
d0254c7c
MD
49};
50
cd80958d
DG
51static struct lttng_handle *handle;
52
d0254c7c
MD
53static struct poptOption long_options[] = {
54 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
55 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
56 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
6caa2bcc 57 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
d0254c7c
MD
58 {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0},
59 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
60 {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0},
61 {"marker", 0, POPT_ARG_NONE, 0, OPT_MARKER, 0, 0},
62 {"probe", 0, POPT_ARG_NONE, 0, OPT_PROBE, 0, 0},
63 {"function", 0, POPT_ARG_NONE, 0, OPT_FUNCTION, 0, 0},
b213d387
MD
64#if 0
65 /*
66 * Removed from options to discourage its use. Not in kernel
67 * tracer anymore.
68 */
d0254c7c 69 {"function:entry", 0, POPT_ARG_NONE, 0, OPT_FUNCTION_ENTRY, 0, 0},
b213d387 70#endif
a54bd42d 71 {"syscall", 0, POPT_ARG_NONE, 0, OPT_SYSCALL, 0, 0},
d0254c7c
MD
72 {0, 0, 0, 0, 0, 0, 0}
73};
74
75/*
76 * usage
77 */
78static void usage(FILE *ofp)
79{
80 fprintf(ofp, "usage: lttng calibrate [options] [calibrate_options]\n");
81 fprintf(ofp, "\n");
82 fprintf(ofp, " -h, --help Show this help\n");
83 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
84 fprintf(ofp, " -u, --userspace [CMD] Apply for the user-space tracer\n");
85 fprintf(ofp, " --all If -u, apply on all traceable apps\n");
86 fprintf(ofp, " -p, --pid PID If -u, apply on a specific PID\n");
87 fprintf(ofp, "\n");
88 fprintf(ofp, "Calibrate options:\n");
89 fprintf(ofp, " --tracepoint Tracepoint event (default)\n");
90 fprintf(ofp, " --probe\n");
91 fprintf(ofp, " Dynamic probe.\n");
92 fprintf(ofp, " --function\n");
93 fprintf(ofp, " Dynamic function entry/return probe.\n");
b213d387 94#if 0
d0254c7c
MD
95 fprintf(ofp, " --function:entry symbol\n");
96 fprintf(ofp, " Function tracer event\n");
b213d387 97#endif
a54bd42d 98 fprintf(ofp, " --syscall System call eventl\n");
d0254c7c
MD
99 fprintf(ofp, " --marker User-space marker (deprecated)\n");
100 fprintf(ofp, "\n");
101}
102
103/*
104 * calibrate_lttng
105 *
106 * Calibrate LTTng.
107 */
108static int calibrate_lttng(void)
109{
110 int ret = CMD_SUCCESS;
111 struct lttng_domain dom;
112 struct lttng_calibrate calibrate;
113
114 /* Create lttng domain */
115 if (opt_kernel) {
116 dom.type = LTTNG_DOMAIN_KERNEL;
117 }
118
cd80958d
DG
119 handle = lttng_create_handle(NULL, &dom);
120 if (handle == NULL) {
121 ret = -1;
122 goto end;
123 }
124
d0254c7c
MD
125 /* Kernel tracer action */
126 if (opt_kernel) {
127 switch (opt_event_type) {
128 case LTTNG_EVENT_TRACEPOINT:
129 DBG("Calibrating kernel tracepoints");
130 break;
131 case LTTNG_EVENT_PROBE:
132 DBG("Calibrating kernel probes");
133 break;
134 case LTTNG_EVENT_FUNCTION:
135 DBG("Calibrating kernel functions");
136 calibrate.type = LTTNG_CALIBRATE_FUNCTION;
cd80958d 137 ret = lttng_calibrate(handle, &calibrate);
d0254c7c
MD
138 break;
139 case LTTNG_EVENT_FUNCTION_ENTRY:
140 DBG("Calibrating kernel function entry");
141 break;
a54bd42d
MD
142 case LTTNG_EVENT_SYSCALL:
143 DBG("Calibrating kernel syscall");
0133c199 144 break;
d0254c7c
MD
145 default:
146 ret = CMD_NOT_IMPLEMENTED;
147 goto end;
148 }
149 } else if (opt_userspace) { /* User-space tracer action */
150 /*
151 * TODO: Waiting on lttng UST 2.0
152 */
153 if (opt_pid_all) {
154 } else if (opt_pid != 0) {
155 }
156 ret = CMD_NOT_IMPLEMENTED;
157 goto end;
158 } else {
048e2159 159 ERR("Please specify a tracer (--kernel or --userspace)");
d0254c7c
MD
160 goto end;
161 }
162end:
cd80958d
DG
163 lttng_destroy_handle(handle);
164
d0254c7c
MD
165 return ret;
166}
167
168/*
169 * cmd_calibrate
170 *
171 * Calibrate LTTng tracer.
172 */
173int cmd_calibrate(int argc, const char **argv)
174{
175 int opt, ret;
176 static poptContext pc;
177
178 pc = poptGetContext(NULL, argc, argv, long_options, 0);
179 poptReadDefaultConfig(pc, 0);
180
181 /* Default event type */
182 opt_event_type = LTTNG_EVENT_TRACEPOINT;
183
184 while ((opt = poptGetNextOpt(pc)) != -1) {
185 switch (opt) {
186 case OPT_HELP:
187 usage(stderr);
188 ret = CMD_SUCCESS;
189 goto end;
d0254c7c
MD
190 case OPT_TRACEPOINT:
191 ret = CMD_NOT_IMPLEMENTED;
192 break;
193 case OPT_MARKER:
194 ret = CMD_NOT_IMPLEMENTED;
195 goto end;
196 case OPT_PROBE:
197 ret = CMD_NOT_IMPLEMENTED;
198 break;
199 case OPT_FUNCTION:
200 opt_event_type = LTTNG_EVENT_FUNCTION;
201 break;
202 case OPT_FUNCTION_ENTRY:
203 ret = CMD_NOT_IMPLEMENTED;
204 break;
a54bd42d 205 case OPT_SYSCALL:
0133c199
MD
206 ret = CMD_NOT_IMPLEMENTED;
207 break;
eeac7d46
MD
208 case OPT_USERSPACE:
209 opt_userspace = 1;
eeac7d46 210 break;
d0254c7c
MD
211 default:
212 usage(stderr);
213 ret = CMD_UNDEFINED;
214 goto end;
215 }
216 }
217
218 ret = calibrate_lttng();
219
220end:
221 return ret;
222}
This page took 0.03245 seconds and 4 git commands to generate.