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