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