[Asterisk-code-review] scope_trace: Added debug messages and added additional macros (asterisk[certified/16.8])
George Joseph
asteriskteam at digium.com
Thu Aug 20 08:39:29 CDT 2020
George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/14738 )
Change subject: scope_trace: Added debug messages and added additional macros
......................................................................
scope_trace: Added debug messages and added additional macros
The SCOPE_ENTER and SCOPE_EXIT* macros now print debug messages
at the same level as the scope level. This allows the same
messages to be printed to the debug log when AST_DEVMODE
isn't enabled.
Also added a few variants of the SCOPE_EXIT macros that will
also call ast_log instead of ast_debug to make it easier to
use scope tracing and still print error messages.
Change-Id: I7fe55f7ec28069919a0fc0b11a82235ce904cc21
---
M include/asterisk/logger.h
1 file changed, 75 insertions(+), 9 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/38/14738/1
diff --git a/include/asterisk/logger.h b/include/asterisk/logger.h
index 5514d83..43a9c01 100644
--- a/include/asterisk/logger.h
+++ b/include/asterisk/logger.h
@@ -662,6 +662,7 @@
*
*/
#define ast_trace_raw(level, indent_type, ...) \
+ ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
if (TRACE_ATLEAST(level)) { \
__ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, indent_type, 0, " " __VA_ARGS__); \
}
@@ -676,6 +677,7 @@
* This will print the file, line and function at the current indent level
*/
#define ast_trace(level, ...) \
+ ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
if (TRACE_ATLEAST(level)) { \
__ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_SAME, 0, " " __VA_ARGS__); \
}
@@ -765,6 +767,7 @@
#define SCOPE_ENTER(level, ...) \
int __scope_level = level; \
int __scope_task = 0; \
+ ast_debug(__scope_level, " " __VA_ARGS__); \
if (TRACE_ATLEAST(level)) { \
__ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_INC_AFTER, 0, " " __VA_ARGS__); \
} \
@@ -772,6 +775,7 @@
#define SCOPE_ENTER_TASK(level, indent, ...) \
int __scope_level = level; \
int __scope_task = 1; \
+ ast_debug(__scope_level, " " __VA_ARGS__); \
if (TRACE_ATLEAST(level)) { \
__ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_PROVIDED, indent, " " __VA_ARGS__); \
} \
@@ -786,6 +790,7 @@
* This macro can be used at the exit points of a statement block since it just prints the message.
*/
#define SCOPE_EXIT(...) \
+ ast_debug(__scope_level, " " __VA_ARGS__); \
if (TRACE_ATLEAST(__scope_level)) { \
__ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
if (__scope_task) { \
@@ -814,6 +819,7 @@
* }
*/
#define SCOPE_EXIT_EXPR(__expr, ...) \
+ ast_debug(__scope_level, " " __VA_ARGS__); \
if (TRACE_ATLEAST(__scope_level)) { \
__ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
if (__scope_task) { \
@@ -833,6 +839,7 @@
* needs to be returned.
*/
#define SCOPE_EXIT_RTN(...) \
+ ast_debug(__scope_level, " " __VA_ARGS__); \
if (TRACE_ATLEAST(__scope_level)) { \
__ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
if (__scope_task) { \
@@ -853,6 +860,7 @@
* needs to be returned.
*/
#define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \
+ ast_debug(__scope_level, " " __VA_ARGS__); \
if (TRACE_ATLEAST(__scope_level)) { \
__ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
if (__scope_task) { \
@@ -861,21 +869,79 @@
} \
return(__return_value)
-#else
-#define ast_trace_raw(__level, __indent_type, ...)
-#define ast_trace(__level, ...)
+#else /* AST_DEVMODE */
+#define ast_trace_raw(level, indent_type, ...) \
+ ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
+
+#define ast_trace(level, ...) \
+ ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
+
#define ast_trace_get_indent() (0)
#define ast_trace_set_indent(indent)
#define ast_trace_inc_indent()
#define ast_trace_dec_indent()
#define SCOPE_TRACE(__level, ...)
-#define SCOPE_ENTER(level, ...)
+
+#define SCOPE_ENTER(level, ...) \
+ int __scope_level = level; \
+ ast_debug(level, " " __VA_ARGS__);
+
#define SCOPE_ENTER_TASK(level, indent, ...)
-#define SCOPE_EXIT(...)
-#define SCOPE_EXIT_EXPR(__expr, ...) __expr
-#define SCOPE_EXIT_RTN(...) return
-#define SCOPE_EXIT_RTN_VALUE(__return_value, ...) return __return_value
-#endif
+ int __scope_level = level; \
+ ast_debug(level, " " __VA_ARGS__);
+
+#define SCOPE_EXIT(...) \
+ ast_debug(__scope_level, " " __VA_ARGS__);
+
+#define SCOPE_EXIT_EXPR(__expr, ...) \
+ ast_debug(__scope_level, " " __VA_ARGS__); \
+ __expr
+
+#define SCOPE_EXIT_RTN(...) \
+ ast_debug(__scope_level, " " __VA_ARGS__); \
+ return
+
+#define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \
+ ast_debug(__scope_level, " " __VA_ARGS__); \
+ return __return_value
+
+#endif /* AST_DEVMODE */
+
+/*!
+ * The following macros will print log messages before running
+ * the associated SCOPE_ macro.
+ */
+
+#define SCOPE_EXIT_LOG(__log_level, ...) \
+({ \
+ ast_log(__log_level, " " __VA_ARGS__); \
+ SCOPE_EXIT(" " __VA_ARGS__); \
+})
+
+#define SCOPE_EXIT_LOG_RTN(__log_level, ...) \
+({ \
+ ast_log(__log_level, " " __VA_ARGS__); \
+ SCOPE_EXIT_RTN(" " __VA_ARGS__); \
+})
+
+#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level, ...) \
+({ \
+ ast_log(__log_level, " " __VA_ARGS__); \
+ SCOPE_EXIT_RTN_VALUE(__value, " " __VA_ARGS__); \
+})
+
+#define SCOPE_EXIT_LOG_EXPR(__expr, __log_level, ...) \
+({ \
+ ast_log(__log_level, " " __VA_ARGS__); \
+ SCOPE_EXIT_EXPR(__expr, " " __VA_ARGS__); \
+})
+
+#define ast_trace_log(__level, __log_level, ...) \
+({ \
+ ast_log(__log_level, " " __VA_ARGS__); \
+ ast_trace(__level < 0 ? __scope_level : __level, " " __VA_ARGS__); \
+})
+
#if defined(__cplusplus) || defined(c_plusplus)
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14738
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: certified/16.8
Gerrit-Change-Id: I7fe55f7ec28069919a0fc0b11a82235ce904cc21
Gerrit-Change-Number: 14738
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200820/0c6c482a/attachment-0001.html>
More information about the asterisk-code-review
mailing list