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_pid_all
;
36 static int opt_userspace
;
37 static char *opt_cmd_name
;
51 static struct lttng_handle
*handle
;
53 static struct poptOption long_options
[] = {
54 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
55 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
56 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
57 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
58 {"all", 0, POPT_ARG_VAL
, &opt_pid_all
, 1, 0, 0},
59 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
60 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
61 {"marker", 0, POPT_ARG_NONE
, 0, OPT_MARKER
, 0, 0},
62 {"probe", 0, POPT_ARG_NONE
, 0, OPT_PROBE
, 0, 0},
63 {"function", 0, POPT_ARG_NONE
, 0, OPT_FUNCTION
, 0, 0},
66 * Removed from options to discourage its use. Not in kernel
69 {"function:entry", 0, POPT_ARG_NONE
, 0, OPT_FUNCTION_ENTRY
, 0, 0},
71 {"syscall", 0, POPT_ARG_NONE
, 0, OPT_SYSCALL
, 0, 0},
78 static void usage(FILE *ofp
)
80 fprintf(ofp
, "usage: lttng calibrate [options] [calibrate_options]\n");
82 fprintf(ofp
, " -h, --help Show this help\n");
83 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
84 fprintf(ofp
, " -u, --userspace [CMD] Apply for the user-space tracer\n");
85 fprintf(ofp
, " --all If -u, apply on all traceable apps\n");
86 fprintf(ofp
, " -p, --pid PID If -u, apply on a specific PID\n");
88 fprintf(ofp
, "Calibrate options:\n");
89 fprintf(ofp
, " --tracepoint Tracepoint event (default)\n");
90 fprintf(ofp
, " --probe\n");
91 fprintf(ofp
, " Dynamic probe.\n");
92 fprintf(ofp
, " --function\n");
93 fprintf(ofp
, " Dynamic function entry/return probe.\n");
95 fprintf(ofp
, " --function:entry symbol\n");
96 fprintf(ofp
, " Function tracer event\n");
98 fprintf(ofp
, " --syscall System call eventl\n");
99 fprintf(ofp
, " --marker User-space marker (deprecated)\n");
108 static int calibrate_lttng(void)
110 int ret
= CMD_SUCCESS
;
111 struct lttng_domain dom
;
112 struct lttng_calibrate calibrate
;
114 /* Create lttng domain */
116 dom
.type
= LTTNG_DOMAIN_KERNEL
;
119 handle
= lttng_create_handle(NULL
, &dom
);
120 if (handle
== NULL
) {
125 /* Kernel tracer action */
127 switch (opt_event_type
) {
128 case LTTNG_EVENT_TRACEPOINT
:
129 DBG("Calibrating kernel tracepoints");
131 case LTTNG_EVENT_PROBE
:
132 DBG("Calibrating kernel probes");
134 case LTTNG_EVENT_FUNCTION
:
135 DBG("Calibrating kernel functions");
136 calibrate
.type
= LTTNG_CALIBRATE_FUNCTION
;
137 ret
= lttng_calibrate(handle
, &calibrate
);
139 case LTTNG_EVENT_FUNCTION_ENTRY
:
140 DBG("Calibrating kernel function entry");
142 case LTTNG_EVENT_SYSCALL
:
143 DBG("Calibrating kernel syscall");
146 ret
= CMD_NOT_IMPLEMENTED
;
149 } else if (opt_userspace
) { /* User-space tracer action */
151 * TODO: Waiting on lttng UST 2.0
154 } else if (opt_pid
!= 0) {
156 ret
= CMD_NOT_IMPLEMENTED
;
159 ERR("Please specify a tracer (--kernel or --userspace)");
163 lttng_destroy_handle(handle
);
171 * Calibrate LTTng tracer.
173 int cmd_calibrate(int argc
, const char **argv
)
176 static poptContext pc
;
178 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
179 poptReadDefaultConfig(pc
, 0);
181 /* Default event type */
182 opt_event_type
= LTTNG_EVENT_TRACEPOINT
;
184 while ((opt
= poptGetNextOpt(pc
)) != -1) {
191 ret
= CMD_NOT_IMPLEMENTED
;
194 ret
= CMD_NOT_IMPLEMENTED
;
197 ret
= CMD_NOT_IMPLEMENTED
;
200 opt_event_type
= LTTNG_EVENT_FUNCTION
;
202 case OPT_FUNCTION_ENTRY
:
203 ret
= CMD_NOT_IMPLEMENTED
;
206 ret
= CMD_NOT_IMPLEMENTED
;
218 ret
= calibrate_lttng();