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
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; only version 2
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.
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.
26 #include <sys/types.h>
31 #include "../command.h"
33 static int opt_event_type
;
34 static char *opt_kernel
;
35 static int opt_userspace
;
37 /* Not implemented yet */
38 static char *opt_cmd_name
;
54 static struct lttng_handle
*handle
;
56 static struct poptOption long_options
[] = {
57 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
58 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
59 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
61 /* Not implemented yet */
62 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
63 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
64 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
65 {"marker", 0, POPT_ARG_NONE
, 0, OPT_MARKER
, 0, 0},
66 {"probe", 0, POPT_ARG_NONE
, 0, OPT_PROBE
, 0, 0},
68 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
69 {"function", 0, POPT_ARG_NONE
, 0, OPT_FUNCTION
, 0, 0},
73 * Removed from options to discourage its use. Not in kernel
76 {"function:entry", 0, POPT_ARG_NONE
, 0, OPT_FUNCTION_ENTRY
, 0, 0},
78 {"syscall", 0, POPT_ARG_NONE
, 0, OPT_SYSCALL
, 0, 0},
79 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
86 static void usage(FILE *ofp
)
88 fprintf(ofp
, "usage: lttng calibrate [options] [calibrate_options]\n");
90 fprintf(ofp
, " -h, --help Show this help\n");
91 fprintf(ofp
, " --list-options Simple listing of options\n");
92 fprintf(ofp
, " -k, --kernel Apply to the kernel tracer\n");
94 fprintf(ofp
, " -u, --userspace [CMD] Apply to the user-space tracer (domain: UST\n");
95 fprintf(ofp
, " EXEC_NAME). If no CMD, the domain is UST global.\n";
96 fprintf(ofp
, " (-k preempts -u)\n");
97 fprintf(ofp
, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
99 fprintf(ofp
, " -u, --userspace Apply to the user-space tracer\n");
102 fprintf(ofp
, "Calibrate options:\n");
104 fprintf(ofp
, " --tracepoint Tracepoint event (default)\n");
105 fprintf(ofp
, " --probe\n");
106 fprintf(ofp
, " Dynamic probe.\n");
108 fprintf(ofp
, " --function:entry symbol\n");
109 fprintf(ofp
, " Function tracer event\n");
111 fprintf(ofp
, " --syscall System call eventl\n");
112 fprintf(ofp
, " --marker User-space marker (deprecated)\n");
114 fprintf(ofp
, " --function Dynamic function entry/return probe (default)\n");
122 * Returns a CMD_* error.
124 static int calibrate_lttng(void)
126 int ret
= CMD_SUCCESS
;
127 struct lttng_domain dom
;
128 struct lttng_calibrate calibrate
;
130 /* Create lttng domain */
132 dom
.type
= LTTNG_DOMAIN_KERNEL
;
133 } else if (opt_userspace
) {
134 dom
.type
= LTTNG_DOMAIN_UST
;
136 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
141 handle
= lttng_create_handle(NULL
, &dom
);
142 if (handle
== NULL
) {
147 switch (opt_event_type
) {
148 case LTTNG_EVENT_TRACEPOINT
:
149 DBG("Calibrating kernel tracepoints");
151 case LTTNG_EVENT_PROBE
:
152 DBG("Calibrating kernel probes");
154 case LTTNG_EVENT_FUNCTION
:
155 DBG("Calibrating kernel functions");
156 calibrate
.type
= LTTNG_CALIBRATE_FUNCTION
;
157 ret
= lttng_calibrate(handle
, &calibrate
);
162 MSG("%s calibration done", opt_kernel
? "Kernel" : "UST");
164 case LTTNG_EVENT_FUNCTION_ENTRY
:
165 DBG("Calibrating kernel function entry");
167 case LTTNG_EVENT_SYSCALL
:
168 DBG("Calibrating kernel syscall");
178 lttng_destroy_handle(handle
);
184 * Calibrate LTTng tracer.
186 int cmd_calibrate(int argc
, const char **argv
)
189 static poptContext pc
;
191 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
192 poptReadDefaultConfig(pc
, 0);
194 /* Default event type */
195 opt_event_type
= LTTNG_EVENT_FUNCTION
;
197 while ((opt
= poptGetNextOpt(pc
)) != -1) {
213 opt_event_type
= LTTNG_EVENT_FUNCTION
;
215 case OPT_FUNCTION_ENTRY
:
224 case OPT_LIST_OPTIONS
:
225 list_cmd_options(stdout
, long_options
);
235 ret
= calibrate_lttng();