Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 97e2975

Browse files
committed
[common] Make FTRACE a reusable feature in zjs_common.h
Signed-off-by: Geoff Gustafson <[email protected]>
1 parent 74a79d8 commit 97e2975

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/zjs_common.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@ int zjs_get_ms(void);
6868
#define ZJS_ASSERT(condition, str) do {} while (0)
6969
#endif
7070

71+
/**
72+
* file-specific function tracing for debug purposes
73+
*
74+
* Displays short thread id, a file-specific prefix, and the function name,
75+
* followed by a formatted string intended to display arguments
76+
*
77+
* Use by defining USE_FTRACE and ftrace_prefix string in a file (see zjs_net.c)
78+
*
79+
* FTRACE takes format string and arguments like printf
80+
* FTRACE_JSAPI takes not arguments and expects to run in a ZJS_DECL_FUNC API
81+
*/
82+
#ifdef USE_FTRACE
83+
#define FTRACE \
84+
ZJS_PRINT("[%x] %s: %s: ", (u32_t)k_current_get() & 0xffff, \
85+
FTRACE_PREFIX, __func__); \
86+
ZJS_PRINT
87+
#define FTRACE_JSAPI \
88+
ZJS_PRINT("[%x] %s: %s: func = %p, this = %p, argc = %d\n", \
89+
(u32_t)k_current_get() & 0xffff, FTRACE_PREFIX, \
90+
__func__, (void *)function_obj, (void *)this, \
91+
(u32_t)argc)
92+
#else
93+
#define FTRACE(fmt...) do {} while (0)
94+
#define FTRACE_JSAPI do {} while (0)
95+
#endif
96+
7197
// TODO: We should instead have a macro that changes in debug vs. release build,
7298
// to save string space and instead print error codes or something for release.
7399

src/zjs_net.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// Copyright (c) 2017, Intel Corporation.
22
#ifdef BUILD_MODULE_NET
33

4+
// enable to use function tracing for debug purposes
5+
#if 0
6+
#define USE_FTRACE
7+
static char FTRACE_PREFIX[] = "net";
8+
#endif
9+
410
// C includes
511
#include <errno.h>
612

@@ -21,21 +27,6 @@
2127
#include "zjs_net_config.h"
2228
#include "zjs_util.h"
2329

24-
// file-specific function tracing for debug purposes
25-
#if 0
26-
#define FTRACE \
27-
ZJS_PRINT("[%x] net: %s: ", (u32_t)k_current_get() & 0xffff, \
28-
__func__); \
29-
ZJS_PRINT
30-
#define FTRACE_JSAPI \
31-
ZJS_PRINT("[%x] net: %s: func = %p, this = %p, argc = %d\n", \
32-
(u32_t)k_current_get() & 0xffff, __func__, \
33-
(void *)function_obj, (void *)this, (u32_t)argc)
34-
#else
35-
#define FTRACE(fmt...) do {} while (0)
36-
#define FTRACE_JSAPI do {} while (0)
37-
#endif
38-
3930
/**
4031
* Net module
4132
* @module net

0 commit comments

Comments
 (0)