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>
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
;
52 static struct poptOption long_options
[] = {
53 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
54 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
55 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
56 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, 0, OPT_USERSPACE
, 0, 0},
57 {"all", 0, POPT_ARG_VAL
, &opt_pid_all
, 1, 0, 0},
58 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
59 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
60 {"marker", 0, POPT_ARG_NONE
, 0, OPT_MARKER
, 0, 0},
61 {"probe", 0, POPT_ARG_NONE
, 0, OPT_PROBE
, 0, 0},
62 {"function", 0, POPT_ARG_NONE
, 0, OPT_FUNCTION
, 0, 0},
63 {"function:entry", 0, POPT_ARG_NONE
, 0, OPT_FUNCTION_ENTRY
, 0, 0},
70 static void usage(FILE *ofp
)
72 fprintf(ofp
, "usage: lttng calibrate [options] [calibrate_options]\n");
74 fprintf(ofp
, " -h, --help Show this help\n");
75 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
76 fprintf(ofp
, " -u, --userspace [CMD] Apply for the user-space tracer\n");
77 fprintf(ofp
, " --all If -u, apply on all traceable apps\n");
78 fprintf(ofp
, " -p, --pid PID If -u, apply on a specific PID\n");
80 fprintf(ofp
, "Calibrate options:\n");
81 fprintf(ofp
, " --tracepoint Tracepoint event (default)\n");
82 fprintf(ofp
, " --probe\n");
83 fprintf(ofp
, " Dynamic probe.\n");
84 fprintf(ofp
, " --function\n");
85 fprintf(ofp
, " Dynamic function entry/return probe.\n");
86 fprintf(ofp
, " --function:entry symbol\n");
87 fprintf(ofp
, " Function tracer event\n");
88 fprintf(ofp
, " --marker User-space marker (deprecated)\n");
97 static int calibrate_lttng(void)
99 int ret
= CMD_SUCCESS
;
100 struct lttng_domain dom
;
101 struct lttng_calibrate calibrate
;
103 /* Create lttng domain */
105 dom
.type
= LTTNG_DOMAIN_KERNEL
;
108 /* Kernel tracer action */
110 switch (opt_event_type
) {
111 case LTTNG_EVENT_TRACEPOINT
:
112 DBG("Calibrating kernel tracepoints");
114 case LTTNG_EVENT_PROBE
:
115 DBG("Calibrating kernel probes");
117 case LTTNG_EVENT_FUNCTION
:
118 DBG("Calibrating kernel functions");
119 calibrate
.type
= LTTNG_CALIBRATE_FUNCTION
;
120 ret
= lttng_calibrate(&dom
, &calibrate
);
122 case LTTNG_EVENT_FUNCTION_ENTRY
:
123 DBG("Calibrating kernel function entry");
126 ret
= CMD_NOT_IMPLEMENTED
;
129 } else if (opt_userspace
) { /* User-space tracer action */
131 * TODO: Waiting on lttng UST 2.0
134 } else if (opt_pid
!= 0) {
136 ret
= CMD_NOT_IMPLEMENTED
;
139 ERR("Please specify a tracer (--kernel or --userspace)");
149 * Calibrate LTTng tracer.
151 int cmd_calibrate(int argc
, const char **argv
)
154 static poptContext pc
;
156 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
157 poptReadDefaultConfig(pc
, 0);
159 /* Default event type */
160 opt_event_type
= LTTNG_EVENT_TRACEPOINT
;
162 while ((opt
= poptGetNextOpt(pc
)) != -1) {
170 opt_cmd_name
= poptGetOptArg(pc
);
173 ret
= CMD_NOT_IMPLEMENTED
;
176 ret
= CMD_NOT_IMPLEMENTED
;
179 ret
= CMD_NOT_IMPLEMENTED
;
182 opt_event_type
= LTTNG_EVENT_FUNCTION
;
184 case OPT_FUNCTION_ENTRY
:
185 ret
= CMD_NOT_IMPLEMENTED
;
194 ret
= calibrate_lttng();