Lines Matching refs:buffer
26 static void stats_buffer_list_append(struct modem_stats_buffer *buffer) in stats_buffer_list_append() argument
29 sys_slist_append(&stats_buffer_list, &buffer->node); in stats_buffer_list_append()
44 static struct modem_stats_buffer *stats_buffer_list_next(struct modem_stats_buffer *buffer) in stats_buffer_list_next() argument
49 next = stats_buffer_from_node(sys_slist_peek_next(&buffer->node)); in stats_buffer_list_next()
74 static void stats_buffer_get_and_clear_max_used(struct modem_stats_buffer *buffer, in stats_buffer_get_and_clear_max_used() argument
78 *max_used = buffer->max_used; in stats_buffer_get_and_clear_max_used()
79 buffer->max_used = 0; in stats_buffer_get_and_clear_max_used()
83 static bool stats_buffer_length_is_valid(const struct modem_stats_buffer *buffer, uint32_t length) in stats_buffer_length_is_valid() argument
85 return length <= buffer->size; in stats_buffer_length_is_valid()
88 static void stats_buffer_log_invalid_length(const struct modem_stats_buffer *buffer, in stats_buffer_log_invalid_length() argument
91 LOG_ERR("%s: length (%u) exceeds size (%u)", buffer->name, length, buffer->size); in stats_buffer_log_invalid_length()
94 static void stats_buffer_update_max_used(struct modem_stats_buffer *buffer, uint32_t length) in stats_buffer_update_max_used() argument
97 if (buffer->max_used < length) { in stats_buffer_update_max_used()
98 buffer->max_used = length; in stats_buffer_update_max_used()
104 const struct modem_stats_buffer *buffer, in stats_buffer_print_to_shell() argument
107 shell_print(sh, "%s: used at most: %u of %u (%u%%)", buffer->name, max_used, in stats_buffer_print_to_shell()
108 buffer->size, percent_used(max_used, buffer->size)); in stats_buffer_print_to_shell()
113 struct modem_stats_buffer *buffer; in stats_buffer_shell_cmd_handler() local
119 buffer = stats_buffer_list_first(); in stats_buffer_shell_cmd_handler()
121 if (buffer == NULL) { in stats_buffer_shell_cmd_handler()
126 while (buffer != NULL) { in stats_buffer_shell_cmd_handler()
127 stats_buffer_get_and_clear_max_used(buffer, &max_used); in stats_buffer_shell_cmd_handler()
128 stats_buffer_print_to_shell(sh, buffer, max_used); in stats_buffer_shell_cmd_handler()
129 buffer = stats_buffer_list_next(buffer); in stats_buffer_shell_cmd_handler()
137 SHELL_CMD(buffer, NULL, "Get buffer statistics", stats_buffer_shell_cmd_handler),
143 static void stats_buffer_set_name(struct modem_stats_buffer *buffer, const char *name) in stats_buffer_set_name() argument
145 buffer->name[sizeof(buffer->name) - 1] = '\0'; in stats_buffer_set_name()
146 strncpy(buffer->name, name, sizeof(buffer->name) - 1); in stats_buffer_set_name()
149 void modem_stats_buffer_init(struct modem_stats_buffer *buffer, in modem_stats_buffer_init() argument
152 stats_buffer_set_name(buffer, name); in modem_stats_buffer_init()
153 buffer->max_used = 0; in modem_stats_buffer_init()
154 buffer->size = size; in modem_stats_buffer_init()
155 stats_buffer_list_append(buffer); in modem_stats_buffer_init()
158 void modem_stats_buffer_advertise_length(struct modem_stats_buffer *buffer, uint32_t length) in modem_stats_buffer_advertise_length() argument
160 if (!stats_buffer_length_is_valid(buffer, length)) { in modem_stats_buffer_advertise_length()
161 stats_buffer_log_invalid_length(buffer, length); in modem_stats_buffer_advertise_length()
165 stats_buffer_update_max_used(buffer, length); in modem_stats_buffer_advertise_length()