logging: add a LOG_TCG_WARN for temp leaks
RFC PATCH 1/1 logging: add a LOG_TCG_WARN for temp leaks
Pretty much all calls to qemu_log are either wrapped in some other enabling check or only enabled with debug defines. Add a specific flag for TCG warnings and expand the documentation of the qemu_log function.
--- include/qemu/log-for-trace.h | 9 ++++++++- include/qemu/log.h | 2 ++ accel/tcg/translator.c | 4 ++-- util/log.c | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-)
include/qemu/log-for-trace.h +8 -1
@@ -29,7 +29,14 @@ static inline bool qemu_loglevel_mask(int mask) return (qemu_loglevel & mask) != 0; } -/* main logging function */ +/** +* qemu_log: main logging function +* +* Most users shouldn't be calling qemu_log unconditionally as it adds +* noise to logging output. Either use qemu_log_mask() or wrap +* successive log calls a qemu_loglevel_mask() check and +* qemu_log_lock/unlock(). The tracing infrastructure does similar wrapping. +*/ int GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); #endif
include/qemu/log.h +2 -0
@@ -64,6 +64,8 @@ static inline bool qemu_log_separate(void)#define CPU_LOG_PLUGIN (1 << 18)/* LOG_STRACE is used for user-mode strace logging. */ #define LOG_STRACE (1 << 19) +/* Additional TCG warnings */ +#define LOG_TCG_WARN (1 << 20)/* Lock output for a series of related logs. Since this is not needed * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we
accel/tcg/translator.c +2 -2
@@ -26,8 +26,8 @@void translator_loop_temp_check (DisasContextBase *db) {if (tcg_check_temp_count ()) { -qemu_log ("warning: TCG temporary leaks before " - TARGET_FMT_lx"\n" , db->pc_next); +qemu_log_mask (LOG_TCG_WARN ,"warning: TCG temporary leaks before " + TARGET_FMT_lx"\n" , db->pc_next); } }
util/log.c +2 -0
@@ -334,6 +334,8 @@ const QEMULogItem qemu_log_items[] = {#endif {LOG_STRACE ,"strace" , "log every user-mode syscall, its input, and its result" }, + { LOG_TCG_WARN, "tcg", + "log TCG warnings useful to developers." }, { 0, NULL, NULL }, };
Signature · 1 line
2.20.1
Quoted 10 lines · Alex Bennée
Pretty much all calls to
qemu_logare either wrapped in some other enabling check or only enabled with debug defines. Add a specific flag for TCG warnings and expand the documentation of theqemu_logfunction.Signed-off-by Alex Bennée <[email protected]>Cc Peter Maydell <[email protected]>---
include/qemu/log-for-trace.h static inline bool qemu_loglevel_mask(int mask) · line 37
Quoted 7 lines
include/qemu/log-for-trace.h +6
-1-/* main logging function */ +/** +* qemu_log: main logging function +* +* Most users shouldn't be calling qemu_log unconditionally as it adds +* noise to logging output. Either use qemu_log_mask() or wrap +* successive log calls a qemu_loglevel_mask() check and
"inside a"
include/qemu/log.h static inline bool qemu_log_separate(void) · line 68
Quoted 6 lines
+ * qemu_log_lock/unlock(). The tracing infrastructure does similar wrapping.
+ */
intGCC_FMT_ATTR(1, 2)qemu_log(const char *fmt, ...);include/qemu/log.h +2
-0+/* Additional TCG warnings */ +#define LOG_TCG_WARN (1 << 20)
I don't object to the new log group in principle, but it has exactly one warning in it. I feel we'd be better to check for all the current places that use qemu_log not inside a loglevel_mask condition (or which use fprintf, if we still have those) and then see what the most reasonable categorization is.
thanks
-- PMM
Quoted 24 lines · Peter Maydell
Quoted 10 lines · Alex Bennée
Pretty much all calls to
qemu_logare either wrapped in some other enabling check or only enabled with debug defines. Add a specific flag for TCG warnings and expand the documentation of theqemu_logfunction.Signed-off-by Alex Bennée <[email protected]>Cc Peter Maydell <[email protected]>---
include/qemu/log-for-trace.h static inline bool qemu_loglevel_mask(int mask) · line 37
Quoted 7 lines
include/qemu/log-for-trace.h +6
-1-/* main logging function */ +/** +* qemu_log: main logging function +* +* Most users shouldn't be calling qemu_log unconditionally as it adds +* noise to logging output. Either use qemu_log_mask() or wrap +* successive log calls a qemu_loglevel_mask() check and "inside a"
Quoted 3 lines
+ * qemu_log_lock/unlock(). The tracing infrastructure does similar wrapping.
+ */
intGCC_FMT_ATTR(1, 2)qemu_log(const char *fmt, ...);
Quoted 8 lines
include/qemu/log.h static inline bool qemu_log_separate(void) · line 68
Quoted 2 lines
include/qemu/log.h +2
-0+/* Additional TCG warnings */ +#define LOG_TCG_WARN (1 << 20)I don't object to the new log group in principle, but it has exactly one warning in it. I feel we'd be better to check for all the current places that use
qemu_lognot inside aloglevel_maskcondition (or which use fprintf, if we still have those) and then see what the most reasonable categorization is.
I did a grep of qemu_log and fprintf cases in accel/tcg and tcg and this was the only one that wasn't:
- either wrapped by qemu_loglevel_mask()
- part of an abort/exit() path (which should arguably be converted to error_report/abort)
In the wider code most of the the qemu_logs() I found where in D() functions in the various device emulations.
Signature · 1 line
Alex Bennée
Quoted 52 lines · Alex Bennée
Pretty much all calls to
qemu_logare either wrapped in some other enabling check or only enabled with debug defines. Add a specific flag for TCG warnings and expand the documentation of theqemu_logfunction.Signed-off-by Alex Bennée <[email protected]>Cc Peter Maydell <[email protected]>--- include/qemu/log-for-trace.h | 9 ++++++++- include/qemu/log.h | 2 ++ accel/tcg/translator.c | 4 ++-- util/log.c | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-)include/qemu/log-for-trace.h +8
-1@@ -29,7 +29,14 @@ static inline bool qemu_loglevel_mask(int mask) return (qemu_loglevel & mask) != 0; } -/* main logging function */ +/** +* qemu_log: main logging function +* +* Most users shouldn't be calling qemu_log unconditionally as it adds +* noise to logging output. Either use qemu_log_mask() or wrap +* successive log calls a qemu_loglevel_mask() check and +* qemu_log_lock/unlock(). The tracing infrastructure does similar wrapping. +*/ int GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); #endifinclude/qemu/log.h +2
-0@@ -64,6 +64,8 @@ static inline bool qemu_log_separate(void)#define CPU_LOG_PLUGIN (1 << 18)/* LOG_STRACE is used for user-mode strace logging. */ #define LOG_STRACE (1 << 19) +/* Additional TCG warnings */ +#define LOG_TCG_WARN (1 << 20)/* Lock output for a series of related logs. Since this is not needed * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we accel/tcg/translator.c +0
-0
accel/tcg/translator.c line 30
Quoted 7 lines
accel/tcg/translator.c +2
-2@@ -26,8 +26,8 @@void translator_loop_temp_check (DisasContextBase *db) {if (tcg_check_temp_count ()) { -qemu_log ("warning: TCG temporary leaks before " - TARGET_FMT_lx"\n" , db->pc_next); +qemu_log_mask (LOG_TCG_WARN ,"warning: TCG temporary leaks before " + TARGET_FMT_lx"\n" , db->pc_next);
Why not replace by warn_report_once()?
Quoted 17 lines
accel/tcg/translator.c +0
-0} }util/log.c +2
-0@@ -334,6 +334,8 @@ const QEMULogItem qemu_log_items[] = {#endif {LOG_STRACE ,"strace" , "log every user-mode syscall, its input, and its result" }, + { LOG_TCG_WARN, "tcg", + "log TCG warnings useful to developers." }, { 0, NULL, NULL }, };