lib: create_packet_message(): use pool to determine beginning or end msg
[babeltrace.git] / cli / babeltrace-log.c
CommitLineData
8c572eba 1/*
899a1d74 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>
899a1d74
PP
24#include <stdio.h>
25#include <stdbool.h>
8a165660 26#include <string.h>
f6ccaed9 27#include <babeltrace/assert-internal.h>
899a1d74
PP
28#include <babeltrace/babeltrace.h>
29#include <popt.h>
95fb061d 30#include <glib.h>
8c572eba 31
b522ac18 32static
899a1d74 33void print_usage(FILE *fp)
b522ac18 34{
899a1d74
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
899a1d74
PP
44int parse_params(int argc, char *argv[], char **output_path,
45 bool *no_extract_ts)
8c572eba 46{
899a1d74
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
899a1d74 68 poptReadDefaultConfig(pc, 0);
185987b1 69
899a1d74
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;
899a1d74
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
899a1d74
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 }
899a1d74
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
899a1d74 98 *output_path = strdup(leftover);
f6ccaed9 99 BT_ASSERT(*output_path);
899a1d74 100 goto end;
989c73bc 101
899a1d74
PP
102error:
103 ret = 1;
ca8b2b02 104
899a1d74
PP
105end:
106 if (pc) {
107 poptFreeContext(pc);
ca8b2b02 108 }
899a1d74
PP
109
110 return ret;
ca8b2b02
MD
111}
112
899a1d74 113int main(int argc, char *argv[])
90219914 114{
899a1d74
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",
899a1d74
PP
125 NULL, /* no-extract-timestamp=? placeholder */
126 "--component",
127 "ctf:sink.ctf.fs",
128 "--key",
129 "path",
130 "--value",
131 NULL, /* output path placeholder */
c5a565d9
PP
132 "--params",
133 "single-trace=yes",
899a1d74
PP
134 "--connect",
135 "dmesg:ctf",
136 NULL, /* sentinel */
137 };
138
139 retcode = parse_params(argc, argv, &output_path, &no_extract_ts);
140 if (retcode) {
141 goto end;
90219914 142 }
90219914 143
899a1d74 144 if (no_extract_ts) {
4da23e31 145 bt_argv[5] = "no-extract-timestamp=yes";
899a1d74 146 } else {
4da23e31 147 bt_argv[5] = "no-extract-timestamp=no";
39592eae
MD
148 }
149
4da23e31 150 bt_argv[11] = output_path;
899a1d74 151 (void) g_spawn_sync(NULL, bt_argv, NULL,
2723b834 152 G_SPAWN_CHILD_INHERITS_STDIN, NULL, NULL,
899a1d74 153 NULL, NULL, &retcode, &error);
989c73bc 154
899a1d74
PP
155 if (error) {
156 fprintf(stderr, "Failed to execute \"%s\": %s (%d)\n",
157 bt_argv[0], error->message, error->code);
989c73bc 158 }
ebd04048 159
899a1d74
PP
160end:
161 free(output_path);
90219914 162
899a1d74
PP
163 if (error) {
164 g_error_free(error);
ebd04048 165 }
989c73bc 166
899a1d74 167 return retcode;
90219914 168}
This page took 0.066323 seconds and 4 git commands to generate.