2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <sys/types.h>
30 #include "../command.h"
32 static int opt_event_type
;
33 static char *opt_kernel
;
34 static int opt_userspace
;
36 /* Not implemented yet */
37 static char *opt_cmd_name
;
53 static struct lttng_handle
*handle
;
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},
60 /* Not implemented yet */
61 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
62 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
63 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
64 {"marker", 0, POPT_ARG_NONE
, 0, OPT_MARKER
, 0, 0},
65 {"probe", 0, POPT_ARG_NONE
, 0, OPT_PROBE
, 0, 0},
67 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
68 {"function", 0, POPT_ARG_NONE
, 0, OPT_FUNCTION
, 0, 0},
72 * Removed from options to discourage its use. Not in kernel
75 {"function:entry", 0, POPT_ARG_NONE
, 0, OPT_FUNCTION_ENTRY
, 0, 0},
77 {"syscall", 0, POPT_ARG_NONE
, 0, OPT_SYSCALL
, 0, 0},
78 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
85 static void usage(FILE *ofp
)
87 fprintf(ofp
, "usage: lttng calibrate [options] [calibrate_options]\n");
89 fprintf(ofp
, " -h, --help Show this help\n");
90 fprintf(ofp
, " --list-options Simple listing of options\n");
91 fprintf(ofp
, " -k, --kernel Apply to the kernel tracer\n");
93 fprintf(ofp
, " -u, --userspace [CMD] Apply to the user-space tracer (domain: UST\n");
94 fprintf(ofp
, " EXEC_NAME). If no CMD, the domain is UST global.\n";
95 fprintf(ofp
, " (-k preempts -u)\n");
96 fprintf(ofp
, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
98 fprintf(ofp
, " -u, --userspace Apply to the user-space tracer\n");
101 fprintf(ofp
, "Calibrate options:\n");
103 fprintf(ofp
, " --tracepoint Tracepoint event (default)\n");
104 fprintf(ofp
, " --probe\n");
105 fprintf(ofp
, " Dynamic probe.\n");
107 fprintf(ofp
, " --function:entry symbol\n");
108 fprintf(ofp
, " Function tracer event\n");
110 fprintf(ofp
, " --syscall System call eventl\n");
111 fprintf(ofp
, " --marker User-space marker (deprecated)\n");
113 fprintf(ofp
, " --function Dynamic function entry/return probe (default)\n");
121 * Returns a CMD_* error.
123 static int calibrate_lttng(void)
125 int ret
= CMD_SUCCESS
;
126 struct lttng_domain dom
;
127 struct lttng_calibrate calibrate
;
129 memset(&dom
, 0, sizeof(dom
));
130 memset(&calibrate
, 0, sizeof(calibrate
));
132 /* Create lttng domain */
134 dom
.type
= LTTNG_DOMAIN_KERNEL
;
135 } else if (opt_userspace
) {
136 dom
.type
= LTTNG_DOMAIN_UST
;
138 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
143 handle
= lttng_create_handle(NULL
, &dom
);
144 if (handle
== NULL
) {
149 switch (opt_event_type
) {
150 case LTTNG_EVENT_TRACEPOINT
:
151 DBG("Calibrating kernel tracepoints");
153 case LTTNG_EVENT_PROBE
:
154 DBG("Calibrating kernel probes");
156 case LTTNG_EVENT_FUNCTION
:
157 DBG("Calibrating kernel functions");
158 calibrate
.type
= LTTNG_CALIBRATE_FUNCTION
;
159 ret
= lttng_calibrate(handle
, &calibrate
);
163 MSG("%s calibration done", opt_kernel
? "Kernel" : "UST");
165 case LTTNG_EVENT_FUNCTION_ENTRY
:
166 DBG("Calibrating kernel function entry");
168 case LTTNG_EVENT_SYSCALL
:
169 DBG("Calibrating kernel syscall");
179 lttng_destroy_handle(handle
);
185 * Calibrate LTTng tracer.
187 * Returns a CMD_* error.
189 int cmd_calibrate(int argc
, const char **argv
)
191 int opt
, ret
= CMD_SUCCESS
;
192 static poptContext pc
;
194 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
195 poptReadDefaultConfig(pc
, 0);
197 /* Default event type */
198 opt_event_type
= LTTNG_EVENT_FUNCTION
;
200 while ((opt
= poptGetNextOpt(pc
)) != -1) {
215 opt_event_type
= LTTNG_EVENT_FUNCTION
;
217 case OPT_FUNCTION_ENTRY
:
226 case OPT_LIST_OPTIONS
:
227 list_cmd_options(stdout
, long_options
);
236 ret
= calibrate_lttng();