[Spice-commits] 3 commits - common/log.c

Frediano Ziglio fziglio at kemper.freedesktop.org
Wed May 31 09:21:50 UTC 2017


 common/log.c |   28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

New commits:
commit 564635e3c1a53390c9748bfb70d4129b411820e7
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Wed May 31 08:52:03 2017 +0100

    log: Check log level from spice_logv
    
    This was suggested by Christophe de Dinechin as an optimisation.
    Most of the messages won't be processed for formatting.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/log.c b/common/log.c
index dae955a..bab1afa 100644
--- a/common/log.c
+++ b/common/log.c
@@ -153,6 +153,11 @@ static void spice_logv(const char *log_domain,
                        va_list args)
 {
     GString *log_msg;
+    GLogLevelFlags glib_level = spice_log_level_to_glib(log_level);
+
+    if ((glib_level & G_LOG_LEVEL_MASK) > glib_debug_level) {
+            return; // do not print anything
+    }
 
     log_msg = g_string_new(NULL);
     if (strloc && function) {
@@ -161,7 +166,7 @@ static void spice_logv(const char *log_domain,
     if (format) {
         g_string_append_vprintf(log_msg, format, args);
     }
-    g_log(log_domain, spice_log_level_to_glib(log_level), "%s", log_msg->str);
+    g_log(log_domain, glib_level, "%s", log_msg->str);
     g_string_free(log_msg, TRUE);
 
     if (abort_level != -1 && abort_level >= (int) log_level) {
commit a60707788360df88c65b33b27091220750ef4e7a
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Wed May 31 08:49:19 2017 +0100

    log: Optimise glib_debug_level check
    
    Use INT_MAX for invalid value to remove a test in code.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/log.c b/common/log.c
index 014b416..dae955a 100644
--- a/common/log.c
+++ b/common/log.c
@@ -30,7 +30,7 @@
 #include "log.h"
 #include "backtrace.h"
 
-static int glib_debug_level = 0;
+static int glib_debug_level = INT_MAX;
 static int abort_level = -1;
 
 #ifndef SPICE_ABORT_LEVEL_DEFAULT
@@ -58,7 +58,7 @@ static GLogLevelFlags spice_log_level_to_glib(SpiceLogLevel level)
 
 static void spice_log_set_debug_level(void)
 {
-    if (glib_debug_level == 0) {
+    if (glib_debug_level == INT_MAX) {
         const char *debug_str = g_getenv("SPICE_DEBUG_LEVEL");
         if (debug_str != NULL) {
             int debug_level;
@@ -121,9 +121,8 @@ static void spice_logger(const gchar *log_domain,
                          const gchar *message,
                          gpointer user_data G_GNUC_UNUSED)
 {
-    if (glib_debug_level != 0) {
-        if ((log_level & G_LOG_LEVEL_MASK) > glib_debug_level)
-            return; // do not print anything
+    if ((log_level & G_LOG_LEVEL_MASK) > glib_debug_level) {
+        return; // do not print anything
     }
     g_log_default_handler(log_domain, log_level, message, NULL);
 }
commit f4a4d527026a9e952b71d2f1a94a2ca26bb95a3e
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Wed May 31 08:47:15 2017 +0100

    log: Do not check impossible function return
    
    spice_log_level_to_glib never returns 0 so don't check
    for this value.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/log.c b/common/log.c
index 28f518b..014b416 100644
--- a/common/log.c
+++ b/common/log.c
@@ -104,14 +104,12 @@ static void spice_log_set_abort_level(void)
             g_warning("Setting SPICE_ABORT_LEVEL is deprecated, use G_DEBUG instead");
             abort_level = atoi(abort_str);
             glib_abort_level = spice_log_level_to_glib(abort_level);
-            if (glib_abort_level != 0) {
-                unsigned int fatal_mask = G_LOG_FATAL_MASK;
-                while (glib_abort_level >= G_LOG_LEVEL_ERROR) {
-                    fatal_mask |= glib_abort_level;
-                    glib_abort_level >>= 1;
-                }
-                g_log_set_fatal_mask(SPICE_LOG_DOMAIN, fatal_mask);
+            unsigned int fatal_mask = G_LOG_FATAL_MASK;
+            while (glib_abort_level >= G_LOG_LEVEL_ERROR) {
+                fatal_mask |= glib_abort_level;
+                glib_abort_level >>= 1;
             }
+            g_log_set_fatal_mask(SPICE_LOG_DOMAIN, fatal_mask);
         } else {
             abort_level = SPICE_ABORT_LEVEL_DEFAULT;
         }
@@ -157,8 +155,6 @@ static void spice_logv(const char *log_domain,
 {
     GString *log_msg;
 
-    g_return_if_fail(spice_log_level_to_glib(log_level) != 0);
-
     log_msg = g_string_new(NULL);
     if (strloc && function) {
         g_string_append_printf(log_msg, "%s:%s: ", strloc, function);


More information about the Spice-commits mailing list