2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 #include "common/assert.h"
28 #include <babeltrace2/babeltrace.h>
33 void print_usage(FILE *fp
)
35 fprintf(stderr
, "Usage: babeltrace2-log [OPTIONS] OUTPUT-PATH\n");
36 fprintf(stderr
, "\n");
37 fprintf(stderr
, "Options:\n");
38 fprintf(stderr
, "\n");
39 fprintf(stderr
, " -t, --with-timestamps Extract timestamps from lines and map them to\n");
40 fprintf(stderr
, " a CTF clock class\n");
44 int parse_params(int argc
, char *argv
[], char **output_path
,
48 OPT_WITH_TIMESTAMPS
= 1,
51 static struct poptOption opts
[] = {
52 { "with-timestamps", 't', POPT_ARG_NONE
, NULL
, OPT_WITH_TIMESTAMPS
, NULL
, NULL
},
53 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
54 { NULL
, '\0', 0, NULL
, 0, NULL
, NULL
},
56 poptContext pc
= NULL
;
61 *no_extract_ts
= true;
62 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, opts
, 0);
64 fprintf(stderr
, "Cannot get popt context\n");
68 poptReadDefaultConfig(pc
, 0);
70 while ((opt
= poptGetNextOpt(pc
)) > 0) {
75 case OPT_WITH_TIMESTAMPS
:
76 *no_extract_ts
= false;
79 fprintf(stderr
, "Unknown command-line option specified (option code %d)\n",
86 fprintf(stderr
, "While parsing command-line options, at option %s: %s\n",
87 poptBadOption(pc
, 0), poptStrerror(opt
));
91 leftover
= poptGetArg(pc
);
93 fprintf(stderr
, "Command line error: Missing output path\n");
98 *output_path
= strdup(leftover
);
99 BT_ASSERT(*output_path
);
113 int main(int argc
, char *argv
[])
115 char *output_path
= NULL
;
118 GError
*error
= NULL
;
123 "dmesg:src.text.dmesg",
125 NULL
, /* no-extract-timestamp=? placeholder */
131 NULL
, /* output path placeholder */
139 retcode
= parse_params(argc
, argv
, &output_path
, &no_extract_ts
);
145 bt_argv
[5] = "no-extract-timestamp=yes";
147 bt_argv
[5] = "no-extract-timestamp=no";
150 bt_argv
[11] = output_path
;
151 (void) g_spawn_sync(NULL
, bt_argv
, NULL
,
152 G_SPAWN_CHILD_INHERITS_STDIN
, NULL
, NULL
,
153 NULL
, NULL
, &retcode
, &error
);
156 fprintf(stderr
, "Failed to execute \"%s\": %s (%d)\n",
157 bt_argv
[0], error
->message
, error
->code
);