src.ctf.fs: use CTF2 metadata stream parser
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 15 Aug 2022 21:41:32 +0000 (17:41 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 23 Aug 2022 16:06:16 +0000 (12:06 -0400)
Change-Id: Ieae140125ac14595845739534d6bb0ee65ae114d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8372
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/plugins/ctf/fs-src/fs.cpp
src/plugins/ctf/fs-src/fs.hpp

index de72ea95bf6a99212aaa5383b82a60c96e9935a5..9b3e8c0903464997824ab0f6c948ecb49fc4b169 100644 (file)
@@ -353,9 +353,9 @@ static void merge_ctf_fs_ds_indexes(ctf_fs_ds_index& dest, ctf_fs_ds_index src)
     }
 }
 
-static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const char *path)
+static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const char *path,
+                                        const bt2_common::LogCfg& logCfg)
 {
-    const bt2_common::LogCfg& logCfg = ctf_fs_trace->logCfg;
     ctf_fs_ds_file_info::UP ds_file_info =
         bt2_common::makeUnique<ctf_fs_ds_file_info>(path, logCfg);
     const TraceCls& traceCls = *ctf_fs_trace->cls();
@@ -440,10 +440,9 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
     return 0;
 }
 
-static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
+static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace,
+                                 const bt2_common::LogCfg& logCfg)
 {
-    const bt2_common::LogCfg& logCfg = ctf_fs_trace->logCfg;
-
     /* Check each file in the path directory, except specific ones */
     GError *error = NULL;
     bt2_common::GDirUP dir {g_dir_open(ctf_fs_trace->path.c_str(), 0, &error)};
@@ -495,7 +494,7 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
             continue;
         }
 
-        ret = add_ds_file_to_ds_file_group(ctf_fs_trace, file->path.c_str());
+        ret = add_ds_file_to_ds_file_group(ctf_fs_trace, file->path.c_str(), logCfg);
         if (ret) {
             BT_CLOGE_APPEND_CAUSE("Cannot add stream file `%s` to stream file group",
                                   file->path.c_str());
@@ -557,7 +556,7 @@ static ctf_fs_trace::UP ctf_fs_trace_create(const char *path,
         set_trace_name(**ctf_fs_trace->trace, name, logCfg);
     }
 
-    int ret = create_ds_file_groups(ctf_fs_trace.get());
+    int ret = create_ds_file_groups(ctf_fs_trace.get(), logCfg);
     if (ret) {
         return nullptr;
     }
@@ -838,11 +837,10 @@ private:
 static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
                                              const ClkCls& default_cc,
                                              const ctf_fs_ds_index_entry& index_entry,
-                                             enum target_event target_event, uint64_t *cs,
+                                             enum target_event target_event,
+                                             const bt2_common::LogCfg& logCfg, uint64_t *cs,
                                              int64_t *ts_ns)
 {
-    const bt2_common::LogCfg& logCfg = ctf_fs_trace->logCfg;
-
     BT_ASSERT(ctf_fs_trace);
     BT_ASSERT(ctf_fs_trace->cls());
     BT_ASSERT(index_entry.path);
@@ -900,19 +898,21 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
 static int decode_packet_first_event_timestamp(struct ctf_fs_trace *ctf_fs_trace,
                                                const ClkCls& default_cc,
                                                const ctf_fs_ds_index_entry& index_entry,
-                                               uint64_t *cs, int64_t *ts_ns)
+                                               const bt2_common::LogCfg& logCfg, uint64_t *cs,
+                                               int64_t *ts_ns)
 {
-    return decode_clock_snapshot_after_event(ctf_fs_trace, default_cc, index_entry, FIRST_EVENT, cs,
-                                             ts_ns);
+    return decode_clock_snapshot_after_event(ctf_fs_trace, default_cc, index_entry, FIRST_EVENT,
+                                             logCfg, cs, ts_ns);
 }
 
 static int decode_packet_last_event_timestamp(struct ctf_fs_trace *ctf_fs_trace,
                                               const ClkCls& default_cc,
                                               const ctf_fs_ds_index_entry& index_entry,
-                                              uint64_t *cs, int64_t *ts_ns)
+                                              const bt2_common::LogCfg& logCfg, uint64_t *cs,
+                                              int64_t *ts_ns)
 {
-    return decode_clock_snapshot_after_event(ctf_fs_trace, default_cc, index_entry, LAST_EVENT, cs,
-                                             ts_ns);
+    return decode_clock_snapshot_after_event(ctf_fs_trace, default_cc, index_entry, LAST_EVENT,
+                                             logCfg, cs, ts_ns);
 }
 
 /*
@@ -933,10 +933,9 @@ static int decode_packet_last_event_timestamp(struct ctf_fs_trace *ctf_fs_trace,
  *  - before lttng-module 2.10.10
  *  - before lttng-module 2.9.13
  */
