Merge pull request #1942 from armink/add_ulog
[component][ulog] Reduce thread stack usage when using ulog.
This commit is contained in:
commit
60ba1e935f
|
@ -162,7 +162,7 @@ config RT_USING_ULOG
|
||||||
|
|
||||||
menu "log format"
|
menu "log format"
|
||||||
config ULOG_OUTPUT_FLOAT
|
config ULOG_OUTPUT_FLOAT
|
||||||
bool "Enable float number support."
|
bool "Enable float number support. It will using more thread stack."
|
||||||
select RT_USING_LIBC
|
select RT_USING_LIBC
|
||||||
default n
|
default n
|
||||||
help
|
help
|
||||||
|
|
|
@ -170,6 +170,26 @@ size_t ulog_strcpy(size_t cur_len, char *dst, const char *src)
|
||||||
return src - src_old;
|
return src - src_old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t ulog_ultoa(char *s, unsigned long int n)
|
||||||
|
{
|
||||||
|
size_t i = 0, j = 0, len = 0;
|
||||||
|
char swap;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
s[len++] = n % 10 + '0';
|
||||||
|
} while (n /= 10);
|
||||||
|
s[len] = '\0';
|
||||||
|
/* reverse string */
|
||||||
|
for (i = 0, j = len - 1; i < j; ++i, --j)
|
||||||
|
{
|
||||||
|
swap = s[i];
|
||||||
|
s[i] = s[j];
|
||||||
|
s[j] = swap;
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
static void output_unlock(void)
|
static void output_unlock(void)
|
||||||
{
|
{
|
||||||
/* is in thread context */
|
/* is in thread context */
|
||||||
|
@ -221,14 +241,18 @@ static char *get_log_buf(void)
|
||||||
RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *tag, rt_bool_t newline,
|
RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *tag, rt_bool_t newline,
|
||||||
const char *format, va_list args)
|
const char *format, va_list args)
|
||||||
{
|
{
|
||||||
rt_size_t log_len = 0, newline_len = rt_strlen(ULOG_NEWLINE_SIGN);
|
/* the caller has locker, so it can use static variable for reduce stack usage */
|
||||||
int fmt_result;
|
static rt_size_t log_len, newline_len;
|
||||||
|
static int fmt_result;
|
||||||
|
|
||||||
RT_ASSERT(log_buf);
|
RT_ASSERT(log_buf);
|
||||||
RT_ASSERT(level <= LOG_LVL_DBG);
|
RT_ASSERT(level <= LOG_LVL_DBG);
|
||||||
RT_ASSERT(tag);
|
RT_ASSERT(tag);
|
||||||
RT_ASSERT(format);
|
RT_ASSERT(format);
|
||||||
|
|
||||||
|
log_len = 0;
|
||||||
|
newline_len = rt_strlen(ULOG_NEWLINE_SIGN);
|
||||||
|
|
||||||
#ifdef ULOG_USING_COLOR
|
#ifdef ULOG_USING_COLOR
|
||||||
/* add CSI start sign and color info */
|
/* add CSI start sign and color info */
|
||||||
if (color_output_info[level])
|
if (color_output_info[level])
|
||||||
|
@ -242,9 +266,10 @@ RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *ta
|
||||||
/* add time info */
|
/* add time info */
|
||||||
{
|
{
|
||||||
#ifdef ULOG_TIME_USING_TIMESTAMP
|
#ifdef ULOG_TIME_USING_TIMESTAMP
|
||||||
time_t now = time(NULL);
|
static time_t now;
|
||||||
struct tm *tm, tm_tmp;
|
static struct tm *tm, tm_tmp;
|
||||||
|
|
||||||
|
now = time(NULL);
|
||||||
tm = gmtime_r(&now, &tm_tmp);
|
tm = gmtime_r(&now, &tm_tmp);
|
||||||
|
|
||||||
#ifdef RT_USING_SOFT_RTC
|
#ifdef RT_USING_SOFT_RTC
|
||||||
|
@ -256,7 +281,12 @@ RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *ta
|
||||||
#endif /* RT_USING_SOFT_RTC */
|
#endif /* RT_USING_SOFT_RTC */
|
||||||
|
|
||||||
#else
|
#else
|
||||||
rt_snprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, "[%d]", rt_tick_get());
|
static rt_size_t tick_len = 0;
|
||||||
|
|
||||||
|
log_buf[log_len] = '[';
|
||||||
|
tick_len = ulog_ultoa(log_buf + log_len + 1, rt_tick_get());
|
||||||
|
log_buf[log_len + 1 + tick_len] = ']';
|
||||||
|
log_buf[log_len + 1 + tick_len + 1] = '\0';
|
||||||
#endif /* ULOG_TIME_USING_TIMESTAMP */
|
#endif /* ULOG_TIME_USING_TIMESTAMP */
|
||||||
|
|
||||||
log_len += rt_strlen(log_buf + log_len);
|
log_len += rt_strlen(log_buf + log_len);
|
||||||
|
@ -988,6 +1018,11 @@ rt_err_t ulog_backend_unregister(ulog_backend_t backend)
|
||||||
RT_ASSERT(backend);
|
RT_ASSERT(backend);
|
||||||
RT_ASSERT(ulog.init_ok);
|
RT_ASSERT(ulog.init_ok);
|
||||||
|
|
||||||
|
if (backend->deinit)
|
||||||
|
{
|
||||||
|
backend->deinit(backend);
|
||||||
|
}
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
rt_slist_remove(&ulog.backend_list, &backend->list);
|
rt_slist_remove(&ulog.backend_list, &backend->list);
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
|
@ -82,7 +82,7 @@ void ulog_async_waiting_log(rt_int32_t time);
|
||||||
void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_size_t size);
|
void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_size_t size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another log output API. This API is difficult to use than LOG_X API.
|
* Another log output API. This API is more difficult to use than LOG_X API.
|
||||||
*/
|
*/
|
||||||
void ulog_voutput(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, va_list args);
|
void ulog_voutput(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, va_list args);
|
||||||
void ulog_output(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, ...);
|
void ulog_output(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, ...);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2018-08-25 armink the first version
|
* 2018-08-25 armink the first version
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _ULOG_DEF_H_
|
#ifndef _ULOG_DEF_H_
|
||||||
#define _ULOG_DEF_H_
|
#define _ULOG_DEF_H_
|
||||||
|
|
||||||
|
@ -63,9 +64,9 @@ extern "C" {
|
||||||
#if !defined(LOG_LVL)
|
#if !defined(LOG_LVL)
|
||||||
/* compatible for rtdbg */
|
/* compatible for rtdbg */
|
||||||
#if defined(DBG_LEVEL)
|
#if defined(DBG_LEVEL)
|
||||||
#define LOG_LVL DBG_LEVEL
|
#define LOG_LVL DBG_LEVEL
|
||||||
#else
|
#else
|
||||||
#define LOG_LVL LOG_LVL_DBG
|
#define LOG_LVL LOG_LVL_DBG
|
||||||
#endif
|
#endif
|
||||||
#endif /* !defined(LOG_LVL) */
|
#endif /* !defined(LOG_LVL) */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue