2 * SPDX-License-Identifier: MIT
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
8 #include "common/assert.h"
9 #include "cpp-common/bt2s/make-unique.hpp"
11 #include "../common/src/metadata/tsdl/decoder.hpp"
14 #include "metadata.hpp"
16 FILE *ctf_fs_metadata_open_file(const char *trace_path
, const bt2c::Logger
& logger
)
18 GString
*metadata_path
;
21 metadata_path
= g_string_new(trace_path
);
26 g_string_append(metadata_path
, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME
);
27 fp
= fopen(metadata_path
->str
, "rb");
29 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(logger
, "Failed to open metadata file", ": path=\"{}\"",
33 g_string_free(metadata_path
, TRUE
);
39 static ctf_fs_file::UP
get_file(const bt2c::CStringView trace_path
, const bt2c::Logger
& logger
)
41 auto file
= bt2s::make_unique
<ctf_fs_file
>(logger
);
47 file
->path
= fmt::format("{}" G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME
, trace_path
);
49 if (ctf_fs_file_open(file
.get(), "rb")) {
62 int ctf_fs_metadata_set_trace_class(bt_self_component
*self_comp
, struct ctf_fs_trace
*ctf_fs_trace
,
63 const ctf::src::ClkClsCfg
& clkClsCfg
)
66 ctf_metadata_decoder_config decoder_config
{ctf_fs_trace
->logger
};
68 decoder_config
.self_comp
= self_comp
;
69 decoder_config
.clkClsCfg
= clkClsCfg
;
70 decoder_config
.create_trace_class
= true;
72 const auto file
= get_file(ctf_fs_trace
->path
, ctf_fs_trace
->logger
);
74 BT_CPPLOGE_SPEC(ctf_fs_trace
->logger
, "Cannot create metadata file object.");
79 ctf_fs_trace
->metadata
->decoder
= ctf_metadata_decoder_create(&decoder_config
);
80 if (!ctf_fs_trace
->metadata
->decoder
) {
81 BT_CPPLOGE_SPEC(ctf_fs_trace
->logger
, "Cannot create metadata decoder object.");
87 ctf_metadata_decoder_append_content(ctf_fs_trace
->metadata
->decoder
.get(), file
->fp
.get());
89 BT_CPPLOGE_SPEC(ctf_fs_trace
->logger
, "Cannot update metadata decoder's content.");
93 ctf_fs_trace
->metadata
->trace_class
=
94 ctf_metadata_decoder_get_ir_trace_class(ctf_fs_trace
->metadata
->decoder
.get());
95 BT_ASSERT(!self_comp
|| ctf_fs_trace
->metadata
->trace_class
);
97 ctf_fs_trace
->metadata
->tc
=
98 ctf_metadata_decoder_borrow_ctf_trace_class(ctf_fs_trace
->metadata
->decoder
.get());
99 BT_ASSERT(ctf_fs_trace
->metadata
->tc
);