Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / ctf / fs-sink / fs-sink-trace.c
index 07d78f764b7e468730edd15853d6eed6a348f9c5..e9097848c8ab0b624b87a49e8acdd2d77a912c3e 100644 (file)
@@ -1,29 +1,13 @@
 /*
- * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
+ * SPDX-License-Identifier: MIT
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
  */
 
 #define BT_COMP_LOG_SELF_COMP (trace->fs_sink->self_comp)
 #define BT_LOG_OUTPUT_LEVEL (trace->log_level)
 #define BT_LOG_TAG "PLUGIN/SINK.CTF.FS/TRACE"
-#include "plugins/comp-logging.h"
+#include "logging/comp-logging.h"
 
 #include <babeltrace2/babeltrace.h>
 #include <stdio.h>
@@ -133,6 +117,15 @@ GString *make_unique_trace_path(const char *path)
        return unique_path;
 }
 
+/*
+ * Disable `deprecated-declarations` warnings for
+ * lttng_validate_datetime() because we're using `GTimeVal` and
+ * g_time_val_from_iso8601() which are deprecated since GLib 2.56
+ * (Babeltrace supports older versions too).
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
 /*
  * Validate that the input string `datetime` is an ISO8601-compliant string (the
  * format used by LTTng in the metadata).
@@ -162,30 +155,32 @@ end:
        return ret;
 }
 
+#pragma GCC diagnostic pop
+
 static
 int append_lttng_trace_path_ust_uid(const struct fs_sink_trace *trace,
-               GString *path, const bt_trace_class *tc)
+               GString *path, const bt_trace *tc)
 {
        const bt_value *v;
        int ret;
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_buffering_id");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(tc, "tracer_buffering_id");
        if (!v || !bt_value_is_signed_integer(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_buffering_id\"");
                goto error;
        }
 
        g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRId64,
-               bt_value_signed_integer_get(v));
+               bt_value_integer_signed_get(v));
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "isa_length");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(tc, "architecture_bit_width");
        if (!v || !bt_value_is_signed_integer(v)) {
-               BT_COMP_LOGI_STR("Couldn't get environment value: name=\"isa_length\"");
+               BT_COMP_LOGI_STR("Couldn't get environment value: name=\"architecture_bit_width\"");
                goto error;
        }
 
        g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRIu64 "-bit",
-               bt_value_signed_integer_get(v));
+               bt_value_integer_signed_get(v));
 
        ret = 0;
        goto end;
@@ -199,13 +194,13 @@ end:
 
 static
 int append_lttng_trace_path_ust_pid(const struct fs_sink_trace *trace,
-               GString *path, const bt_trace_class *tc)
+               GString *path, const bt_trace *tc)
 {
        const bt_value *v;
        const char *datetime;
        int ret;
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "procname");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(tc, "procname");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"procname\"");
                goto error;
@@ -213,15 +208,15 @@ int append_lttng_trace_path_ust_pid(const struct fs_sink_trace *trace,
 
        g_string_append_printf(path, G_DIR_SEPARATOR_S "%s", bt_value_string_get(v));
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "vpid");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(tc, "vpid");
        if (!v || !bt_value_is_signed_integer(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"vpid\"");
                goto error;
        }
 
-       g_string_append_printf(path, "-%" PRId64, bt_value_signed_integer_get(v));
+       g_string_append_printf(path, "-%" PRId64, bt_value_integer_signed_get(v));
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "vpid_datetime");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(tc, "vpid_datetime");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"vpid_datetime\"");
                goto error;
@@ -252,7 +247,6 @@ end:
 static
 GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
 {
-       const bt_trace_class *tc;
        const bt_value *v;
        const char *tracer_name, *domain, *datetime;
        int64_t tracer_major, tracer_minor;
@@ -263,9 +257,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
                goto error;
        }
 
-       tc = bt_trace_borrow_class_const(trace->ir_trace);
-
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_name");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "tracer_name");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_name\"");
                goto error;
@@ -279,21 +272,23 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
                goto error;
        }
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_major");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "tracer_major");
        if (!v || !bt_value_is_signed_integer(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_major\"");
                goto error;
        }
 
-       tracer_major = bt_value_signed_integer_get(v);
+       tracer_major = bt_value_integer_signed_get(v);
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_minor");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "tracer_minor");
        if (!v || !bt_value_is_signed_integer(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_minor\"");
                goto error;
        }
 
-       tracer_minor = bt_value_signed_integer_get(v);
+       tracer_minor = bt_value_integer_signed_get(v);
 
        if (!(tracer_major >= 3 || (tracer_major == 2 && tracer_minor >= 11))) {
                BT_COMP_LOGI("Unsupported LTTng version for automatic trace path: major=%" PRId64 ", minor=%" PRId64,
@@ -301,7 +296,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
                goto error;
        }
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "hostname");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "hostname");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_hostname\"");
                goto error;
@@ -309,7 +305,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
 
        g_string_assign(path, bt_value_string_get(v));
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "trace_name");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "trace_name");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"trace_name\"");
                goto error;
@@ -317,7 +314,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
 
        g_string_append_printf(path, G_DIR_SEPARATOR_S "%s", bt_value_string_get(v));
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "trace_creation_datetime");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "trace_creation_datetime");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"trace_creation_datetime\"");
                goto error;
@@ -331,7 +329,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
 
        g_string_append_printf(path, "-%s", datetime);
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "domain");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "domain");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"domain\"");
                goto error;
@@ -343,7 +342,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
        if (g_str_equal(domain, "ust")) {
                const char *tracer_buffering_scheme;
 
-               v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_buffering_scheme");
+               v = bt_trace_borrow_environment_entry_value_by_name_const(
+                       trace->ir_trace, "tracer_buffering_scheme");
                if (!v || !bt_value_is_string(v)) {
                        BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_buffering_scheme\"");
                        goto error;
@@ -353,11 +353,13 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
                g_string_append_printf(path, G_DIR_SEPARATOR_S "%s", tracer_buffering_scheme);
 
                if (g_str_equal(tracer_buffering_scheme, "uid")) {
-                       if (append_lttng_trace_path_ust_uid(trace, path, tc)) {
+                       if (append_lttng_trace_path_ust_uid(trace, path,
+                                       trace->ir_trace)) {
                                goto error;
                        }
                } else if (g_str_equal(tracer_buffering_scheme, "pid")){
-                       if (append_lttng_trace_path_ust_pid(trace, path, tc)) {
+                       if (append_lttng_trace_path_ust_pid(trace, path,
+                                       trace->ir_trace)) {
                                goto error;
                        }
                } else {
@@ -389,6 +391,7 @@ static
 GString *make_trace_path_rel(const struct fs_sink_trace *trace)
 {
        GString *path = NULL;
+       const char *trace_name;
 
        if (trace->fs_sink->assume_single_trace) {
                /* Use output directory directly */
