lib: add bt_{graph,query_executor}_add_interrupter()
[babeltrace.git] / src / lib / lib-logging.c
index c9c8249b39af6ed07d5f7321495e6c56e6f98e8c..e9afb80656da61d7bb1cdbbc5dbdd28183e540d4 100644 (file)
 #include <glib.h>
 #include "common/common.h"
 #include "common/uuid.h"
-#include <babeltrace2/trace-ir/event-const.h>
-#include <babeltrace2/trace-ir/packet-const.h>
-#include <babeltrace2/trace-ir/stream-const.h>
-#include <babeltrace2/current-thread.h>
+#include <babeltrace2/babeltrace.h>
 
 #include "logging.h"
 #include "assert-pre.h"
 #include "assert-post.h"
 #include "value.h"
+#include "integer-range-set.h"
 #include "object-pool.h"
+#include "graph/interrupter.h"
 #include "graph/component-class.h"
 #include "graph/component-class-sink-colander.h"
 #include "graph/component-filter.h"
@@ -104,11 +103,17 @@ static __thread char lib_logging_buf[LIB_LOGGING_BUF_SIZE];
 
 #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL)
 
-#define TMP_PREFIX_LEN 64
+#define TMP_PREFIX_LEN 128
 #define SET_TMP_PREFIX(_prefix2)                                       \
        do {                                                            \
-               snprintf(tmp_prefix, TMP_PREFIX_LEN - 1, "%s%s",        \
-                       prefix, (_prefix2));                            \
+               int snprintf_ret =                                      \
+                       snprintf(tmp_prefix, TMP_PREFIX_LEN - 1, "%s%s", \
+                               prefix, (_prefix2));                    \
+                                                                       \
+               if (snprintf_ret < 0 || snprintf_ret >= TMP_PREFIX_LEN - 1) { \
+                       abort();                                        \
+               }                                                       \
+                                                                       \
                tmp_prefix[TMP_PREFIX_LEN - 1] = '\0';                  \
        } while (0)
 
