[Asterisk-code-review] scope_trace: Updated macro stubs to match other branches (asterisk[13])

George Joseph asteriskteam at digium.com
Thu Aug 20 09:09:02 CDT 2020


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/14801 )


Change subject: scope_trace: Updated macro stubs to match other branches
......................................................................

scope_trace: Updated macro stubs to match other branches

Although scope tracing isn't actually implemented in this branch,
macro stubs had been added to allow code that used scope tracing
to be cherry-picked to this branch without modification.

To match the other branches, the following changes were made
to the stubs...

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: Ifc281793a5b91c84a4f1633db9d07006d31585ed
---
M include/asterisk/logger.h
1 file changed, 70 insertions(+), 11 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/01/14801/1

diff --git a/include/asterisk/logger.h b/include/asterisk/logger.h
index f3cefd3..42348cb 100644
--- a/include/asterisk/logger.h
+++ b/include/asterisk/logger.h
@@ -599,24 +599,83 @@
 };
 
 /*
- * The "#if 1" keeps the last few lines of scope tracing
+ * The "#if 0" keeps the last few lines of scope tracing
  * common to all branches.
  */
-#if 1
-#define ast_trace_raw(__level, __indent_type, ...)
-#define ast_trace(__level, ...)
+#if 0
+
+#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_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
+
+#define SCOPE_ENTER(level, ...) \
+	int __scope_level = level; \
+	ast_debug(level, " " __VA_ARGS__)
+
+#define SCOPE_ENTER_TASK(level, indent, ...) \
+	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/+/14801
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Ifc281793a5b91c84a4f1633db9d07006d31585ed
Gerrit-Change-Number: 14801
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/3f20ef7f/attachment-0001.html>


More information about the asterisk-code-review mailing list