d8916653ad1722b00bfec8df45a40e1bc5c8a7d1
1 /* Copyright (C) 2009 Pierre-Marc Fournier
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
49 char *progname
= NULL
;
53 fprintf(stderr
, "usage: %s COMMAND PIDs...\n", progname
);
54 fprintf(stderr
, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\
57 --start-trace\t\t\tStart tracing\n\
58 --stop-trace\t\t\tStop tracing\n\
59 --destroy-trace\t\t\tDestroy the trace\n\
60 --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\
61 --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\
62 --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\
67 int parse_opts_long(int argc
, char **argv
, struct ust_opts
*opts
)
73 opts
->regex_state
= -1;
77 static struct option long_options
[] = {
78 {"start-trace", 0, 0, 1000},
79 {"stop-trace", 0, 0, 1001},
80 {"destroy-trace", 0, 0, 1002},
81 {"list-markers", 0, 0, 1004},
82 {"print-markers", 0, 0, 1005},
84 {"enable-marker", 1, 0, 1007},
85 {"disable-marker", 1, 0, 1008},
86 {"start", 0, 0, 1009},
88 {"version", 0, 0, 1010},
89 {"online-pids", 0, 0, 1011},
93 c
= getopt_long(argc
, argv
, "h", long_options
, &option_index
);
99 printf("option %s", long_options
[option_index
].name
);
101 printf(" with arg %s", optarg
);
106 opts
->cmd
= START_TRACE
;
109 opts
->cmd
= STOP_TRACE
;
118 opts
->cmd
= LIST_MARKERS
;
121 opts
->cmd
= ENABLE_MARKER
;
122 opts
->regex
= strdup(optarg
);
125 opts
->cmd
= DISABLE_MARKER
;
126 opts
->regex
= strdup(optarg
);
129 opts
->cmd
= GET_ONLINE_PIDS
;
135 printf("Version 0.1\n");
138 /* unknown option or other error; error is
139 printed by getopt, just return */
145 if (argc
- optind
> 0 && opts
->cmd
!= GET_ONLINE_PIDS
) {
148 opts
->pids
= malloc((argc
-optind
+1) * sizeof(pid_t
));
150 for(i
=optind
; i
<argc
; i
++) {
151 opts
->pids
[pididx
++] = atoi(argv
[i
]);
153 opts
->pids
[pididx
] = -1;
156 if (opts
->cmd
== ENABLE_MARKER
|| opts
->cmd
== DISABLE_MARKER
) {
157 if (opts
->regex_state
= regcomp(&opts
->preg
, opts
->regex
, 0)) {
158 fprintf(stderr
, "Invalid regular expression.\n");
165 static void regex_change_m_state(struct ust_opts
* opts
, pid_t pid
) {
166 struct USTcmd_cmsf
* cmsf
= NULL
;
168 int e
= (opts
->cmd
== ENABLE_MARKER
);
170 if (opts
->regex_state
!= 0) {
174 if (ustcmd_get_cmsf(&cmsf
, pid
)) {
175 fprintf(stderr
, "error while trying to get markers for PID "
176 "%u\n", (unsigned int) pid
);
179 while (cmsf
[i
].channel
!= NULL
) {
181 asprintf(&mc
, "%s/%s", cmsf
[i
].channel
, cmsf
[i
].marker
);
182 if (regexec(&opts
->preg
, mc
, 0, NULL
, 0) == 0) {
183 /* We got a match! */
184 if (ustcmd_set_marker_state(mc
,
185 e
? USTCMD_MS_ON
: USTCMD_MS_OFF
, pid
)) {
187 "error while trying to %sable marker"
188 "\"%s\" for PID %u\n",
189 e
? "en" : "dis", mc
,
192 printf("sucessfully %sabled marker "
193 "\"%s\" for PID %u\n",
194 e
? "en" : "dis", mc
,
201 ustcmd_free_cmsf(cmsf
);
204 int main(int argc
, char *argv
[])
207 struct ustcomm_connection conn
;
209 struct ust_opts opts
;
214 fprintf(stderr
, "No operation specified.\n");
219 result
= parse_opts_long(argc
, argv
, &opts
);
225 if(opts
.pids
== NULL
&& opts
.cmd
!= GET_ONLINE_PIDS
) {
226 fprintf(stderr
, "No pid specified.\n");
230 if(opts
.cmd
== UNKNOWN
) {
231 fprintf(stderr
, "No command specified.\n");
235 if (opts
.cmd
== GET_ONLINE_PIDS
) {
236 pid_t
* pp
= ustcmd_get_online_pids();
241 printf("%u\n", (unsigned int) pp
[i
]);
251 struct USTcmd_cmsf
* cmsf
= NULL
;
253 while(*pidit
!= -1) {
256 if (ustcmd_start_trace(*pidit
)) {
258 "error while trying to for trace "
259 "with PID %u\n", (unsigned int) *pidit
);
262 printf("sucessfully started trace for PID %u\n",
263 (unsigned int) *pidit
);
267 if (ustcmd_stop_trace(*pidit
)) {
269 "error while trying to stop trace "
270 "for PID %u\n", (unsigned int) *pidit
);
273 printf("sucessfully stopped trace for PID %u\n",
274 (unsigned int) *pidit
);
278 if (ustcmd_setup_and_start(*pidit
)) {
280 "error while trying to setup/start "
281 "trace for PID %u\n",
282 (unsigned int) *pidit
);
285 printf("sucessfully setup/started trace for PID %u\n",
286 (unsigned int) *pidit
);
290 if (ustcmd_destroy_trace(*pidit
)) {
292 "error while trying to destroy "
293 "trace with PID %u\n",
294 (unsigned int) *pidit
);
297 printf("sucessfully destroyed trace for PID %u\n",
298 (unsigned int) *pidit
);
303 if (ustcmd_get_cmsf(&cmsf
, *pidit
)) {
305 "error while trying to list markers for"
306 " PID %u\n", (unsigned int) *pidit
);
310 while (cmsf
[i
].channel
!= NULL
) {
311 printf("{PID: %u, channel/marker: %s/%s, "
312 "state: %u, fs: %s}\n",
313 (unsigned int) *pidit
,
320 ustcmd_free_cmsf(cmsf
);
325 regex_change_m_state(&opts
, *pidit
);
329 fprintf(stderr
, "error: unknown command...\n");
337 if (opts
.pids
!= NULL
) {
340 if (opts
.regex
!= NULL
) {
This page took 0.04751 seconds and 3 git commands to generate.