@@ -228,7 +233,7 @@ static inline void format_field_class(char **buf_ch, bool extended,
        }
        case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
        {
-               const struct bt_field_class_static_array *array_fc =
+               const struct bt_field_class_array_static *array_fc =
                        (const void *) field_class;
 
                format_array_field_class(buf_ch, extended, prefix, field_class);
@@ -237,7 +242,7 @@ static inline void format_field_class(char **buf_ch, bool extended,
        }
        case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
        {
-               const struct bt_field_class_dynamic_array *array_fc =
+               const struct bt_field_class_array_dynamic *array_fc =
                        (const void *) field_class;
 
                format_array_field_class(buf_ch, extended, prefix, field_class);
@@ -256,7 +261,9 @@ static inline void format_field_class(char **buf_ch, bool extended,
 
                break;
        }
-       case BT_FIELD_CLASS_TYPE_VARIANT:
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
        {
                const struct bt_field_class_variant *var_fc =
                        (const void *) field_class;
@@ -266,16 +273,22 @@ static inline void format_field_class(char **buf_ch, bool extended,
                                PRFIELD(var_fc->common.named_fcs->len));
                }
 
-               if (var_fc->selector_fc) {
-                       SET_TMP_PREFIX("selector-fc-");
-                       format_field_class(buf_ch, extended, tmp_prefix,
-                               var_fc->selector_fc);
-               }
+               if (field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR ||
+                               field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) {
+                       const struct bt_field_class_variant_with_selector *var_with_sel_fc =
+                               (const void *) var_fc;
 
-               if (var_fc->selector_field_path) {
-                       SET_TMP_PREFIX("selector-field-path-");
-                       format_field_path(buf_ch, extended, tmp_prefix,
-                               var_fc->selector_field_path);
+                       if (var_with_sel_fc->selector_fc) {
+                               SET_TMP_PREFIX("selector-fc-");
+                               format_field_class(buf_ch, extended, tmp_prefix,
+                                       var_with_sel_fc->selector_fc);
+                       }
+
+                       if (var_with_sel_fc->selector_field_path) {
+                               SET_TMP_PREFIX("selector-field-path-");
+                               format_field_path(buf_ch, extended, tmp_prefix,
+                                       var_with_sel_fc->selector_field_path);
+                       }
                }
 
                break;
@@ -381,7 +394,9 @@ static inline void format_field(char **buf_ch, bool extended,
 
                break;
        }
-       case BT_FIELD_CLASS_TYPE_VARIANT:
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
        {
                const struct bt_field_variant *var_field = (const void *) field;
 
@@ -793,6 +808,12 @@ static inline void format_clock_snapshot(char **buf_ch, bool extended,
        }
 }
 
+static inline void format_interrupter(char **buf_ch, bool extended,
+               const char *prefix, const struct bt_interrupter *intr)
+{
+       BUF_APPEND(", %sis-set=%d", PRFIELD(intr->is_set));
+}
+
 static inline void format_value(char **buf_ch, bool extended,
                const char *prefix, const struct bt_value *value)
 {
@@ -814,13 +835,13 @@ static inline void format_value(char **buf_ch, bool extended,
        case BT_VALUE_TYPE_UNSIGNED_INTEGER:
        {
                BUF_APPEND(", %svalue=%" PRIu64,
-                       PRFIELD(bt_value_unsigned_integer_get(value)));
+                       PRFIELD(bt_value_integer_unsigned_get(value)));
                break;
        }
        case BT_VALUE_TYPE_SIGNED_INTEGER:
        {
                BUF_APPEND(", %svalue=%" PRId64,
-                       PRFIELD(bt_value_signed_integer_get(value)));
+                       PRFIELD(bt_value_integer_signed_get(value)));
                break;
        }
        case BT_VALUE_TYPE_REAL:
@@ -858,6 +879,19 @@ static inline void format_value(char **buf_ch, bool extended,
        }
 }
 
+static inline void format_integer_range_set(char **buf_ch, bool extended,
+               const char *prefix,
+               const struct bt_integer_range_set *range_set)
+{
+       BUF_APPEND(", %srange-count=%u", PRFIELD(range_set->ranges->len));
+
+       if (!extended) {
+               return;
+       }
+
+       BUF_APPEND(", %sis-frozen=%d", PRFIELD(range_set->frozen));
+}
+
 static inline void format_message(char **buf_ch, bool extended,
                const char *prefix, const struct bt_message *msg)
 {
@@ -1086,9 +1120,7 @@ static inline void format_graph(char **buf_ch, bool extended,
 {
        char tmp_prefix[TMP_PREFIX_LEN];
 
-       BUF_APPEND(", %sis-canceled=%d, %scan-consume=%d, "
-               "%sconfig-state=%s",
-               PRFIELD(graph->canceled),
+       BUF_APPEND(", %scan-consume=%d, %sconfig-state=%s",
                PRFIELD(graph->can_consume),
                PRFIELD(bt_graph_configuration_state_string(graph->config_state)));
 
@@ -1392,6 +1424,9 @@ static inline void handle_conversion_specifier_bt(void *priv_data,
        case 'v':
                format_value(buf_ch, extended, prefix, obj);
                break;
+       case 'R':
+               format_integer_range_set(buf_ch, extended, prefix, obj);
+               break;
        case 'n':
                format_message(buf_ch, extended, prefix, obj);
                break;
@@ -1416,6 +1451,9 @@ static inline void handle_conversion_specifier_bt(void *priv_data,
        case 'g':
                format_graph(buf_ch, extended, prefix, obj);
                break;
+       case 'z':
+               format_interrupter(buf_ch, extended, prefix, obj);
+               break;
        case 'o':
                format_object_pool(buf_ch, extended, prefix, obj);
                break;
This page took 0.026807 seconds and 4 git commands to generate.