mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
mlearning/tflite-micro: add a config option to redirect micro log to syslog
new config option TFLITEMICRO_SYSLOG to redirect micro log to syslog Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
parent
37acd5e671
commit
9c5a2ad062
4 changed files with 99 additions and 0 deletions
|
|
@ -101,6 +101,10 @@ if(CONFIG_TFLITEMICRO)
|
|||
|
||||
# Remove test file
|
||||
list(FILTER TFLITE_MICRO_SRCS EXCLUDE REGEX ".*test.cc")
|
||||
if(CONFIG_TFLITEMICRO_SYSLOG)
|
||||
list(FILTER TFLITE_MICRO_SRCS EXCLUDE REGEX "micro_log.cc")
|
||||
list(APPEND TFLITE_MICRO_SRCS ${CMAKE_CURRENT_LIST_DIR}/tflm_syslog.cc)
|
||||
endif()
|
||||
|
||||
if(CONFIG_MLEARNING_CMSIS_NN)
|
||||
list(APPEND COMMON_FLAGS -DCMSIS_NN)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,30 @@ config TFLITEMICRO_TOOL
|
|||
bool "tflite-micro cmdline tool"
|
||||
default n
|
||||
|
||||
config TFLITEMICRO_SYSLOG
|
||||
bool "tflite-micro syslog backend"
|
||||
default n
|
||||
|
||||
if TFLITEMICRO_SYSLOG
|
||||
|
||||
config TFLITEMICRO_SYSLOG_LEVEL
|
||||
int "tflite-micro syslog level"
|
||||
default 6
|
||||
---help---
|
||||
Syslog level mapping of tflm, This log level mapping is consistent
|
||||
with the nuttx syslog level, please refer to syslog.h:
|
||||
|
||||
define LOG_EMERG 0 /* System is unusable */
|
||||
define LOG_ALERT 1 /* Action must be taken immediately */
|
||||
define LOG_CRIT 2 /* Critical conditions */
|
||||
define LOG_ERR 3 /* Error conditions */
|
||||
define LOG_WARNING 4 /* Warning conditions */
|
||||
define LOG_NOTICE 5 /* Normal, but significant, condition */
|
||||
define LOG_INFO 6 /* Informational message */
|
||||
define LOG_DEBUG 7 /* Debug-level message */
|
||||
|
||||
endif # TFLITEMICRO_SYSLOG
|
||||
|
||||
if TFLITEMICRO_TOOL
|
||||
config TFLITEMICRO_TOOL_PRIORITY
|
||||
int "tflite-micro tool priority"
|
||||
|
|
|
|||
|
|
@ -78,6 +78,11 @@ CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/micro/tflite_bridge/*.cc)
|
|||
CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/schema/*.cc)
|
||||
CXXSRCS := $(filter-out %test.cc, $(CXXSRCS))
|
||||
|
||||
ifneq ($(CONFIG_TFLITEMICRO_SYSLOG),)
|
||||
CXXSRCS := $(filter-out %micro_log.cc, $(CXXSRCS))
|
||||
CXXSRCS += $(wildcard $(CURDIR)/tflm_syslog.cc)
|
||||
endif
|
||||
|
||||
# cmsis
|
||||
ifneq ($(CONFIG_MLEARNING_CMSIS_NN),)
|
||||
COMMON_FLAGS += -DCMSIS_NN
|
||||
|
|
|
|||
66
mlearning/tflite-micro/tflm_syslog.cc
Normal file
66
mlearning/tflite-micro/tflm_syslog.cc
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/****************************************************************************
|
||||
* apps/mlearning/tflite-micro/tflm_syslog.cc
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "tensorflow/lite/micro/micro_log.h"
|
||||
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if !defined(TF_LITE_STRIP_ERROR_STRINGS)
|
||||
#include "tensorflow/lite/micro/debug_log.h"
|
||||
#endif
|
||||
|
||||
#if !defined(TF_LITE_STRIP_ERROR_STRINGS)
|
||||
|
||||
void VMicroPrintf(FAR const char *format, va_list ap)
|
||||
{
|
||||
vsyslog(CONFIG_TFLITEMICRO_SYSLOG_LEVEL, format, ap);
|
||||
}
|
||||
|
||||
void MicroPrintf(FAR const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
/* Let vsyslog do the work */
|
||||
|
||||
va_start(ap, format);
|
||||
vsyslog(CONFIG_TFLITEMICRO_SYSLOG_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
int MicroSnprintf(FAR char *buffer, size_t buf_size, FAR const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start(ap, format);
|
||||
ret = vsnprintf(buffer, buf_size, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int MicroVsnprintf(FAR char *buffer, size_t buf_size,
|
||||
FAR const char *format, va_list vlist)
|
||||
{
|
||||
return vsnprintf(buffer, buf_size, format, vlist);
|
||||
}
|
||||
|
||||
#endif // !defined(TF_LITE_STRIP_ERROR_STRINGS)
|
||||
Loading…
Add table
Add a link
Reference in a new issue