* all copies or substantial portions of the Software.
*/
-#define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-RESOLVE"
-#include "logging.h"
+#define BT_LOG_OUTPUT_LEVEL (ctx->log_level)
+#define BT_LOG_TAG "PLUGIN/CTF/META/RESOLVE"
+#include "logging/log.h"
#include <babeltrace2/babeltrace.h>
-#include "common/babeltrace.h"
+#include "common/macros.h"
#include "common/assert.h"
#include "common/common.h"
#include <glib.h>
* The current context of the resolving engine.
*/
struct resolve_context {
+ bt_logging_level log_level;
struct ctf_trace_class *tc;
struct ctf_stream_class *sc;
struct ctf_event_class *ec;
* Pushes a field class onto a class stack.
*/
static
-int field_class_stack_push(field_class_stack *stack, struct ctf_field_class *fc)
+int field_class_stack_push(field_class_stack *stack, struct ctf_field_class *fc,
+ struct resolve_context *ctx)
{
int ret = 0;
struct field_class_stack_frame *frame = NULL;
goto end;
}
- BT_LOGV("Pushing field class on context's stack: "
+ BT_LOGD("Pushing field class on context's stack: "
"fc-addr=%p, stack-size-before=%u", fc, stack->len);
frame->fc = fc;
g_ptr_array_add(stack, frame);
* Removes the top frame of `stack`.
*/
static
-void field_class_stack_pop(field_class_stack *stack)
+void field_class_stack_pop(field_class_stack *stack,
+ struct resolve_context *ctx)
{
if (!field_class_stack_empty(stack)) {
/*
* This will call the frame's destructor and free it, as
* well as put its contained field class.
*/
- BT_LOGV("Popping context's stack: stack-size-before=%u",
+ BT_LOGD("Popping context's stack: stack-size-before=%u",
stack->len);
g_ptr_array_set_size(stack, stack->len - 1);
}
* is found to be relative.
*/
static
-enum ctf_scope get_root_scope_from_absolute_pathstr(const char *pathstr)
+enum ctf_scope get_root_scope_from_absolute_pathstr(const char *pathstr,
+ struct resolve_context *ctx)
{
enum ctf_scope scope;
enum ctf_scope ret = -1;
if (strncmp(pathstr, absolute_path_prefixes[scope],
strlen(absolute_path_prefixes[scope]))) {
/* Prefix does not match: try the next one */
- BT_LOGV("Prefix does not match: trying the next one: "
+ BT_LOGD("Prefix does not match: trying the next one: "
"path=\"%s\", path-prefix=\"%s\", scope=%s",
pathstr, absolute_path_prefixes[scope],
ctf_scope_string(scope));
/* Found it! */
ret = scope;
- BT_LOGV("Found root scope from absolute path: "
+ BT_LOGD("Found root scope from absolute path: "
"path=\"%s\", scope=%s", pathstr,
ctf_scope_string(scope));
goto end;
* strings.
*/
static
-GList *pathstr_to_ptokens(const char *pathstr)
+GList *pathstr_to_ptokens(const char *pathstr, struct resolve_context *ctx)
{
const char *at = pathstr;
const char *last = at;
*/
static
int ptokens_to_field_path(GList *ptokens, struct ctf_field_path *field_path,
- struct ctf_field_class *fc, int64_t src_index)
+ struct ctf_field_class *fc, int64_t src_index,
+ struct resolve_context *ctx)
{
int ret = 0;
GList *cur_ptoken = ptokens;
struct ctf_field_class *child_fc;
const char *ft_name = ptoken_get_string(cur_ptoken);
- BT_LOGV("Current path token: token=\"%s\"", ft_name);
+ BT_LOGD("Current path token: token=\"%s\"", ft_name);
/* Find to which index corresponds the current path token */
if (fc->type == CTF_FIELD_CLASS_TYPE_ARRAY ||
* Error: field name does not exist or
* wrong current class.
*/
- BT_LOGV("Cannot get index of field class: "
+ BT_LOGD("Cannot get index of field class: "
"field-name=\"%s\", "
"src-index=%" PRId64 ", "
"child-index=%" PRId64 ", "
goto end;
} else if (child_index > src_index &&
!first_level_done) {
- BT_LOGV("Child field class is located after source field class: "
+ BT_LOGD("Child field class is located after source field class: "
"field-name=\"%s\", "
"src-index=%" PRId64 ", "
"child-index=%" PRId64 ", "
}
/* Locate target */
- ret = ptokens_to_field_path(cur_ptoken, field_path, fc, INT64_MAX);
+ ret = ptokens_to_field_path(cur_ptoken, field_path, fc, INT64_MAX, ctx);
end:
return ret;
int64_t cur_index = field_class_stack_at(ctx->field_class_stack,
parent_pos_in_stack)->index;
- BT_LOGV("Locating target field class from current parent field class: "
+ BT_LOGD("Locating target field class from current parent field class: "
"parent-pos=%" PRId64 ", parent-fc-addr=%p, "
"cur-index=%" PRId64,
parent_pos_in_stack, parent_class, cur_index);
/* Locate target from current parent class */
ret = ptokens_to_field_path(ptokens, &tail_field_path,
- parent_class, cur_index);
+ parent_class, cur_index, ctx);
if (ret) {
/* Not found... yet */
- BT_LOGV_STR("Not found at this point.");
+ BT_LOGD_STR("Not found at this point.");
ctf_field_path_clear(&tail_field_path);
} else {
/* Found: stitch tail field path to head field path */
GList *ptokens = NULL;
/* Convert path string to path tokens */
- ptokens = pathstr_to_ptokens(pathstr);
+ ptokens = pathstr_to_ptokens(pathstr, ctx);
if (!ptokens) {
BT_LOGE("Cannot convert path string to path tokens: "
"path=\"%s\"", pathstr);
}
/* Absolute or relative path? */
- root_scope = get_root_scope_from_absolute_pathstr(pathstr);
+ root_scope = get_root_scope_from_absolute_pathstr(pathstr, ctx);
if (root_scope == -1) {
/* Relative path: start with current root scope */
field_path->root = ctx->root_scope;
- BT_LOGV("Detected relative path: starting with current root scope: "
+ BT_LOGD("Detected relative path: starting with current root scope: "
"scope=%s", ctf_scope_string(field_path->root));
ret = relative_ptokens_to_field_path(ptokens, field_path, ctx);
if (ret) {
} else {
/* Absolute path: use found root scope */
field_path->root = root_scope;
- BT_LOGV("Detected absolute path: using root scope: "
+ BT_LOGD("Detected absolute path: using root scope: "
"scope=%s", ctf_scope_string(field_path->root));
ret = absolute_ptokens_to_field_path(ptokens, field_path, ctx);
if (ret) {
const char *field_path_pretty_str =
field_path_pretty ? field_path_pretty->str : NULL;
- BT_LOGV("Found field path: path=\"%s\", field-path=\"%s\"",
+ BT_LOGD("Found field path: path=\"%s\", field-path=\"%s\"",
pathstr, field_path_pretty_str);
if (field_path_pretty) {
* objects having the same root scope.
*/
int64_t get_field_paths_lca_index(struct ctf_field_path *field_path1,
- struct ctf_field_path *field_path2)
+ struct ctf_field_path *field_path2,
+ struct resolve_context *ctx)
{
int64_t lca_index = 0;
uint64_t field_path1_len, field_path2_len;
const char *field_path2_pretty_str =
field_path2_pretty ? field_path2_pretty->str : NULL;
- BT_LOGV("Finding lowest common ancestor (LCA) between two field paths: "
+ BT_LOGD("Finding lowest common ancestor (LCA) between two field paths: "
"field-path-1=\"%s\", field-path-2=\"%s\"",
field_path1_pretty_str, field_path2_pretty_str);
lca_index++;
}
- BT_LOGV("Found LCA: lca-index=%" PRId64, lca_index);
+ BT_LOGD("Found LCA: lca-index=%" PRId64, lca_index);
return lca_index;
}
* paths.
*/
lca_index = get_field_paths_lca_index(target_field_path,
- &ctx_field_path);
+ &ctx_field_path, ctx);
if (lca_index < 0) {
BT_LOGE_STR("Cannot get least common ancestor.");
ret = -1;
uint64_t field_count =
ctf_field_class_compound_get_field_class_count(fc);
- ret = field_class_stack_push(ctx->field_class_stack, fc);
+ ret = field_class_stack_push(ctx->field_class_stack, fc, ctx);
if (ret) {
BT_LOGE("Cannot push field class on context's stack: "
"fc-addr=%p", fc);
(int64_t) i;
}
- BT_LOGV("Resolving field class's child field class: "
+ BT_LOGD("Resolving field class's child field class: "
"parent-fc-addr=%p, child-fc-addr=%p, "
"index=%" PRIu64 ", count=%" PRIu64,
fc, child_fc, i, field_count);
}
}
- field_class_stack_pop(ctx->field_class_stack);
+ field_class_stack_pop(ctx->field_class_stack, ctx);
break;
}
default:
}
BT_HIDDEN
-int ctf_trace_class_resolve_field_classes(struct ctf_trace_class *tc)
+int ctf_trace_class_resolve_field_classes(struct ctf_trace_class *tc,
+ bt_logging_level log_level)
{
int ret = 0;
uint64_t i;
- struct resolve_context ctx = {
+ struct resolve_context local_ctx = {
+ .log_level = log_level,
.tc = tc,
.sc = NULL,
.ec = NULL,
.root_scope = CTF_SCOPE_PACKET_HEADER,
.cur_fc = NULL,
};
+ struct resolve_context *ctx = &local_ctx;
/* Initialize class stack */
- ctx.field_class_stack = field_class_stack_create();
- if (!ctx.field_class_stack) {
+ ctx->field_class_stack = field_class_stack_create();
+ if (!ctx->field_class_stack) {
BT_LOGE_STR("Cannot create field class stack.");
ret = -1;
goto end;
}
if (!tc->is_translated) {
- ctx.scopes.packet_header = tc->packet_header_fc;
- ret = resolve_root_class(CTF_SCOPE_PACKET_HEADER, &ctx);
+ ctx->scopes.packet_header = tc->packet_header_fc;
+ ret = resolve_root_class(CTF_SCOPE_PACKET_HEADER, ctx);
if (ret) {
BT_LOGE("Cannot resolve packet header field class: "
"ret=%d", ret);
}
}
- ctx.scopes.packet_header = tc->packet_header_fc;
+ ctx->scopes.packet_header = tc->packet_header_fc;
for (i = 0; i < tc->stream_classes->len; i++) {
struct ctf_stream_class *sc = tc->stream_classes->pdata[i];
- ret = resolve_stream_class_field_classes(&ctx, sc);
+ ret = resolve_stream_class_field_classes(ctx, sc);
if (ret) {
BT_LOGE("Cannot resolve stream class's field classes: "
"sc-id=%" PRIu64, sc->id);
}
end:
- field_class_stack_destroy(ctx.field_class_stack);
+ field_class_stack_destroy(ctx->field_class_stack);
return ret;
}