fcf6e128941877a46322827b046e3d79e5043c6d
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 static char *opt_output_path
;
32 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
, NULL
, OPT_HELP
, NULL
, NULL
},
42 {"output", 'o', POPT_ARG_STRING
, &opt_output_path
, 0, NULL
, NULL
},
43 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
50 static void usage(FILE *ofp
)
52 fprintf(ofp
, "usage: lttng create [options] [NAME]\n");
54 fprintf(ofp
, " The default NAME is 'auto-yyyymmdd-hhmmss'\n");
55 fprintf(ofp
, " -h, --help Show this help\n");
56 fprintf(ofp
, " --list-options Simple listing of options\n");
57 fprintf(ofp
, " -o, --output PATH Specify output path for traces\n");
62 * Create a tracing session.
63 * If no name is specified, a default name is generated.
65 * Returns one of the CMD_* result constants.
67 static int create_session()
69 int ret
, have_name
= 0;
71 char *session_name
, *traces_path
= NULL
, *alloc_path
= NULL
;
75 /* Get date and time for automatic session name/path */
77 timeinfo
= localtime(&rawtime
);
78 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
80 /* Auto session name creation */
81 if (opt_session_name
== NULL
) {
82 ret
= asprintf(&session_name
, "auto-%s", datetime
);
84 perror("asprintf session name");
87 DBG("Auto session name set to %s", session_name
);
89 session_name
= opt_session_name
;
93 /* Auto output path */
94 if (opt_output_path
== NULL
) {
95 alloc_path
= strdup(config_get_default_path());
96 if (alloc_path
== NULL
) {
97 ERR("Home path not found.\n \
98 Please specify an output path using -o, --output PATH");
104 ret
= asprintf(&traces_path
, "%s/" DEFAULT_TRACE_DIR_NAME
105 "/%s-%s", alloc_path
, session_name
, datetime
);
107 ret
= asprintf(&traces_path
, "%s/" DEFAULT_TRACE_DIR_NAME
108 "/%s", alloc_path
, session_name
);
112 perror("asprintf trace dir name");
116 traces_path
= opt_output_path
;
119 ret
= lttng_create_session(session_name
, traces_path
);
121 /* Don't set ret so lttng can interpret the sessiond error. */
125 /* Init lttng session config */
126 ret
= config_init(session_name
);
132 MSG("Session %s created.", session_name
);
133 MSG("Traces will be written in %s" , traces_path
);
138 if (opt_session_name
== NULL
) {
153 * The 'create <options>' first level command
155 * Returns one of the CMD_* result constants.
157 int cmd_create(int argc
, const char **argv
)
159 int opt
, ret
= CMD_SUCCESS
;
160 static poptContext pc
;
162 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
163 poptReadDefaultConfig(pc
, 0);
165 while ((opt
= poptGetNextOpt(pc
)) != -1) {
170 case OPT_LIST_OPTIONS
:
171 list_cmd_options(stdout
, long_options
);
180 opt_session_name
= (char*) poptGetArg(pc
);
182 ret
= create_session();
This page took 0.057138 seconds and 4 git commands to generate.