2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program 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
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/types.h>
28 #include "../command.h"
31 #include <common/sessiond-comm/sessiond-comm.h>
33 static char *opt_output_path
;
34 static char *opt_session_name
;
41 static struct poptOption long_options
[] = {
42 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
43 {"help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
44 {"output", 'o', POPT_ARG_STRING
, &opt_output_path
, 0, NULL
, NULL
},
45 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
52 static void usage(FILE *ofp
)
54 fprintf(ofp
, "usage: lttng create [options] [NAME]\n");
56 fprintf(ofp
, " The default NAME is 'auto-yyyymmdd-hhmmss'\n");
57 fprintf(ofp
, " -h, --help Show this help\n");
58 fprintf(ofp
, " --list-options Simple listing of options\n");
59 fprintf(ofp
, " -o, --output PATH Specify output path for traces\n");
64 * Create a tracing session.
65 * If no name is specified, a default name is generated.
67 * Returns one of the CMD_* result constants.
69 static int create_session()
71 int ret
, have_name
= 0;
73 char *session_name
, *traces_path
= NULL
, *alloc_path
= NULL
;
77 /* Get date and time for automatic session name/path */
79 timeinfo
= localtime(&rawtime
);
80 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
82 /* Auto session name creation */
83 if (opt_session_name
== NULL
) {
84 ret
= asprintf(&session_name
, "auto-%s", datetime
);
86 perror("asprintf session name");
89 DBG("Auto session name set to %s", session_name
);
91 session_name
= opt_session_name
;
95 /* Auto output path */
96 if (opt_output_path
== NULL
) {
97 alloc_path
= strdup(config_get_default_path());
98 if (alloc_path
== NULL
) {
99 ERR("Home path not found.\n \
100 Please specify an output path using -o, --output PATH");
106 ret
= asprintf(&traces_path
, "%s/" DEFAULT_TRACE_DIR_NAME
107 "/%s-%s", alloc_path
, session_name
, datetime
);
109 ret
= asprintf(&traces_path
, "%s/" DEFAULT_TRACE_DIR_NAME
110 "/%s", alloc_path
, session_name
);
114 perror("asprintf trace dir name");
118 traces_path
= expand_full_path(opt_output_path
);
119 if (traces_path
== NULL
) {
125 ret
= lttng_create_session(session_name
, traces_path
);
127 /* Don't set ret so lttng can interpret the sessiond error. */
129 case LTTCOMM_EXIST_SESS
:
130 WARN("Session %s already exists", session_name
);
136 /* Init lttng session config */
137 ret
= config_init(session_name
);
143 MSG("Session %s created.", session_name
);
144 MSG("Traces will be written in %s" , traces_path
);
149 if (opt_session_name
== NULL
) {
164 * The 'create <options>' first level command
166 * Returns one of the CMD_* result constants.
168 int cmd_create(int argc
, const char **argv
)
170 int opt
, ret
= CMD_SUCCESS
;
171 static poptContext pc
;
173 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
174 poptReadDefaultConfig(pc
, 0);
176 while ((opt
= poptGetNextOpt(pc
)) != -1) {
181 case OPT_LIST_OPTIONS
:
182 list_cmd_options(stdout
, long_options
);
191 opt_session_name
= (char*) poptGetArg(pc
);
193 ret
= create_session();
This page took 0.039001 seconds and 4 git commands to generate.