aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/zjs_common.h26
-rw-r--r--src/zjs_net.c21
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