-static int fix_index_lttng_event_after_packet_bug(struct ctf_fs_trace *trace)
+static int fix_index_lttng_event_after_packet_bug(struct ctf_fs_trace *trace,
+                                                  const bt2_common::LogCfg& logCfg)
 {
-    const bt2_common::LogCfg& logCfg = trace->logCfg;
-
     for (ctf_fs_ds_file_group::UP& ds_file_group : trace->ds_file_groups) {
         BT_ASSERT(ds_file_group);
         ctf_fs_ds_index& index = ds_file_group->index;
@@ -972,8 +971,9 @@ static int fix_index_lttng_event_after_packet_bug(struct ctf_fs_trace *trace)
          * Decode packet to read the timestamp of the last event of the
          * entry.
          */
-        int ret = decode_packet_last_event_timestamp(
-            trace, default_cc, last_entry, &last_entry.timestamp_end, &last_entry.timestamp_end_ns);
+        int ret = decode_packet_last_event_timestamp(trace, default_cc, last_entry, logCfg,
+                                                     &last_entry.timestamp_end,
+                                                     &last_entry.timestamp_end_ns);
         if (ret) {
             BT_CLOGE_APPEND_CAUSE(
                 "Failed to decode stream's last packet to get its last event's clock snapshot.");
@@ -998,10 +998,9 @@ static int fix_index_lttng_event_after_packet_bug(struct ctf_fs_trace *trace)
  * Known buggy tracer versions:
  *  - before barectf 2.3.1
  */
-static int fix_index_barectf_event_before_packet_bug(struct ctf_fs_trace *trace)
+static int fix_index_barectf_event_before_packet_bug(struct ctf_fs_trace *trace,
+                                                     const bt2_common::LogCfg& logCfg)
 {
-    const bt2_common::LogCfg& logCfg = trace->logCfg;
-
     for (ctf_fs_ds_file_group::UP& ds_file_group : trace->ds_file_groups) {
         ctf_fs_ds_index& index = ds_file_group->index;
 
@@ -1021,7 +1020,7 @@ static int fix_index_barectf_event_before_packet_bug(struct ctf_fs_trace *trace)
              * 2. Set the current entry `begin` timestamp to the
              * timestamp of the first event of the current packet.
              */
-            int ret = decode_packet_first_event_timestamp(trace, default_cc, curr_entry,
+            int ret = decode_packet_first_event_timestamp(trace, default_cc, curr_entry, logCfg,
                                                           &curr_entry.timestamp_begin,
                                                           &curr_entry.timestamp_begin_ns);
             if (ret) {
@@ -1058,10 +1057,8 @@ static int fix_index_barectf_event_before_packet_bug(struct ctf_fs_trace *trace)
  * Affected versions:
  * - All current and future lttng-ust and lttng-modules versions.
  */
-static int fix_index_lttng_crash_quirk(struct ctf_fs_trace *trace)
+static int fix_index_lttng_crash_quirk(struct ctf_fs_trace *trace, const bt2_common::LogCfg& logCfg)
 {
-    const bt2_common::LogCfg& logCfg = trace->logCfg;
-
     for (ctf_fs_ds_file_group::UP& ds_file_group : trace->ds_file_groups) {
         BT_ASSERT(ds_file_group);
         ctf_fs_ds_index& index = ds_file_group->index;
@@ -1079,7 +1076,7 @@ static int fix_index_lttng_crash_quirk(struct ctf_fs_trace *trace)
              * Decode packet to read the timestamp of the
              * last event of the stream file.
              */
-            int ret = decode_packet_last_event_timestamp(trace, default_cc, last_entry,
+            int ret = decode_packet_last_event_timestamp(trace, default_cc, last_entry, logCfg,
                                                          &last_entry.timestamp_end,
                                                          &last_entry.timestamp_end_ns);
             if (ret) {
@@ -1280,7 +1277,7 @@ static int fix_packet_index_tracer_bugs(struct ctf_fs_component *ctf_fs)
     /* Check if the trace may be affected by old tracer bugs. */
     if (is_tracer_affected_by_lttng_event_after_packet_bug(&current_tracer_info)) {
         BT_LOGI_STR("Trace may be affected by LTTng tracer packet timestamp bug. Fixing up.");
-        ret = fix_index_lttng_event_after_packet_bug(ctf_fs->trace.get());
+        ret = fix_index_lttng_event_after_packet_bug(ctf_fs->trace.get(), logCfg);
         if (ret) {
             BT_CLOGE_APPEND_CAUSE("Failed to fix LTTng event-after-packet bug.");
             return ret;
@@ -1290,7 +1287,7 @@ static int fix_packet_index_tracer_bugs(struct ctf_fs_component *ctf_fs)
 
     if (is_tracer_affected_by_barectf_event_before_packet_bug(&current_tracer_info)) {
         BT_LOGI_STR("Trace may be affected by barectf tracer packet timestamp bug. Fixing up.");
-        ret = fix_index_barectf_event_before_packet_bug(ctf_fs->trace.get());
+        ret = fix_index_barectf_event_before_packet_bug(ctf_fs->trace.get(), logCfg);
         if (ret) {
             BT_CLOGE_APPEND_CAUSE("Failed to fix barectf event-before-packet bug.");
             return ret;
@@ -1299,7 +1296,7 @@ static int fix_packet_index_tracer_bugs(struct ctf_fs_component *ctf_fs)
     }
 
     if (is_tracer_affected_by_lttng_crash_quirk(&current_tracer_info)) {
-        ret = fix_index_lttng_crash_quirk(ctf_fs->trace.get());
+        ret = fix_index_lttng_crash_quirk(ctf_fs->trace.get(), logCfg);
         if (ret) {
             BT_CLOGE_APPEND_CAUSE("Failed to fix lttng-crash timestamp quirks.");
             return ret;
@@ -1564,7 +1561,6 @@ ctf_fs_init(bt_self_component_source *self_comp_src, bt_self_component_source_co
         }
 
         bt_self_component_set_data(selfComp, ctf_fs.release());
-
         return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
     } catch (const std::bad_alloc&) {
         return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
index 7acde6d4912d6f210bdce7d5373c1a79eabce10c..d5ecf8fbcff89d4d12bff7215d0b43cb4994a917 100644 (file)
 #include <babeltrace2/babeltrace.h>
 #include "cpp-common/data-len.hpp"
 #include "data-stream-file.hpp"
-#include "../common/src/metadata/tsdl/ctf-1-metadata-stream-parser.hpp"
+#include "../common/src/metadata/metadata-stream-parser.hpp"
 #include "../common/src/metadata/metadata-stream-parser-utils.hpp"
 #include "../common/src/msg-iter.hpp"
+#include "../common/src/clk-cls-cfg.hpp"
 #include "cpp-common/glib-up.hpp"
 
 #define CTF_FS_METADATA_FILENAME "metadata"
@@ -32,8 +33,8 @@ struct ctf_fs_trace
     using UP = std::unique_ptr<ctf_fs_trace>;
 
     explicit ctf_fs_trace(const ctf::src::ClkClsCfg clkClsCfg, bt_self_component *selfComp,
-                          const bt2_common::LogCfg& logCfgParam) noexcept :
-        logCfg {logCfgParam},
+                          const bt2_common::LogCfg& logCfg) noexcept :
+        _mLogCfg {logCfg},
         _mClkClsCfg {clkClsCfg}, _mSelfComp {selfComp}
     {
     }
@@ -53,12 +54,9 @@ struct ctf_fs_trace
 
     void parseMetadata(const uint8_t *begin, const uint8_t *end)
     {
-        _mParseRet =
-            ctf::src::parseMetadataStream(_mClkClsCfg, _mSelfComp, begin, end, this->logCfg);
+        _mParseRet = ctf::src::parseMetadataStream(_mClkClsCfg, _mSelfComp, begin, end, _mLogCfg);
     }
 
-    const bt2_common::LogCfg logCfg;
-
     nonstd::optional<bt2::Trace::Shared> trace;
 
     std::vector<ctf_fs_ds_file_group::UP> ds_file_groups;
@@ -69,6 +67,7 @@ struct ctf_fs_trace
     uint64_t next_stream_id = 0;
 
 private:
+    const bt2_common::LogCfg _mLogCfg;
     const ctf::src::ClkClsCfg _mClkClsCfg;
     bt_self_component *_mSelfComp;
     nonstd::optional<ctf::src::MetadataStreamParser::ParseRet> _mParseRet;
This page took 0.030222 seconds and 5 git commands to generate.