* Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
*/
+#include <glib.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <babeltrace2/babeltrace.h>
+
#define BT_COMP_LOG_SELF_COMP (self_comp)
#define BT_LOG_OUTPUT_LEVEL (log_level)
#define BT_LOG_TAG "PLUGIN/SRC.CTF.FS/DS"
+#include <string.h>
+
#include "logging/comp-logging.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <inttypes.h>
-#include "compat/mman.h"
-#include "compat/endian.h"
-#include <babeltrace2/babeltrace.h>
-#include "common/common.h"
-#include "file.hpp"
-#include "metadata.hpp"
-#include "../common/msg-iter/msg-iter.hpp"
#include "common/assert.h"
+#include "compat/endian.h" /* IWYU pragma: keep */
+#include "compat/mman.h" /* IWYU pragma: keep */
+
+#include "../common/src/msg-iter/msg-iter.hpp"
#include "data-stream-file.hpp"
-#include <string.h>
+#include "file.hpp"
+#include "fs.hpp"
+#include "lttng-index.hpp"
static inline size_t remaining_mmap_bytes(struct ctf_fs_ds_file *ds_file)
{
BT_ASSERT(ds_file->mmap_len > 0);
ds_file->mmap_addr =
- bt_mmap((void *) 0, ds_file->mmap_len, PROT_READ, MAP_PRIVATE, fileno(ds_file->file->fp),
+ bt_mmap(ds_file->mmap_len, PROT_READ, MAP_PRIVATE, fileno(ds_file->file->fp),
ds_file->mmap_offset_in_file, ds_file->log_level);
if (ds_file->mmap_addr == MAP_FAILED) {
BT_COMP_LOGE("Cannot memory-map address (size %zu) of file \"%s\" (%p) at offset %jd: %s",
return status;
}
-static bt_stream *medop_borrow_stream(bt_stream_class *stream_class, int64_t stream_id, void *data)
+static bt_stream *medop_borrow_stream(bt_stream_class *stream_class, int64_t, void *data)
{
struct ctf_fs_ds_file *ds_file = (struct ctf_fs_ds_file *) data;
bt_stream_class *ds_file_stream_class;
return ds_file_mmap(ds_file, offset);
}
-BT_HIDDEN
struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops = {
medop_request_bytes,
medop_seek,
struct ctf_fs_ds_group_medops_data
{
/* Weak, set once at creation time. */
- struct ctf_fs_ds_file_group *ds_file_group;
+ struct ctf_fs_ds_file_group *ds_file_group = nullptr;
/*
* Index (as in element rank) of the index entry of ds_file_groups'
* index we will read next (so, the one after the one we are reading
* right now).
*/
- guint next_index_entry_index;
+ guint next_index_entry_index = 0;
/*
* File we are currently reading. Changes whenever we switch to
*
* Owned by this.
*/
- struct ctf_fs_ds_file *file;
+ struct ctf_fs_ds_file *file = nullptr;
/* Weak, for context / logging / appending causes. */
- bt_self_message_iterator *self_msg_iter;
- bt_logging_level log_level;
+ bt_self_message_iterator *self_msg_iter = nullptr;
+ bt_logging_level log_level = (bt_logging_level) 0;
};
static enum ctf_msg_iter_medium_status medop_group_request_bytes(size_t request_sz,
/* Create the new file. */
data->file =
- ctf_fs_ds_file_create(data->ds_file_group->ctf_fs_trace, self_msg_iter,
- data->ds_file_group->stream, index_entry->path, log_level);
+ ctf_fs_ds_file_create(data->ds_file_group->ctf_fs_trace, data->ds_file_group->stream,
+ index_entry->path, log_level);
if (!data->file) {
BT_MSG_ITER_LOGE_APPEND_CAUSE(self_msg_iter, "failed to create ctf_fs_ds_file.");
status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR;
return status;
}
-BT_HIDDEN
void ctf_fs_ds_group_medops_data_destroy(struct ctf_fs_ds_group_medops_data *data)
{
if (!data) {
ctf_fs_ds_file_destroy(data->file);
- g_free(data);
+ delete data;
end:
return;
struct ctf_fs_ds_file_group *ds_file_group, bt_self_message_iterator *self_msg_iter,
bt_logging_level log_level, struct ctf_fs_ds_group_medops_data **out)
{
- struct ctf_fs_ds_group_medops_data *data;
- enum ctf_msg_iter_medium_status status;
-
BT_ASSERT(self_msg_iter);
BT_ASSERT(ds_file_group);
BT_ASSERT(ds_file_group->index);
BT_ASSERT(ds_file_group->index->entries->len > 0);
- data = g_new0(struct ctf_fs_ds_group_medops_data, 1);
- if (!data) {
- BT_MSG_ITER_LOGE_APPEND_CAUSE(self_msg_iter,
- "Failed to allocate a struct ctf_fs_ds_group_medops_data");
- status = CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR;
- goto error;
- }
-
+ ctf_fs_ds_group_medops_data *data = new ctf_fs_ds_group_medops_data;
data->ds_file_group = ds_file_group;
data->self_msg_iter = self_msg_iter;
data->log_level = log_level;
*/
*out = data;
- status = CTF_MSG_ITER_MEDIUM_STATUS_OK;
- goto end;
-
-error:
- ctf_fs_ds_group_medops_data_destroy(data);
-
-end:
- return status;
+ return CTF_MSG_ITER_MEDIUM_STATUS_OK;
}
void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data)
.borrow_stream = medop_group_borrow_stream,
};
-static struct ctf_fs_ds_index_entry *ctf_fs_ds_index_entry_create(bt_self_component *self_comp,
- bt_logging_level log_level)
+static void ctf_fs_ds_index_entry_destroy(ctf_fs_ds_index_entry *entry)
{
- struct ctf_fs_ds_index_entry *entry;
-
- entry = g_new0(struct ctf_fs_ds_index_entry, 1);
- if (!entry) {
- BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to allocate a ctf_fs_ds_index_entry.");
- goto end;
- }
+ delete entry;
+}
+static struct ctf_fs_ds_index_entry *ctf_fs_ds_index_entry_create()
+{
+ ctf_fs_ds_index_entry *entry = new ctf_fs_ds_index_entry;
entry->packet_seq_num = UINT64_MAX;
-end:
return entry;
}
goto error;
}
- index_entry = ctf_fs_ds_index_entry_create(ds_file->self_comp, ds_file->log_level);
+ index_entry = ctf_fs_ds_index_entry_create();
if (!index_entry) {
BT_COMP_LOGE_APPEND_CAUSE(ds_file->self_comp,
"Failed to create a ctf_fs_ds_index_entry.");
return index;
error:
ctf_fs_ds_index_destroy(index);
- g_free(index_entry);
+ ctf_fs_ds_index_entry_destroy(index_entry);
index = NULL;
goto end;
}
goto error;
}
- index_entry = ctf_fs_ds_index_entry_create(ds_file->self_comp, ds_file->log_level);
+ index_entry = ctf_fs_ds_index_entry_create();
if (!index_entry) {
BT_COMP_LOGE_APPEND_CAUSE(ds_file->self_comp,
"Failed to create a ctf_fs_ds_index_entry.");
ret = init_index_entry(index_entry, ds_file, &props, current_packet_size_bytes,
current_packet_offset_bytes);
if (ret) {
- g_free(index_entry);
+ ctf_fs_ds_index_entry_destroy(index_entry);
goto error;
}
goto end;
}
-BT_HIDDEN
-struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace,
- bt_self_message_iterator *self_msg_iter,
- bt_stream *stream, const char *path,
- bt_logging_level log_level)
+struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream,
+ const char *path, bt_logging_level log_level)
{
int ret;
const size_t offset_align = bt_mmap_get_offset_align_size(log_level);
- struct ctf_fs_ds_file *ds_file = g_new0(struct ctf_fs_ds_file, 1);
+ ctf_fs_ds_file *ds_file = new ctf_fs_ds_file;
if (!ds_file) {
goto error;
ds_file->log_level = log_level;
ds_file->self_comp = ctf_fs_trace->self_comp;
- ds_file->self_msg_iter = self_msg_iter;
ds_file->file = ctf_fs_file_create(log_level, ds_file->self_comp);
if (!ds_file->file) {
goto error;
return ds_file;
}
-BT_HIDDEN
struct ctf_fs_ds_index *ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file,
struct ctf_fs_ds_file_info *file_info,
struct ctf_msg_iter *msg_iter)
return index;
}
-BT_HIDDEN
struct ctf_fs_ds_index *ctf_fs_ds_index_create(bt_logging_level log_level,
bt_self_component *self_comp)
{
- struct ctf_fs_ds_index *index = g_new0(struct ctf_fs_ds_index, 1);
-
- if (!index) {
- BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp, "Failed to allocate index");
- goto error;
- }
-
- index->entries = g_ptr_array_new_with_free_func((GDestroyNotify) g_free);
+ ctf_fs_ds_index *index = new ctf_fs_ds_index;
+ index->entries = g_ptr_array_new_with_free_func((GDestroyNotify) ctf_fs_ds_index_entry_destroy);
if (!index->entries) {
BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp,
"Failed to allocate index entries.");
return index;
}
-BT_HIDDEN
void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *ds_file)
{
if (!ds_file) {
ctf_fs_file_destroy(ds_file->file);
}
- g_free(ds_file);
+ delete ds_file;
}
-BT_HIDDEN
void ctf_fs_ds_index_destroy(struct ctf_fs_ds_index *index)
{
if (!index) {
if (index->entries) {
g_ptr_array_free(index->entries, TRUE);
}
- g_free(index);
+
+ delete index;
}