summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonas Ã…dahl <jadahl@gmail.com>2020-10-02 19:30:58 +0200
committerverdre <jonas@dressler.it>2020-10-14 14:29:36 +0000
commit43c6f70605b3fb305210f4adf3ab89abd06b60ad (patch)
tree99b77c05aee1b7396881d3ee6daebf4153ece919 /src
parentf79d40077ecfe7b7f471a8d750f1e9ef65058e54 (diff)
downloadmutter-43c6f70605b3fb305210f4adf3ab89abd06b60ad.tar.gz
util: Don't expand meta_*() debug log arguments if topic not enabled
It's pointless to call into functions that produce information that will end up nowhere, so lets not. This will generate less angst when doing more intense data gathering and string generation in debug log calls. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1467
Diffstat (limited to 'src')
-rw-r--r--src/core/util.c16
-rw-r--r--src/meta/util.h20
2 files changed, 31 insertions, 5 deletions
diff --git a/src/core/util.c b/src/core/util.c
index 681529b16..0c9a31d82 100644
--- a/src/core/util.c
+++ b/src/core/util.c
@@ -285,6 +285,18 @@ topic_name (MetaDebugTopic topic)
static int sync_count = 0;
+gboolean
+meta_is_topic_enabled (MetaDebugTopic topic)
+{
+ if (verbose_topics == 0)
+ return FALSE;
+
+ if (topic == META_DEBUG_VERBOSE && verbose_topics != META_DEBUG_VERBOSE)
+ return FALSE;
+
+ return !!(verbose_topics & topic);
+}
+
static void
meta_topic_real_valist (MetaDebugTopic topic,
const char *format,
@@ -295,9 +307,7 @@ meta_topic_real_valist (MetaDebugTopic topic,
g_return_if_fail (format != NULL);
- if (verbose_topics == 0
- || (topic == META_DEBUG_VERBOSE && verbose_topics != META_DEBUG_VERBOSE)
- || (!(verbose_topics & topic)))
+ if (!meta_is_topic_enabled (topic))
return;
str = g_strdup_vprintf (format, args);
diff --git a/src/meta/util.h b/src/meta/util.h
index 6d06ea572..5fddf0873 100644
--- a/src/meta/util.h
+++ b/src/meta/util.h
@@ -113,6 +113,9 @@ typedef enum
} MetaDebugPaintFlag;
META_EXPORT
+gboolean meta_is_topic_enabled (MetaDebugTopic topic);
+
+META_EXPORT
void meta_topic_real (MetaDebugTopic topic,
const char *format,
...) G_GNUC_PRINTF (2, 3);
@@ -162,8 +165,21 @@ GPid meta_show_dialog (const char *type,
/* To disable verbose mode, we make these functions into no-ops */
#ifdef WITH_VERBOSE_MODE
-#define meta_verbose meta_verbose_real
-#define meta_topic meta_topic_real
+#define meta_verbose(...) \
+ G_STMT_START \
+ { \
+ if (meta_is_topic_enabled (META_DEBUG_VERBOSE)) \
+ meta_verbose_real (__VA_ARGS__); \
+ } \
+ G_STMT_END
+
+#define meta_topic(debug_topic,...) \
+ G_STMT_START \
+ { \
+ if (meta_is_topic_enabled (debug_topic)) \
+ meta_topic_real (debug_topic, __VA_ARGS__); \
+ } \
+ G_STMT_END
#else