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
;
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},
64 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
66 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
67 {"marker", 0, POPT_ARG_NONE
, 0, OPT_MARKER
, 0, 0},
68 {"probe", 0, POPT_ARG_NONE
, 0, OPT_PROBE
, 0, 0},
69 {"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},
84 static void usage(FILE *ofp
)
86 fprintf(ofp
, "usage: lttng calibrate [options] [calibrate_options]\n");
88 fprintf(ofp
, " -h, --help Show this help\n");
89 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
91 fprintf(ofp
, " -u, --userspace [CMD] Apply for the user-space tracer\n");
92 fprintf(ofp
, " If no CMD, the domain used is UST global\n");
93 fprintf(ofp
, " or else the domain is UST EXEC_NAME\n");
94 fprintf(ofp
, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
96 fprintf(ofp
, " -u, --userspace Apply for the user-space tracer\n");
99 fprintf(ofp
, "Calibrate options:\n");
100 fprintf(ofp
, " --tracepoint Tracepoint event (default)\n");
101 fprintf(ofp
, " --probe\n");
102 fprintf(ofp
, " Dynamic probe.\n");
103 fprintf(ofp
, " --function\n");
104 fprintf(ofp
, " Dynamic function entry/return probe.\n");
106 fprintf(ofp
, " --function:entry symbol\n");
107 fprintf(ofp
, " Function tracer event\n");
109 fprintf(ofp
, " --syscall System call eventl\n");
110 fprintf(ofp
, " --marker User-space marker (deprecated)\n");
119 static int calibrate_lttng(void)
121 int ret
= CMD_SUCCESS
;
122 struct lttng_domain dom
;
123 struct lttng_calibrate calibrate
;
125 /* Create lttng domain */
127 dom
.type
= LTTNG_DOMAIN_KERNEL
;
130 handle
= lttng_create_handle(NULL
, &dom
);
131 if (handle
== NULL
) {
136 /* Kernel tracer action */
138 switch (opt_event_type
) {
139 case LTTNG_EVENT_TRACEPOINT
:
140 DBG("Calibrating kernel tracepoints");
142 case LTTNG_EVENT_PROBE
:
143 DBG("Calibrating kernel probes");
145 case LTTNG_EVENT_FUNCTION
:
146 DBG("Calibrating kernel functions");
147 calibrate
.type
= LTTNG_CALIBRATE_FUNCTION
;
148 ret
= lttng_calibrate(handle
, &calibrate
);
150 case LTTNG_EVENT_FUNCTION_ENTRY
:
151 DBG("Calibrating kernel function entry");
153 case LTTNG_EVENT_SYSCALL
:
154 DBG("Calibrating kernel syscall");
160 } else if (opt_userspace
) { /* User-space tracer action */
164 ERR("Please specify a tracer (--kernel or --userspace)");
168 lttng_destroy_handle(handle
);
176 * Calibrate LTTng tracer.
178 int cmd_calibrate(int argc
, const char **argv
)
181 static poptContext pc
;
183 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
184 poptReadDefaultConfig(pc
, 0);
186 /* Default event type */
187 opt_event_type
= LTTNG_EVENT_TRACEPOINT
;
189 while ((opt
= poptGetNextOpt(pc
)) != -1) {
205 opt_event_type
= LTTNG_EVENT_FUNCTION
;
207 case OPT_FUNCTION_ENTRY
:
223 ret
= calibrate_lttng();