return ret;
}
+static int logger_getsize(struct fd_info *fdi, uint32_t *val)
+{
+ assert(fdi);
+
+ int r = logger_ioctl(fdi->fd, LOGGER_GET_LOG_BUF_SIZE);
+ if (r < 0)
+ return r;
+
+ *val = (uint32_t)r;
+ return 0;
+}
+
/**
* @brief Get buffer filled size
* @details Sends a get log len ioctl to given fd
.extract_entry = logger_extract_entry,
.prepare_print = logger_prepare_print,
.clear = logger_clear,
+ .getsize = logger_getsize,
};
int sock_fd;
};
+static int pipe_getsize(struct fd_info *fdi, uint32_t *val)
+{
+ 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_GETSIZE, NULL, 0);
+ if (r < 0)
+ return r;
+
+ uint32_t *data;
+ int datalen;
+ r = recv_dlog_reply(ppd->sock_fd, DLOG_REQ_GETSIZE, (void **)&data, &datalen);
+ if (r < 0)
+ goto cleanup;
+ if (!data || datalen != sizeof *data) {
+ r = -EINVAL;
+ goto cleanup;
+ }
+ *val = *data;
+
+cleanup:
+ free(data);
+ return r;
+}
+
/**
* @brief Clear request
* @details Send a CLEAR request to the logger daemon
.extract_entry = generic_extract_entry,
.prepare_print = pipe_prepare_print,
.clear = pipe_clear,
+ .getsize = pipe_getsize,
};
} action_e;
/**
- * @brief Get buffer size
- * @details Print the size of the working buffer
- * @param[in] conf The configuration
- * @param[in] names Buffers to process
- * @param[in] cnt Buffer count
- * @return 0 on success, 1 on failure
- */
-static int do_getsize(struct log_config *conf, int enabled_buffers)
-{
- for (log_id_t i = 0; i < LOG_ID_MAX; ++i) {
- if (!bit_test(enabled_buffers, i))
- continue;
-
- char conf_key[MAX_CONF_KEY_LEN];
- const char *const bufname = log_name_by_id(i);
- snprintf(conf_key, MAX_CONF_KEY_LEN, "%s_size", bufname);
- const char *conf_value = log_config_get(conf, conf_key);
- if (!conf_value) {
- printf("Error: could not get size of buffer #%d (%s); it has no config entry\n", i, bufname);
- return 1;
- }
-
- printf("Buffer #%d (%s) has size %d KB\n", i, bufname, BtoKiB(atoi(conf_value)));
- }
- return 0;
-}
-
-/**
* @brief Process log
* @details Processes a raw log and, if it's old enough, prints it
* @param[in] e The entry to process
if (!sort_vector_finalize(&logs))
goto err_nomem;
- if (action == ACTION_GETSIZE)
- return do_getsize(&conf, enabled_buffers);
-
conf_value = log_config_get(&conf, "backend");
if (!conf_value) {
printf("Error: backend not defined\n");
case ACTION_PRINT: {
r = fdi->ops->prepare_print(fdi, dump, filters, l_file.format);
break;
- } case ACTION_GETSIZE:
- // r = fdi->ops->getsize(fdi);
+ } case ACTION_GETSIZE: {
+ uint32_t size;
+ r = fdi->ops->getsize(fdi, &size);
+ if (!r)
+ printf("%s: %u KiB\n", fdi->name, BtoKiB(size));
break;
- default:
+ } default:
assert(false);
}