2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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; either version 2
7 * of the License, or (at your option) any later version.
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.
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.
25 #include <sys/types.h>
32 static char *opt_output_path
;
33 static char *opt_session_name
;
39 static struct poptOption long_options
[] = {
40 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
41 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
42 {"output", 'o', POPT_ARG_STRING
, &opt_output_path
, 0, 0, 0},
49 static void usage(FILE *ofp
)
51 fprintf(ofp
, "usage: lttng create [options] [NAME]\n");
53 fprintf(ofp
, " -h, --help Show this help\n");
54 fprintf(ofp
, " -o, --output PATH Specify output path\n");
61 * Create a tracing session. If no name specified, a default name will be
64 static int create_session()
68 char *session_name
, *path
= NULL
, *alloc_path
;
72 /* Auto session name creation */
73 if (opt_session_name
== NULL
) {
75 timeinfo
= localtime(&rawtime
);
76 strftime(name
, sizeof(name
), "auto-%Y%m%d-%H%M%S", timeinfo
);
78 DBG("Auto session name set to %s", session_name
);
80 session_name
= opt_session_name
;
83 /* Auto output path */
84 if (opt_output_path
== NULL
) {
85 alloc_path
= config_get_default_path();
86 if (alloc_path
== NULL
) {
91 alloc_path
= opt_output_path
;
94 path
= config_generate_dir_path(alloc_path
);
100 /* Init lttng session config */
101 ret
= config_init(path
);
106 ret
= config_add_session_name(path
, session_name
);
111 ret
= lttng_create_session(session_name
, path
);
116 MSG("Session %s created.", session_name
);
117 MSG("Working directory of created session is %s", path
);
135 * The 'list <options>' first level command
137 int cmd_create(int argc
, const char **argv
)
139 int opt
, ret
= CMD_SUCCESS
;
140 static poptContext pc
;
142 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
143 poptReadDefaultConfig(pc
, 0);
145 while ((opt
= poptGetNextOpt(pc
)) != -1) {
157 opt_session_name
= (char*) poptGetArg(pc
);
159 ret
= create_session();
This page took 0.035663 seconds and 4 git commands to generate.