@@ -403,7 +406,7 @@ GString *make_trace_path_rel(const struct fs_sink_trace *trace)
        }
 
        /* Otherwise, use the trace name, if available. */
-       const char *trace_name = bt_trace_get_name(trace->ir_trace);
+       trace_name = bt_trace_get_name(trace->ir_trace);
        if (trace_name) {
                path = g_string_new(trace_name);
                goto end;
@@ -493,23 +496,23 @@ void fs_sink_trace_destroy(struct fs_sink_trace *trace)
 
        tsdl = g_string_new(NULL);
        BT_ASSERT(tsdl);
-       translate_trace_class_ctf_ir_to_tsdl(trace->tc, tsdl);
+       translate_trace_ctf_ir_to_tsdl(trace->trace, tsdl);
 
        BT_ASSERT(trace->metadata_path);
        fh = fopen(trace->metadata_path->str, "wb");
        if (!fh) {
                BT_COMP_LOGF_ERRNO("In trace destruction listener: "
-                       "cannot open metadata file for writing",
+                       "cannot open metadata file for writing",
                        ": path=\"%s\"", trace->metadata_path->str);
-               abort();
+               bt_common_abort();
        }
 
        len = fwrite(tsdl->str, sizeof(*tsdl->str), tsdl->len, fh);
        if (len != tsdl->len) {
                BT_COMP_LOGF_ERRNO("In trace destruction listener: "
-                       "cannot write metadata file",
+                       "cannot write metadata file",
                        ": path=\"%s\"", trace->metadata_path->str);
-               abort();
+               bt_common_abort();
        }
 
        if (!trace->fs_sink->quiet) {
@@ -521,28 +524,26 @@ void fs_sink_trace_destroy(struct fs_sink_trace *trace)
                trace->path = NULL;
        }
 
-       g_string_free(trace->metadata_path, TRUE);
-       trace->metadata_path = NULL;
-
-       fs_sink_ctf_trace_class_destroy(trace->tc);
-       trace->tc = NULL;
-       g_free(trace);
-
-end:
        if (fh) {
                int ret = fclose(fh);
 
                if (ret != 0) {
                        BT_COMP_LOGW_ERRNO("In trace destruction listener: "
-                               "cannot close metadata file",
+                               "cannot close metadata file",
                                ": path=\"%s\"", trace->metadata_path->str);
                }
        }
 
-       if (tsdl) {
-               g_string_free(tsdl, TRUE);
-       }
+       g_string_free(trace->metadata_path, TRUE);
+       trace->metadata_path = NULL;
+
+       fs_sink_ctf_trace_destroy(trace->trace);
+       trace->trace = NULL;
+       g_free(trace);
 
+       g_string_free(tsdl, TRUE);
+
+end:
        return;
 }
 
@@ -576,9 +577,8 @@ struct fs_sink_trace *fs_sink_trace_create(struct fs_sink_comp *fs_sink,
        trace->fs_sink = fs_sink;
        trace->ir_trace = ir_trace;
        trace->ir_trace_destruction_listener_id = UINT64_C(-1);
-       trace->tc = translate_trace_class_trace_ir_to_ctf_ir(
-               fs_sink, bt_trace_borrow_class_const(ir_trace));
-       if (!trace->tc) {
+       trace->trace = translate_trace_trace_ir_to_ctf_ir(fs_sink, ir_trace);
+       if (!trace->trace) {
                goto error;
        }
 
This page took 0.030231 seconds and 4 git commands to generate.