Add new API call lttng_channel_set_default_attr
[lttng-tools.git] / lttng / commands / start.c
... / ...
CommitLineData
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; only version 2
7 * of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#define _GNU_SOURCE
20#include <popt.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26#include <unistd.h>
27
28#include "../cmd.h"
29#include "../conf.h"
30#include "../utils.h"
31
32static char *opt_session_name;
33
34enum {
35 OPT_HELP = 1,
36};
37
38static struct lttng_handle *handle;
39
40static struct poptOption long_options[] = {
41 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
42 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
43 {0, 0, 0, 0, 0, 0, 0}
44};
45
46/*
47 * usage
48 */
49static void usage(FILE *ofp)
50{
51 fprintf(ofp, "usage: lttng start [options] [NAME]\n");
52 fprintf(ofp, "\n");
53 fprintf(ofp, "Where NAME is an optional session name. If not specified, lttng will\n");
54 fprintf(ofp, "get it from the configuration directory (.lttng).\n");
55 fprintf(ofp, "\n");
56 fprintf(ofp, " -h, --help Show this help\n");
57 fprintf(ofp, "\n");
58}
59
60/*
61 * start_tracing
62 *
63 * Start tracing for all trace of the session.
64 */
65static int start_tracing(void)
66{
67 int ret = CMD_SUCCESS;
68 char *session_name;
69
70 if (opt_session_name == NULL) {
71 session_name = get_session_name();
72 if (session_name == NULL) {
73 ret = CMD_ERROR;
74 goto error;
75 }
76 } else {
77 session_name = opt_session_name;
78 }
79
80 handle = lttng_create_handle(session_name, NULL);
81 if (handle == NULL) {
82 ret = -1;
83 goto error;
84 }
85
86 DBG("Starting tracing for session %s", session_name);
87
88 ret = lttng_start_tracing(handle);
89 if (ret < 0) {
90 goto free_name;
91 }
92
93 MSG("Tracing started for session %s", session_name);
94
95free_name:
96 if (opt_session_name == NULL) {
97 free(session_name);
98 }
99error:
100 lttng_destroy_handle(handle);
101
102 return ret;
103}
104
105/*
106 * cmd_start
107 *
108 * The 'start <options>' first level command
109 */
110int cmd_start(int argc, const char **argv)
111{
112 int opt, ret;
113 static poptContext pc;
114
115 pc = poptGetContext(NULL, argc, argv, long_options, 0);
116 poptReadDefaultConfig(pc, 0);
117
118 while ((opt = poptGetNextOpt(pc)) != -1) {
119 switch (opt) {
120 case OPT_HELP:
121 usage(stderr);
122 ret = CMD_SUCCESS;
123 goto end;
124 default:
125 usage(stderr);
126 ret = CMD_UNDEFINED;
127 goto end;
128 }
129 }
130
131 opt_session_name = (char*) poptGetArg(pc);
132
133 ret = start_tracing();
134
135end:
136 return ret;
137}
This page took 0.023129 seconds and 4 git commands to generate.