}
bt_packet_put_ref(stream->packet_state.packet);
- g_free(stream);
+ delete stream;
end:
return;
struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
const bt_stream *ir_stream)
{
- struct fs_sink_stream *stream = g_new0(struct fs_sink_stream, 1);
+ fs_sink_stream *stream = new fs_sink_stream;
int ret;
GString *path = g_string_new(trace->path->str);
- if (!stream) {
- goto end;
- }
-
stream->log_level = trace->log_level;
stream->trace = trace;
stream->ir_stream = ir_stream;
#include "ctfser/ctfser.h"
+struct fs_sink_trace;
+struct fs_sink_ctf_stream_class;
+
struct fs_sink_stream
{
- bt_logging_level log_level;
- struct fs_sink_trace *trace;
- struct bt_ctfser ctfser;
+ bt_logging_level log_level = BT_LOGGING_LEVEL_NONE;
+ fs_sink_trace *trace = nullptr;
+ bt_ctfser ctfser {};
/* Stream's file name */
- GString *file_name;
+ GString *file_name = nullptr;
/* Weak */
- const bt_stream *ir_stream;
+ const bt_stream *ir_stream = nullptr;
- struct fs_sink_ctf_stream_class *sc;
+ fs_sink_ctf_stream_class *sc = nullptr;
/* Current packet's state */
struct
* packet (got a packet beginning message, but no
* packet end message yet).
*/
- bool is_open;
+ bool is_open = false;
/*
* Current beginning default clock snapshot for the
* current packet (`UINT64_C(-1)` if not set).
*/
- uint64_t beginning_cs;
+ uint64_t beginning_cs = 0;
/*
* Current end default clock snapshot for the current
* packet (`UINT64_C(-1)` if not set).
*/
- uint64_t end_cs;
+ uint64_t end_cs = 0;
/*
* Current packet's content size (bits) for the current
* packet.
*/
- uint64_t content_size;
+ uint64_t content_size = 0;
/*
* Current packet's total size (bits) for the current
* packet.
*/
- uint64_t total_size;
+ uint64_t total_size = 0;
/*
* Discarded events (free running) counter for the
* current packet.
*/
- uint64_t discarded_events_counter;
+ uint64_t discarded_events_counter = 0;
/* Sequence number (free running) of the current packet */
- uint64_t seq_num;
+ uint64_t seq_num = 0;
/*
* Offset of the packet context structure within the
* current packet (bits).
*/
- uint64_t context_offset_bits;
+ uint64_t context_offset_bits = 0;
/*
* Owned by this; `NULL` if the current packet is closed
* or if the trace IR stream does not support packets.
*/
- const bt_packet *packet;
+ const bt_packet *packet = nullptr;
} packet_state;
/* Previous packet's state */
struct
{
/* End default clock snapshot (`UINT64_C(-1)` if not set) */
- uint64_t end_cs;
+ uint64_t end_cs = 0;
/* Discarded events (free running) counter */
- uint64_t discarded_events_counter;
+ uint64_t discarded_events_counter = 0;
/* Sequence number (free running) */
- uint64_t seq_num;
+ uint64_t seq_num = 0;
} prev_packet_state;
/* State to handle discarded events */
*
* * Its end time is the current packet's end time.
*/
- bool in_range;
+ bool in_range = false;
/*
* Beginning and end times of the time range given by a
* previously received discarded events message.
*/
- uint64_t beginning_cs;
- uint64_t end_cs;
+ uint64_t beginning_cs = 0;
+ uint64_t end_cs = 0;
} discarded_events_state;
/* State to handle discarded packets */
* * Its end time is the current packet's beginning
* time.
*/
- bool in_range;
+ bool in_range = false;
/*
* Beginning and end times of the time range given by a
* previously received discarded packets message.
*/
- uint64_t beginning_cs;
- uint64_t end_cs;
+ uint64_t beginning_cs = 0;
+ uint64_t end_cs = 0;
} discarded_packets_state;
};
fs_sink_ctf_trace_destroy(trace->trace);
trace->trace = NULL;
- g_free(trace);
+ delete trace;
g_string_free(tsdl, TRUE);
struct fs_sink_trace *fs_sink_trace_create(struct fs_sink_comp *fs_sink, const bt_trace *ir_trace)
{
int ret;
- struct fs_sink_trace *trace = g_new0(struct fs_sink_trace, 1);
+ fs_sink_trace *trace = new fs_sink_trace;
bt_trace_add_listener_status trace_status;
- if (!trace) {
- goto end;
- }
-
trace->log_level = fs_sink->log_level;
trace->fs_sink = fs_sink;
trace->ir_trace = ir_trace;
#include <babeltrace2/babeltrace.h>
+struct fs_sink_comp;
+struct fs_sink_ctf_trace;
+
struct fs_sink_trace
{
- bt_logging_level log_level;
- struct fs_sink_comp *fs_sink;
+ bt_logging_level log_level = BT_LOGGING_LEVEL_NONE;
+ fs_sink_comp *fs_sink = nullptr;
/* Owned by this */
- struct fs_sink_ctf_trace *trace;
+ fs_sink_ctf_trace *trace = nullptr;
/*
* Weak reference: this object does not own it, and `trace`
* could "leak" resources (memory, file descriptors) associated
* to traces and streams which otherwise would not exist.
*/
- const bt_trace *ir_trace;
+ const bt_trace *ir_trace = nullptr;
- bt_listener_id ir_trace_destruction_listener_id;
+ bt_listener_id ir_trace_destruction_listener_id = 0;
/* Trace's directory */
- GString *path;
+ GString *path = nullptr;
/* `metadata` file path */
- GString *metadata_path;
+ GString *metadata_path = nullptr;
/*
* Hash table of `const bt_stream *` (weak) to
* `struct fs_sink_stream *` (owned by hash table).
*/
- GHashTable *streams;
+ GHashTable *streams = nullptr;
};
struct fs_sink_trace *fs_sink_trace_create(struct fs_sink_comp *fs_sink, const bt_trace *ir_trace);
}
BT_MESSAGE_ITERATOR_PUT_REF_AND_RESET(fs_sink->upstream_iter);
- g_free(fs_sink);
+ delete fs_sink;
end:
return;
bt_logging_level log_level =
bt_component_get_logging_level(bt_self_component_as_component(self_comp));
- fs_sink = g_new0(struct fs_sink_comp, 1);
- if (!fs_sink) {
- BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp,
- "Failed to allocate one CTF FS sink structure.");
- BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT(
- self_comp, "Failed to allocate one CTF FS sink structure.");
- status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
- goto end;
- }
-
+ fs_sink = new fs_sink_comp;
fs_sink->log_level = log_level;
fs_sink->self_comp = self_comp;
fs_sink->output_dir_path = g_string_new(NULL);
struct fs_sink_comp
{
- bt_logging_level log_level;
- bt_self_component *self_comp;
+ bt_logging_level log_level = BT_LOGGING_LEVEL_NONE;
+ bt_self_component *self_comp = nullptr;
/* Owned by this */
- bt_message_iterator *upstream_iter;
+ bt_message_iterator *upstream_iter = nullptr;
/* Base output directory path */
- GString *output_dir_path;
+ GString *output_dir_path = nullptr;
/*
* True if the component assumes that it will only write a
* streams). This makes the component write the stream files
* directly in the output directory (`output_dir_path` above).
*/
- bool assume_single_trace;
+ bool assume_single_trace = false;
/* True to completely ignore discarded events messages */
- bool ignore_discarded_events;
+ bool ignore_discarded_events = false;
/* True to completely ignore discarded packets messages */
- bool ignore_discarded_packets;
+ bool ignore_discarded_packets = false;
/*
* True to make the component quiet (nothing printed to the
* standard output).
*/
- bool quiet;
+ bool quiet = false;
/*
* Hash table of `const bt_trace *` (weak) to
* `struct fs_sink_trace *` (owned by hash table).
*/
- GHashTable *traces;
+ GHashTable *traces = nullptr;
};
bt_component_class_initialize_method_status
struct TraceIrToCtfIrCtx
{
- bt_logging_level log_level;
- bt_self_component *self_comp;
+ bt_logging_level log_level = BT_LOGGING_LEVEL_NONE;
+ bt_self_component *self_comp = nullptr;
/* Weak */
- struct fs_sink_ctf_stream_class *cur_sc;
+ struct fs_sink_ctf_stream_class *cur_sc = nullptr;
/* Weak */
- struct fs_sink_ctf_event_class *cur_ec;
+ struct fs_sink_ctf_event_class *cur_ec = nullptr;
- bt_field_path_scope cur_scope;
+ bt_field_path_scope cur_scope = BT_FIELD_PATH_SCOPE_PACKET_CONTEXT;
/*
* Array of `struct field_path_elem` */
- GArray *cur_path;
+ GArray *cur_path = nullptr;
};
} /* namespace sink */
static inline void ctx_init(ctf::sink::TraceIrToCtfIrCtx *ctx, struct fs_sink_comp *fs_sink)
{
- memset(ctx, 0, sizeof(*ctx));
ctx->cur_path = g_array_new(FALSE, TRUE, sizeof(struct field_path_elem));
BT_ASSERT(ctx->cur_path);
ctx->log_level = fs_sink->log_level;