8052826a245296b0d2d9c310165385a11c5f6ad9
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; only version 2
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>
29 #include "../command.h"
32 static char *opt_output_path
;
33 static char *opt_session_name
;
40 static struct poptOption long_options
[] = {
41 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
42 {"help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
43 {"output", 'o', POPT_ARG_STRING
, &opt_output_path
, 0, NULL
, NULL
},
44 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
51 static void usage(FILE *ofp
)
53 fprintf(ofp
, "usage: lttng create [options] [NAME]\n");
55 fprintf(ofp
, " The default NAME is 'auto-yyyymmdd-hhmmss'\n");
56 fprintf(ofp
, " -h, --help Show this help\n");
57 fprintf(ofp
, " --list-options Simple listing of options\n");
58 fprintf(ofp
, " -o, --output PATH Specify output path for traces\n");
63 * Create a tracing session.
64 * If no name is specified, a default name is generated.
66 * Returns one of the CMD_* result constants.
68 static int create_session()
70 int ret
, have_name
= 0;
72 char *session_name
, *traces_path
= NULL
, *alloc_path
= NULL
;
76 /* Get date and time for automatic session name/path */
78 timeinfo
= localtime(&rawtime
);
79 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
81 /* Auto session name creation */
82 if (opt_session_name
== NULL
) {
83 ret
= asprintf(&session_name
, "auto-%s", datetime
);
85 perror("asprintf session name");
88 DBG("Auto session name set to %s", session_name
);
90 session_name
= opt_session_name
;
94 /* Auto output path */
95 if (opt_output_path
== NULL
) {
96 alloc_path
= strdup(config_get_default_path());
97 if (alloc_path
== NULL
) {
98 ERR("Home path not found.\n \
99 Please specify an output path using -o, --output PATH");
105 ret
= asprintf(&traces_path
, "%s/" DEFAULT_TRACE_DIR_NAME
106 "/%s-%s", alloc_path
, session_name
, datetime
);
108 ret
= asprintf(&traces_path
, "%s/" DEFAULT_TRACE_DIR_NAME
109 "/%s", alloc_path
, session_name
);
113 perror("asprintf trace dir name");
117 traces_path
= opt_output_path
;
120 ret
= lttng_create_session(session_name
, traces_path
);
122 /* Don't set ret so lttng can interpret the sessiond error. */
126 /* Init lttng session config */
127 ret
= config_init(session_name
);
133 MSG("Session %s created.", session_name
);
134 MSG("Traces will be written in %s" , traces_path
);
139 if (opt_session_name
== NULL
) {
154 * The 'create <options>' first level command
156 * Returns one of the CMD_* result constants.
158 int cmd_create(int argc
, const char **argv
)
160 int opt
, ret
= CMD_SUCCESS
;
161 static poptContext pc
;
163 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
164 poptReadDefaultConfig(pc
, 0);
166 while ((opt
= poptGetNextOpt(pc
)) != -1) {
171 case OPT_LIST_OPTIONS
:
172 list_cmd_options(stdout
, long_options
);
181 opt_session_name
= (char*) poptGetArg(pc
);
183 ret
= create_session();
This page took 0.039847 seconds and 4 git commands to generate.