int dlogutil_buffer_get_capacity(dlogutil_buffer_e buffer, unsigned int *capacity);
/**
+ * @brief Gets the usage of a buffer.
+ * @since_tizen 6.0
+ * @remarks Either CAP_SYSLOG or being in the log group is required.
+ * @bug This is currently evaluated using the config file, which can change at runtime. In particular,
+ * this can desync from the value of the server if the config file changes. Note that this is mostly
+ * a theoretical concern, since the file is not intended to change during the runtime (the daemon asks
+ * to reboot the system in such a case).
+ * @param[in] buffer A single buffer to be inspected
+ * @param[out] usage Buffer's current usage, in bytes
+ * @return An error code
+ * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER More than one buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
+ * @retval Other An arbitrary Tizen error code
+ */
+int dlogutil_buffer_get_usage(dlogutil_buffer_e buffer, unsigned int *usage);
+
+/**
* @brief Gets the default timestamp type of a buffer.
* @since_tizen 6.0
* @remarks This is the timestamp type that will be used for sorting by default.
/// Get the capacity of the buffer
int (*get_capacity)(struct fd_info *fdi, unsigned int *capacity);
+ /// Get the current size (usage) of the buffer
+ int (*get_usage)(struct fd_info *fdi, unsigned int *used);
+
/// Check whether there will be no more logs on this FD
bool (*eof)(const struct fd_info *fdi);
return 0;
}
+static int logger_get_usage(struct fd_info *fdi, unsigned int *usage)
+{
+ assert(fdi);
+
+ int r = logger_ioctl(fdi->fd, LOGGER_GET_LOG_LEN);
+ if (r < 0)
+ return r;
+
+ *usage = (unsigned int)r;
+ return 0;
+}
+
/**
* @brief Get buffer filled size
* @details Sends a get log len ioctl to given fd
.prepare_print = logger_prepare_print,
.clear = logger_clear,
.get_capacity = logger_get_capacity,
+ .get_usage = logger_get_usage,
.eof = logger_eof,
.should_filter = true,
};
return r;
}
+static int pipe_get_usage(struct fd_info *fdi, unsigned int *usage)
+{
+ assert(fdi);
+ struct pipe_priv_data *ppd = (struct pipe_priv_data *)fdi->priv_data;
+ assert(ppd);
+ assert(ppd->sock_fd >= 0);
+
+ int r = send_dlog_request(ppd->sock_fd, DLOG_REQ_GET_USAGE, NULL, 0);
+ if (r < 0)
+ return r;
+
+ unsigned int *data;
+ int datalen;
+ r = recv_dlog_reply(ppd->sock_fd, DLOG_REQ_GET_USAGE, (void **)&data, &datalen);
+ if (r < 0)
+ goto cleanup;
+
+ if (!data || datalen != sizeof *data) {
+ r = -EINVAL;
+ goto cleanup;
+ }
+
+ *usage = *data;
+
+cleanup:
+ free(data);
+ return r;
+}
+
/**
* @brief Clear request
* @details Send a CLEAR request to the logger daemon
.prepare_print = pipe_prepare_print,
.clear = pipe_clear,
.get_capacity = pipe_get_capacity,
+ .get_usage = pipe_get_usage,
.eof = pipe_eof,
.should_filter = false,
};
return fdi_ptrs[0]->ops->get_capacity(fdi_ptrs[0], capacity);
}
+EXPORT_API int dlogutil_buffer_get_usage(dlogutil_buffer_e buffer, unsigned int *usage)
+{
+ CHECK_PARAM(usage);
+
+ COMMON_INIT_SINGLE
+
+ return fdi_ptrs[0]->ops->get_usage(fdi_ptrs[0], usage);
+}
+
EXPORT_API int dlogutil_buffer_get_default_ts_type(dlogutil_buffer_e buffer, dlogutil_sorting_order_e *type)
{
CHECK_PARAM(type);
if (r != 0)
return r;
- unsigned int capacity;
+ unsigned int usage, capacity;
r = dlogutil_buffer_get_capacity(buffer, &capacity);
if (r != 0)
return r;
- printf("%s: %u KiB\n", name, BtoKiB(capacity));
+ r = dlogutil_buffer_get_usage(buffer, &usage);
+ if (r != 0)
+ return r;
+
+ printf("%s: %u KiB, of which %u used (%u%%)\n", name, BtoKiB(capacity), BtoKiB(usage), 100 * usage / capacity);
return 0;
}
ioctl_ret = -77;
assert(-77 == ops_logger.clear(&fdi));
- unsigned int sz;
+ unsigned int us, sz;
expected_ioctl = LOGGER_GET_LOG_BUF_SIZE;
ioctl_ret = -EALREADY;
assert(-EALREADY == ops_logger.get_capacity(&fdi, &sz));
+ assert(-EALREADY == ops_logger.get_usage(&fdi, &us));
expected_ioctl = LOGGER_GET_LOG_LEN;
ioctl_ret = -67;
ioctl_ret = 15;
assert(0 == ops_logger.clear(&fdi));
- unsigned int sz;
+ unsigned int us, sz;
+ expected_ioctl = LOGGER_GET_LOG_BUF_SIZE;
+ ioctl_ret = -EALREADY;
+ assert(-EALREADY == ops_logger.get_capacity(&fdi, &sz));
+ assert(-EALREADY == ops_logger.get_usage(&fdi, &us));
+
expected_ioctl = LOGGER_GET_LOG_BUF_SIZE;
ioctl_ret = 2019;
assert(0 == ops_logger.get_capacity(&fdi, &sz));
+ assert(0 == ops_logger.get_usage(&fdi, &us));
assert(2019 == sz);
+ assert(2020 == us);
+
+ expected_ioctl = LOGGER_GET_LOG_BUF_SIZE;
+ fail_next_ioctl = true;
+ sz = 0xBAADF00D;
+ us = 0xDEADBEEF;
+
+ assert(0 == ops_logger.get_capacity(&fdi, &sz));
+ assert(-4665 == ops_logger.get_usage(&fdi, &us));
+ assert(2021 == sz);
+ assert(0xDEADBEEF == us);
+ fail_next_ioctl = false;
expected_ioctl = LOGGER_GET_LOG_LEN;
ioctl_ret = 0;
static int expected_ioctl;
static int ioctl_ret;
+static bool fail_next_ioctl;
int __real_ioctl(int fd, int request, char *argp);
int __wrap_ioctl(int fd, int request, char *argp)
{
assert(fd == 0xFD);
assert(expected_ioctl == request);
+ if (LOGGER_GET_LOG_BUF_SIZE == expected_ioctl)
+ expected_ioctl = LOGGER_GET_LOG_LEN;
+
if (ioctl_ret < 0) {
errno = -ioctl_ret;
return -1;
}
- return ioctl_ret;
-}
+ if (fail_next_ioctl) {
+ const int temp = ioctl_ret;
+ ioctl_ret = -4665;
+ return temp;
+ }
+ return ioctl_ret++;
+}
correct_request = DLOG_REQ_GET_CAPACITY;
correct_send_data = NULL;
correct_send_datalen = 0;
- unsigned int size_target = 0;
+ unsigned int size_target = 0, usage_target = 0;
send_return = -1;
assert(ops_pipe.get_capacity(&info, &size_target) == -1);
+ correct_request = DLOG_REQ_GET_USAGE;
+ assert(ops_pipe.get_usage(&info, &usage_target) == -1);
+
send_return = 0;
recv_return = -1;
+ correct_request = DLOG_REQ_GET_CAPACITY;
assert(ops_pipe.get_capacity(&info, &size_target) == -1);
+ correct_request = DLOG_REQ_GET_USAGE;
+ assert(ops_pipe.get_usage(&info, &usage_target) == -1);
recv_return = 0;
const char *wrong_ans = "I won't tell you the pipe size :)";
assert(recv_data);
memcpy(recv_data, wrong_ans, recv_datalen);
ptr_to_free = recv_data;
+ correct_request = DLOG_REQ_GET_CAPACITY;
assert(ops_pipe.get_capacity(&info, &size_target) == -EINVAL);
assert(ptr_to_free == NULL);
+ recv_data = malloc(recv_datalen);
+ assert(recv_data);
+ memcpy(recv_data, wrong_ans, recv_datalen);
+ ptr_to_free = recv_data;
+ correct_request = DLOG_REQ_GET_USAGE;
+ assert(ops_pipe.get_usage(&info, &usage_target) == -EINVAL);
+ assert(ptr_to_free == NULL);
+
recv_datalen = 0;
recv_data = NULL;
+ correct_request = DLOG_REQ_GET_CAPACITY;
assert(ops_pipe.get_capacity(&info, &size_target) == -EINVAL);
+ correct_request = DLOG_REQ_GET_USAGE;
+ assert(ops_pipe.get_usage(&info, &usage_target) == -EINVAL);
ops_pipe.destroy(&info);
ops_pipe.destroy(&info);
assert(ops_pipe.clear(&info) == 0);
correct_request = DLOG_REQ_GET_CAPACITY;
- unsigned int size_target = 0;
+ unsigned int size_target = 0, usage_target = 0;
recv_return = 0;
recv_datalen = sizeof(unsigned int);
ptr_to_free = recv_data;
assert(ops_pipe.get_capacity(&info, &size_target) == 0);
assert(ptr_to_free == NULL);
+
+ correct_request = DLOG_REQ_GET_USAGE;
+ recv_data = malloc(recv_datalen);
+ assert(recv_data);
+ *(int *)recv_data = (unsigned int)235U;
+ ptr_to_free = recv_data;
+ assert(ops_pipe.get_usage(&info, &usage_target) == 0);
+ assert(ptr_to_free == NULL);
+
assert(size_target == 17);
+ assert(usage_target == 235U);
ptr_to_free = ppd;
ops_pipe.destroy(&info);
assert(dlogutil_buffer_get_name(DLOGUTIL_BUF_KMSG, &name) == 0);
assert(!strcmp(name, "kmsg"));
- unsigned int capacity;
+ unsigned int usage, capacity;
assert(dlogutil_buffer_get_capacity(DLOGUTIL_BUF_MAIN, &capacity) == 0);
+ assert(dlogutil_buffer_get_usage(DLOGUTIL_BUF_MAIN, &usage) == 0);
if (pipe)
assert(capacity == MB(1));
else {
}
assert(dlogutil_buffer_get_capacity(DLOGUTIL_BUF_KMSG, &capacity) == 0);
+ assert(dlogutil_buffer_get_usage(DLOGUTIL_BUF_KMSG, &usage) == 0);
assert(capacity == MB(1));
dlogutil_sorting_order_e type;
assert(dlogutil_buffer_clear(0) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_name(0, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_capacity(0, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_usage(0, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_default_ts_type(0, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_check_ts_type_available(0, DLOGUTIL_SORT_RECV_MONO, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_clear(1 << 16) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_name(1 << 16, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_capacity(1 << 16, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_usage(1 << 16, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_default_ts_type(1 << 16, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_check_ts_type_available(1 << 16, DLOGUTIL_SORT_RECV_MONO, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_clear(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_name(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_capacity(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_usage(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_default_ts_type(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_check_ts_type_available(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, DLOGUTIL_SORT_RECV_MONO, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_entry_get_message(bad_ptr, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_name(DLOGUTIL_BUF_MAIN, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_capacity(DLOGUTIL_BUF_MAIN, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_usage(DLOGUTIL_BUF_MAIN, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_get_default_ts_type(DLOGUTIL_BUF_MAIN, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
assert(dlogutil_buffer_check_ts_type_available(DLOGUTIL_BUF_MAIN, DLOGUTIL_SORT_RECV_MONO, NULL) == TIZEN_ERROR_INVALID_PARAMETER);