diff options
author | Geoff Gustafson <geoff@linux.intel.com> | 2017-09-08 11:04:41 -0700 |
---|---|---|
committer | Geoff Gustafson <geoff@linux.intel.com> | 2017-09-11 16:13:23 -0700 |
commit | 97e29758f0551370dd6e1af83183d50ec832f51d (patch) | |
tree | aa6c195db0deb504d0df9f4aaa78642137384ee5 | |
parent | 74a79d84cab020cea907d0044bb09da8f94dbc1b (diff) |
[common] Make FTRACE a reusable feature in zjs_common.h
Signed-off-by: Geoff Gustafson <geoff@linux.intel.com>
-rw-r--r-- | src/zjs_common.h | 26 | ||||
-rw-r--r-- | src/zjs_net.c | 21 |
2 files changed, 32 insertions, 15 deletions
diff --git a/src/zjs_common.h b/src/zjs_common.h index d91d101..0a7f574 100644 --- a/src/zjs_common.h +++ b/src/zjs_common.h @@ -68,6 +68,32 @@ int zjs_get_ms(void); #define ZJS_ASSERT(condition, str) do {} while (0) #endif +/** + * file-specific function tracing for debug purposes + * + * Displays short thread id, a file-specific prefix, and the function name, + * followed by a formatted string intended to display arguments + * + * Use by defining USE_FTRACE and ftrace_prefix string in a file (see zjs_net.c) + * + * FTRACE takes format string and arguments like printf + * FTRACE_JSAPI takes not arguments and expects to run in a ZJS_DECL_FUNC API + */ +#ifdef USE_FTRACE +#define FTRACE \ + ZJS_PRINT("[%x] %s: %s: ", (u32_t)k_current_get() & 0xffff, \ + FTRACE_PREFIX, __func__); \ + ZJS_PRINT +#define FTRACE_JSAPI \ + ZJS_PRINT("[%x] %s: %s: func = %p, this = %p, argc = %d\n", \ + (u32_t)k_current_get() & 0xffff, FTRACE_PREFIX, \ + __func__, (void *)function_obj, (void *)this, \ + (u32_t)argc) +#else +#define FTRACE(fmt...) do {} while (0) +#define FTRACE_JSAPI do {} while (0) +#endif + // TODO: We should instead have a macro that changes in debug vs. release build, // to save string space and instead print error codes or something for release. diff --git a/src/zjs_net.c b/src/zjs_net.c index 8a94cc5..2c944d4 100644 --- a/src/zjs_net.c +++ b/src/zjs_net.c @@ -1,6 +1,12 @@ // Copyright (c) 2017, Intel Corporation. #ifdef BUILD_MODULE_NET +// enable to use function tracing for debug purposes +#if 0 +#define USE_FTRACE +static char FTRACE_PREFIX[] = "net"; +#endif + // C includes #include <errno.h> @@ -21,21 +27,6 @@ #include "zjs_net_config.h" #include "zjs_util.h" -// file-specific function tracing for debug purposes -#if 0 -#define FTRACE \ - ZJS_PRINT("[%x] net: %s: ", (u32_t)k_current_get() & 0xffff, \ - __func__); \ - ZJS_PRINT -#define FTRACE_JSAPI \ - ZJS_PRINT("[%x] net: %s: func = %p, this = %p, argc = %d\n", \ - (u32_t)k_current_get() & 0xffff, __func__, \ - (void *)function_obj, (void *)this, (u32_t)argc) -#else -#define FTRACE(fmt...) do {} while (0) -#define FTRACE_JSAPI do {} while (0) -#endif - /** * Net module * @module net |