Rename VERBOSE log level to TRACE
[babeltrace.git] / src / common / common.h
index d5f2d096e89dd8f1b48754c9205ef7c9b636bd38..6f9fb65df4bf069fbe24dc07a5ceb20784600a3f 100644 (file)
@@ -37,6 +37,9 @@
 #include <babeltrace2/trace-ir/event-class-const.h>
 #include <babeltrace2/trace-ir/field-class-const.h>
 #include <babeltrace2/trace-ir/field-path-const.h>
+#include <babeltrace2/graph/self-component.h>
+#include <babeltrace2/graph/message-iterator-const.h>
+#include <babeltrace2/logging.h>
 #include <babeltrace2/value.h>
 
 #include "common/assert.h"
@@ -92,7 +95,7 @@ const char *bt_common_get_system_plugin_path(void);
  * return value.
  */
 BT_HIDDEN
-char *bt_common_get_home_plugin_path(void);
+char *bt_common_get_home_plugin_path(int log_level);
 
 /*
  * Appends the list of directories in `paths` to the array `dirs`.
@@ -309,7 +312,23 @@ void bt_common_custom_snprintf(char *buf, size_t buf_size,
  * Returns the system page size.
  */
 BT_HIDDEN
-size_t bt_common_get_page_size(void);
+size_t bt_common_get_page_size(int log_level);
+
+/*
+ * Adds the digit separator `sep` as many times as needed to form groups
+ * of `digits_per_group` digits within `str`. `str` must have enough
+ * room to accomodate the new separators, that is:
+ *
+ *     strlen(str) + (strlen(str) / digits_per_group) + 1
+ *
+ * Example: with `str` `1983198398213`, `digits_per_group` 3, and `sep`
+ * `,`, `str` becomes `1,983,198,398,213`.
+ *
+ * `strlen(str)` must not be 0. `digits_per_group` must not be 0. `sep`
+ * must not be `\0`.
+ */
+BT_HIDDEN
+void bt_common_sep_digits(char *str, unsigned int digits_per_group, char sep);
 
 /*
  * Wraps read() function to handle EINTR and partial reads.
@@ -317,7 +336,7 @@ size_t bt_common_get_page_size(void);
  * value smaller than the requested `count`.
  */
 static inline
-ssize_t bt_common_read(int fd, void *buf, size_t count)
+ssize_t bt_common_read(int fd, void *buf, size_t count, int log_level)
 {
        size_t i = 0;
        ssize_t ret;
@@ -331,15 +350,18 @@ ssize_t bt_common_read(int fd, void *buf, size_t count)
                ret = read(fd, buf + i, count - i);
                if (ret < 0) {
                        if (errno == EINTR) {
-#ifdef BT_LOGD_STR
-                               BT_LOGD_STR("read() call interrupted. Retrying...");
+#ifdef BT_LOG_WRITE_CUR_LVL
+                               BT_LOG_WRITE_CUR_LVL(BT_LOG_DEBUG, log_level,
+                                       BT_LOG_TAG,
+                                       "read() call interrupted; retrying...");
 #endif
                                /* retry operation */
                                continue;
                        } else {
-#ifdef BT_LOGE_ERRNO
-                               BT_LOGE_ERRNO("Error while reading", ": fd=%d",
-                                       fd);
+#ifdef BT_LOG_WRITE_ERRNO_CUR_LVL
+                               BT_LOG_WRITE_ERRNO_CUR_LVL(BT_LOG_ERROR,
+                                       log_level, BT_LOG_TAG,
+                                       "Error while reading", ": fd=%d", fd);
 #endif
                                goto end;
                        }
@@ -546,6 +568,72 @@ const char *bt_common_self_message_iterator_status_string(
        }
 };
 
+static inline
+const char *bt_common_logging_level_string(
+               enum bt_logging_level level)
+{
+       switch (level) {
+       case BT_LOGGING_LEVEL_TRACE:
+               return "BT_LOGGING_LEVEL_TRACE";
+       case BT_LOGGING_LEVEL_DEBUG:
+               return "BT_LOGGING_LEVEL_DEBUG";
+       case BT_LOGGING_LEVEL_INFO:
+               return "BT_LOGGING_LEVEL_INFO";
+       case BT_LOGGING_LEVEL_WARN:
+               return "BT_LOGGING_LEVEL_WARN";
+       case BT_LOGGING_LEVEL_ERROR:
+               return "BT_LOGGING_LEVEL_ERROR";
+       case BT_LOGGING_LEVEL_FATAL:
+               return "BT_LOGGING_LEVEL_FATAL";
+       case BT_LOGGING_LEVEL_NONE:
+               return "BT_LOGGING_LEVEL_NONE";
+       default:
+               return "(unknown)";
+       }
+};
+
+static inline
+const char *bt_self_component_status_string(
+               enum bt_self_component_status status)
+{
+       switch (status) {
+       case BT_SELF_COMPONENT_STATUS_OK:
+               return "BT_SELF_COMPONENT_STATUS_OK";
+       case BT_SELF_COMPONENT_STATUS_END:
+               return "BT_SELF_COMPONENT_STATUS_END";
+       case BT_SELF_COMPONENT_STATUS_AGAIN:
+               return "BT_SELF_COMPONENT_STATUS_AGAIN";
+       case BT_SELF_COMPONENT_STATUS_REFUSE_PORT_CONNECTION:
+               return "BT_SELF_COMPONENT_STATUS_REFUSE_PORT_CONNECTION";
+       case BT_SELF_COMPONENT_STATUS_ERROR:
+               return "BT_SELF_COMPONENT_STATUS_ERROR";
+       case BT_SELF_COMPONENT_STATUS_NOMEM:
+               return "BT_SELF_COMPONENT_STATUS_NOMEM";
+       default:
+               return "(unknown)";
+       }
+}
+
+static inline
+const char *bt_message_iterator_status_string(
+               enum bt_message_iterator_status status)
+{
+       switch (status) {
+       case BT_MESSAGE_ITERATOR_STATUS_AGAIN:
+               return "BT_MESSAGE_ITERATOR_STATUS_AGAIN";
+       case BT_MESSAGE_ITERATOR_STATUS_END:
+               return "BT_MESSAGE_ITERATOR_STATUS_END";
+       case BT_MESSAGE_ITERATOR_STATUS_OK:
+               return "BT_MESSAGE_ITERATOR_STATUS_OK";
+       case BT_MESSAGE_ITERATOR_STATUS_ERROR:
+               return "BT_MESSAGE_ITERATOR_STATUS_ERROR";
+       case BT_MESSAGE_ITERATOR_STATUS_NOMEM:
+               return "BT_MESSAGE_ITERATOR_STATUS_NOMEM";
+       default:
+               return "(unknown)";
+       }
+}
+
 #define NS_PER_S_I     INT64_C(1000000000)
 #define NS_PER_S_U     UINT64_C(1000000000)
 
@@ -643,4 +731,5 @@ enum bt_self_message_iterator_status bt_common_message_iterator_status_to_self(
 {
        return (int) status;
 }
+
 #endif /* BABELTRACE_COMMON_INTERNAL_H */
This page took 0.024731 seconds and 4 git commands to generate.