Remove notification iterator seeking API until it's supported
[babeltrace.git] / cli / babeltrace-log.c
CommitLineData
8c572eba 1/*
5781a924 2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
8c572eba
MD
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
c462e188
MD
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
20 * SOFTWARE.
8c572eba
MD
21 */
22
989c73bc 23#include <stdlib.h>
5781a924
PP
24#include <stdio.h>
25#include <stdbool.h>
c647ce09 26#include <string.h>
5781a924
PP
27#include <assert.h>
28#include <babeltrace/babeltrace.h>
29#include <popt.h>
95fb061d 30#include <glib.h>
8c572eba 31
b522ac18 32static
5781a924 33void print_usage(FILE *fp)
b522ac18 34{
5781a924
PP
35 fprintf(stderr, "Usage: babeltrace-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");
b522ac18
MD
41}
42
8c572eba 43static
5781a924
PP
44int parse_params(int argc, char *argv[], char **output_path,
45 bool *no_extract_ts)
8c572eba 46{
5781a924
PP
47 enum {
48 OPT_WITH_TIMESTAMPS = 1,
49 OPT_HELP = 2,
50 };
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 },
55 };
56 poptContext pc = NULL;
57 int opt;
58 int ret = 0;
59 const char *leftover;
60
61 *no_extract_ts = true;
62 pc = poptGetContext(NULL, argc, (const char **) argv, opts, 0);
63 if (!pc) {
64 fprintf(stderr, "Cannot get popt context\n");
70fd5a51 65 goto error;
ca8b2b02 66 }
08c82b90 67
5781a924 68 poptReadDefaultConfig(pc, 0);
185987b1 69
5781a924
PP
70 while ((opt = poptGetNextOpt(pc)) > 0) {
71 switch (opt) {
72 case OPT_HELP:
73 print_usage(stdout);
74 goto end;
75 case OPT_WITH_TIMESTAMPS:
76 *no_extract_ts = false;
08c82b90 77 break;
5781a924
PP
78 default:
79 fprintf(stderr, "Unknown command-line option specified (option code %d)\n",
80 opt);
81 goto error;
8c572eba 82 }
8c572eba
MD
83 }
84
5781a924
PP
85 if (opt < -1) {
86 fprintf(stderr, "While parsing command-line options, at option %s: %s\n",
87 poptBadOption(pc, 0), poptStrerror(opt));
70fd5a51 88 goto error;
f824ae04 89 }
5781a924
PP
90
91 leftover = poptGetArg(pc);
92 if (!leftover) {
93 fprintf(stderr, "Command line error: Missing output path\n");
94 print_usage(stderr);
95 goto error;
f824ae04 96 }
90219914 97
5781a924
PP
98 *output_path = strdup(leftover);
99 assert(*output_path);
100 goto end;
989c73bc 101
5781a924
PP
102error:
103 ret = 1;
ca8b2b02 104
5781a924
PP
105end:
106 if (pc) {
107 poptFreeContext(pc);
ca8b2b02 108 }
5781a924
PP
109
110 return ret;
ca8b2b02
MD
111}
112
5781a924 113int main(int argc, char *argv[])
90219914 114{
5781a924
PP
115 char *output_path = NULL;
116 bool no_extract_ts;
117 int retcode;
118 GError *error = NULL;
119 gchar *bt_argv[] = {
120 BT_CLI_PATH,
121 "run",
122 "--component",
123 "dmesg:src.text.dmesg",
124 "--params",
125 "read-from-stdin=yes",
126 "--params",
127 NULL, /* no-extract-timestamp=? placeholder */
128 "--component",
129 "ctf:sink.ctf.fs",
130 "--key",
131 "path",
132 "--value",
133 NULL, /* output path placeholder */
d80bd59e
PP
134 "--params",
135 "single-trace=yes",
5781a924
PP
136 "--connect",
137 "dmesg:ctf",
138 NULL, /* sentinel */
139 };
140
141 retcode = parse_params(argc, argv, &output_path, &no_extract_ts);
142 if (retcode) {
143 goto end;
90219914 144 }
90219914 145
5781a924
PP
146 if (no_extract_ts) {
147 bt_argv[7] = "no-extract-timestamp=yes";
148 } else {
149 bt_argv[7] = "no-extract-timestamp=no";
39592eae
MD
150 }
151
5781a924
PP
152 bt_argv[13] = output_path;
153 (void) g_spawn_sync(NULL, bt_argv, NULL,
4db594dd 154 G_SPAWN_CHILD_INHERITS_STDIN, NULL, NULL,
5781a924 155 NULL, NULL, &retcode, &error);
989c73bc 156
5781a924
PP
157 if (error) {
158 fprintf(stderr, "Failed to execute \"%s\": %s (%d)\n",
159 bt_argv[0], error->message, error->code);
989c73bc 160 }
bb9c6e6a 161
5781a924
PP
162end:
163 free(output_path);
90219914 164
5781a924
PP
165 if (error) {
166 g_error_free(error);
bb9c6e6a 167 }
989c73bc 168
5781a924 169 return retcode;
90219914 170}
This page took 0.061064 seconds and 4 git commands to generate.