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

Commit

Permalink
[common] Make FTRACE a reusable feature in zjs_common.h
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Gustafson <geoff@linux.intel.com>
  • Loading branch information
grgustaf committed Sep 8, 2017
1 parent 56b3cd0 commit 193e87d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
26 changes: 26 additions & 0 deletions src/zjs_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
21 changes: 6 additions & 15 deletions src/zjs_net.c
Original file line number Diff line number Diff line change
@@ -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>

Expand All @@ -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
Expand Down

0 comments on commit 193e87d

Please sign in to comment.