Add calibrate command
[lttng-tools.git] / lttng / commands / calibrate.c
CommitLineData
d0254c7c
MD
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
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
8 * of the License.
9 *
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.
14 *
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.
18 */
19
20#define _GNU_SOURCE
21#include <popt.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <sys/stat.h>
26#include <sys/types.h>
27#include <unistd.h>
28#include <inttypes.h>
29#include <ctype.h>
30
31#include "../cmd.h"
32#include "../conf.h"
33#include "../utils.h"
34
35static int opt_event_type;
36static char *opt_kernel;
37static char *opt_cmd_name;
38static int opt_pid_all;
39static int opt_userspace;
40static pid_t opt_pid;
41
42enum {
43 OPT_HELP = 1,
44 OPT_USERSPACE,
45 OPT_TRACEPOINT,
46 OPT_MARKER,
47 OPT_PROBE,
48 OPT_FUNCTION,
49 OPT_FUNCTION_ENTRY,
50};
51
52static 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},
64 {0, 0, 0, 0, 0, 0, 0}
65};
66
67/*
68 * usage
69 */
70static void usage(FILE *ofp)
71{
72 fprintf(ofp, "usage: lttng calibrate [options] [calibrate_options]\n");
73 fprintf(ofp, "\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");
79 fprintf(ofp, "\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");
89 fprintf(ofp, "\n");
90}
91
92/*
93 * calibrate_lttng
94 *
95 * Calibrate LTTng.
96 */
97static int calibrate_lttng(void)
98{
99 int ret = CMD_SUCCESS;
100 struct lttng_domain dom;
101 struct lttng_calibrate calibrate;
102
103 /* Create lttng domain */
104 if (opt_kernel) {
105 dom.type = LTTNG_DOMAIN_KERNEL;
106 }
107
108 /* Kernel tracer action */
109 if (opt_kernel) {
110 switch (opt_event_type) {
111 case LTTNG_EVENT_TRACEPOINT:
112 DBG("Calibrating kernel tracepoints");
113 break;
114 case LTTNG_EVENT_PROBE:
115 DBG("Calibrating kernel probes");
116 break;
117 case LTTNG_EVENT_FUNCTION:
118 DBG("Calibrating kernel functions");
119 calibrate.type = LTTNG_CALIBRATE_FUNCTION;
120 ret = lttng_calibrate(&dom, &calibrate);
121 break;
122 case LTTNG_EVENT_FUNCTION_ENTRY:
123 DBG("Calibrating kernel function entry");
124 break;
125 default:
126 ret = CMD_NOT_IMPLEMENTED;
127 goto end;
128 }
129 } else if (opt_userspace) { /* User-space tracer action */
130 /*
131 * TODO: Waiting on lttng UST 2.0
132 */
133 if (opt_pid_all) {
134 } else if (opt_pid != 0) {
135 }
136 ret = CMD_NOT_IMPLEMENTED;
137 goto end;
138 } else {
139 ERR("Please specify a tracer (kernel or user-space)");
140 goto end;
141 }
142end:
143 return ret;
144}
145
146/*
147 * cmd_calibrate
148 *
149 * Calibrate LTTng tracer.
150 */
151int cmd_calibrate(int argc, const char **argv)
152{
153 int opt, ret;
154 static poptContext pc;
155
156 pc = poptGetContext(NULL, argc, argv, long_options, 0);
157 poptReadDefaultConfig(pc, 0);
158
159 /* Default event type */
160 opt_event_type = LTTNG_EVENT_TRACEPOINT;
161
162 while ((opt = poptGetNextOpt(pc)) != -1) {
163 switch (opt) {
164 case OPT_HELP:
165 usage(stderr);
166 ret = CMD_SUCCESS;
167 goto end;
168 case OPT_USERSPACE:
169 opt_userspace = 1;
170 opt_cmd_name = poptGetOptArg(pc);
171 break;
172 case OPT_TRACEPOINT:
173 ret = CMD_NOT_IMPLEMENTED;
174 break;
175 case OPT_MARKER:
176 ret = CMD_NOT_IMPLEMENTED;
177 goto end;
178 case OPT_PROBE:
179 ret = CMD_NOT_IMPLEMENTED;
180 break;
181 case OPT_FUNCTION:
182 opt_event_type = LTTNG_EVENT_FUNCTION;
183 break;
184 case OPT_FUNCTION_ENTRY:
185 ret = CMD_NOT_IMPLEMENTED;
186 break;
187 default:
188 usage(stderr);
189 ret = CMD_UNDEFINED;
190 goto end;
191 }
192 }
193
194 ret = calibrate_lttng();
195
196end:
197 return ret;
198}
This page took 0.029906 seconds and 4 git commands to generate.