kopia lustrzana https://github.com/espressif/esp-idf
refactor(log): replace the tag uncached list with standard SLIST.
NOTE: split the header modify outside.pull/910/merge
rodzic
28c4ba1288
commit
940f5fcb89
|
@ -13,7 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Log library — implementation notes.
|
* Log library â€implementation notes.
|
||||||
*
|
*
|
||||||
* Log library stores all tags provided to esp_log_level_set as a linked
|
* Log library stores all tags provided to esp_log_level_set as a linked
|
||||||
* list. See uncached_tag_entry_t structure.
|
* list. See uncached_tag_entry_t structure.
|
||||||
|
@ -53,6 +53,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
|
#include "rom/queue.h"
|
||||||
|
|
||||||
//print number of bytes per line for esp_log_buffer_char and esp_log_buffer_hex
|
//print number of bytes per line for esp_log_buffer_char and esp_log_buffer_hex
|
||||||
#define BYTES_PER_LINE 16
|
#define BYTES_PER_LINE 16
|
||||||
|
@ -76,14 +77,13 @@ typedef struct {
|
||||||
} cached_tag_entry_t;
|
} cached_tag_entry_t;
|
||||||
|
|
||||||
typedef struct uncached_tag_entry_{
|
typedef struct uncached_tag_entry_{
|
||||||
struct uncached_tag_entry_* next;
|
SLIST_ENTRY(uncached_tag_entry_) entries;
|
||||||
uint8_t level; // esp_log_level_t as uint8_t
|
uint8_t level; // esp_log_level_t as uint8_t
|
||||||
char tag[0]; // beginning of a zero-terminated string
|
char tag[0]; // beginning of a zero-terminated string
|
||||||
} uncached_tag_entry_t;
|
} uncached_tag_entry_t;
|
||||||
|
|
||||||
static esp_log_level_t s_log_default_level = ESP_LOG_VERBOSE;
|
static esp_log_level_t s_log_default_level = ESP_LOG_VERBOSE;
|
||||||
static uncached_tag_entry_t* s_log_tags_head = NULL;
|
static SLIST_HEAD(log_tags_head , uncached_tag_entry_) s_log_tags = SLIST_HEAD_INITIALIZER(s_log_tags);
|
||||||
static uncached_tag_entry_t* s_log_tags_tail = NULL;
|
|
||||||
static cached_tag_entry_t s_log_cache[TAG_CACHE_SIZE];
|
static cached_tag_entry_t s_log_cache[TAG_CACHE_SIZE];
|
||||||
static uint32_t s_log_cache_max_generation = 0;
|
static uint32_t s_log_cache_max_generation = 0;
|
||||||
static uint32_t s_log_cache_entry_count = 0;
|
static uint32_t s_log_cache_entry_count = 0;
|
||||||
|
@ -122,41 +122,29 @@ void esp_log_level_set(const char* tag, esp_log_level_t level)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate new linked list entry and append it to the endo of the list
|
// allocate new linked list entry and append it to the head of the list
|
||||||
size_t entry_size = offsetof(uncached_tag_entry_t, tag) + strlen(tag) + 1;
|
size_t entry_size = offsetof(uncached_tag_entry_t, tag) + strlen(tag) + 1;
|
||||||
uncached_tag_entry_t* new_entry = (uncached_tag_entry_t*) malloc(entry_size);
|
uncached_tag_entry_t* new_entry = (uncached_tag_entry_t*) malloc(entry_size);
|
||||||
if (!new_entry) {
|
if (!new_entry) {
|
||||||
xSemaphoreGive(s_log_mutex);
|
xSemaphoreGive(s_log_mutex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new_entry->next = NULL;
|
|
||||||
new_entry->level = (uint8_t) level;
|
new_entry->level = (uint8_t) level;
|
||||||
strcpy(new_entry->tag, tag);
|
strcpy(new_entry->tag, tag);
|
||||||
if (s_log_tags_tail) {
|
SLIST_INSERT_HEAD( &s_log_tags, new_entry, entries );
|
||||||
s_log_tags_tail->next = new_entry;
|
|
||||||
}
|
|
||||||
s_log_tags_tail = new_entry;
|
|
||||||
if (!s_log_tags_head) {
|
|
||||||
s_log_tags_head = new_entry;
|
|
||||||
}
|
|
||||||
xSemaphoreGive(s_log_mutex);
|
xSemaphoreGive(s_log_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_log_level_list()
|
void clear_log_level_list()
|
||||||
{
|
{
|
||||||
for (uncached_tag_entry_t* it = s_log_tags_head; it != NULL; ) {
|
while( !SLIST_EMPTY(&s_log_tags)) {
|
||||||
uncached_tag_entry_t* next = it->next;
|
SLIST_REMOVE_HEAD(&s_log_tags, entries );
|
||||||
free(it);
|
|
||||||
it = next;
|
|
||||||
}
|
}
|
||||||
s_log_tags_tail = NULL;
|
|
||||||
s_log_tags_head = NULL;
|
|
||||||
s_log_cache_entry_count = 0;
|
s_log_cache_entry_count = 0;
|
||||||
s_log_cache_max_generation = 0;
|
s_log_cache_max_generation = 0;
|
||||||
#ifdef LOG_BUILTIN_CHECKS
|
#ifdef LOG_BUILTIN_CHECKS
|
||||||
s_log_cache_misses = 0;
|
s_log_cache_misses = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR esp_log_write(esp_log_level_t level,
|
void IRAM_ATTR esp_log_write(esp_log_level_t level,
|
||||||
|
@ -253,7 +241,8 @@ static inline bool get_uncached_log_level(const char* tag, esp_log_level_t* leve
|
||||||
{
|
{
|
||||||
// Walk the linked list of all tags and see if given tag is present in the list.
|
// Walk the linked list of all tags and see if given tag is present in the list.
|
||||||
// This is slow because tags are compared as strings.
|
// This is slow because tags are compared as strings.
|
||||||
for (uncached_tag_entry_t* it = s_log_tags_head; it != NULL; it = it->next) {
|
uncached_tag_entry_t *it;
|
||||||
|
SLIST_FOREACH( it, &s_log_tags, entries ) {
|
||||||
if (strcmp(tag, it->tag) == 0) {
|
if (strcmp(tag, it->tag) == 0) {
|
||||||
*level = it->level;
|
*level = it->level;
|
||||||
return true;
|
return true;
|
||||||
|
|
Ładowanie…
Reference in New Issue