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