Move mono_trace to header file
authorMarek Habersack <grendel@twistedcode.net>
Mon, 18 Jan 2016 22:41:30 +0000 (23:41 +0100)
committerMarek Habersack <grendel@twistedcode.net>
Mon, 18 Jan 2016 23:35:03 +0000 (00:35 +0100)
This commit moves mono_trace to a header file so that all the
calls are inlined, avoiding one function call at the small expense
of binary size.

man/mono.1
mono/metadata/appdomain.c
mono/mini/driver.c
mono/utils/mono-logger-internals.h
mono/utils/mono-logger.c

index f4d71fadaebc4e0c0e7c6908b56825589b1696a2..51618f260cc8e9e1b5e23a82f796ab2830dff2d8 100644 (file)
@@ -888,7 +888,9 @@ environment variable to limit the extent of the messages you get:
 If set, the log mask is changed to the set value. Possible values are
 "asm" (assembly loader), "type", "dll" (native library loader), "gc"
 (garbage collector), "cfg" (config file loader), "aot" (precompiler),
-"security" (e.g. Moonlight CoreCLR support) and "all". 
+"security" (e.g. Moonlight CoreCLR support), "threadpool" (thread pool generic), 
+"io-threadpool" (thread pool I/O), "io-layer" (I/O layer - sockets, handles, shared memory etc) 
+and "all". 
 The default value is "all". Changing the mask value allows you to display only 
 messages for a certain component. You can use multiple masks by comma 
 separating them. For example to see config file messages and assembly loader
index d5cea26a9a751cb2cb6668e2b71a093d4f00402c..5cc6e7057d13bf633edae686c47336db41520da7 100644 (file)
@@ -278,7 +278,7 @@ mono_runtime_init (MonoDomain *domain, MonoThreadStartCB start_cb,
 
        /* mscorlib is loaded before we install the load hook */
        mono_domain_fire_assembly_load (mono_defaults.corlib->assembly, NULL);
-       
+
        return;
 }
 
index b5533d23980b7edb6305cba16d12c3bdc866aae3..c801bd9ed21d3244b451647ca88523541a1cc15d 100644 (file)
@@ -50,6 +50,7 @@
 #include <mono/metadata/attach.h>
 #include "mono/utils/mono-counters.h"
 #include "mono/utils/mono-hwcap.h"
+#include "mono/utils/mono-logger-internals.h"
 
 #include "mini.h"
 #include "jit.h"
@@ -1574,7 +1575,7 @@ mono_main (int argc, char* argv[])
 #if TARGET_OSX
        darwin_change_default_file_handles ();
 #endif
-       
+
        if (g_getenv ("MONO_NO_SMP"))
                mono_set_use_smp (FALSE);
        
index ee88665ae6c185ceaf09da5d3b9ba6edf887d5d6..89e9a01023ab32bf0a3738271aa6141b5a397f72 100644 (file)
@@ -16,6 +16,7 @@ typedef enum {
        MONO_TRACE_SECURITY             = (1<<6),
        MONO_TRACE_THREADPOOL           = (1<<7),
        MONO_TRACE_IO_THREADPOOL        = (1<<8),
+       MONO_TRACE_IO_LAYER             = (1<<9),
        MONO_TRACE_ALL                  = MONO_TRACE_ASSEMBLY |
                                          MONO_TRACE_TYPE |
                                          MONO_TRACE_DLLIMPORT |
@@ -24,17 +25,21 @@ typedef enum {
                                          MONO_TRACE_AOT |
                                          MONO_TRACE_SECURITY |
                                          MONO_TRACE_THREADPOOL |
-                                         MONO_TRACE_IO_THREADPOOL
+                                         MONO_TRACE_IO_THREADPOOL |
+                                         MONO_TRACE_IO_LAYER
 } MonoTraceMask;
 
+extern GLogLevelFlags mono_internal_current_level;
+extern MonoTraceMask mono_internal_current_mask;
+
 void 
-mono_trace_cleanup (void);
+mono_trace_init (void);
 
 void 
-mono_trace (GLogLevelFlags level, MonoTraceMask mask, const char *format, ...);
+mono_trace_cleanup (void);
 
 void 
-mono_tracev (GLogLevelFlags level, MonoTraceMask mask, const char *format, va_list args);
+mono_tracev_inner (GLogLevelFlags level, MonoTraceMask mask, const char *format, va_list args);
 
 void 
 mono_trace_set_level (GLogLevelFlags level);
@@ -51,6 +56,33 @@ mono_trace_pop (void);
 gboolean
 mono_trace_is_traced (GLogLevelFlags level, MonoTraceMask mask);
 
+G_GNUC_UNUSED static void
+mono_tracev (GLogLevelFlags level, MonoTraceMask mask, const char *format, va_list args)
+{
+       if(G_UNLIKELY (level <= mono_internal_current_level && mask & mono_internal_current_mask))
+               mono_tracev_inner (level, mask, format, args);
+}
+
+/**
+ * mono_trace:
+ *
+ *     @level: Verbose level of the specified message
+ *     @mask: Type of the specified message
+ *
+ * Traces a new message, depending on the current logging level
+ * and trace mask.
+ */
+G_GNUC_UNUSED static void
+mono_trace (GLogLevelFlags level, MonoTraceMask mask, const char *format, ...) 
+{
+       if(G_UNLIKELY (level <= mono_internal_current_level && mask & mono_internal_current_mask)) {
+               va_list args;
+               va_start (args, format);
+               mono_tracev_inner (level, mask, format, args);
+               va_end (args);
+       }
+}
+
 #ifdef G_HAVE_ISO_VARARGS
 #define mono_trace_error(...)  mono_trace(G_LOG_LEVEL_ERROR, \
                                                                                        __VA_ARGS__)
index 09d72dd2f008325724e2bf60c4d25b499a1eeed5..7d0c9ce12a4f811d33e6d5a3bca405b2f564da03 100644 (file)
@@ -11,11 +11,11 @@ typedef struct {
        MonoTraceMask   mask;
 } MonoLogLevelEntry;
 
-static GLogLevelFlags current_level            = G_LOG_LEVEL_ERROR;
-static MonoTraceMask current_mask              = MONO_TRACE_ALL;
+GLogLevelFlags mono_internal_current_level             = INT_MAX;
+MonoTraceMask  mono_internal_current_mask              = MONO_TRACE_ALL;
 
-static const char      *mono_log_domain        = "Mono";
 static GQueue          *level_stack            = NULL;
+static const char      *mono_log_domain        = "Mono";
 static MonoPrintCallback print_callback, printerr_callback;
 
 /**
@@ -23,10 +23,11 @@ static MonoPrintCallback print_callback, printerr_callback;
  *
  * Initializes the mono tracer.
  */
-static void 
+void 
 mono_trace_init (void)
 {
        if(level_stack == NULL) {
+               mono_internal_current_level = G_LOG_LEVEL_ERROR;
                level_stack = g_queue_new();
 
                mono_trace_set_mask_string(g_getenv("MONO_LOG_MASK"));
@@ -52,29 +53,6 @@ mono_trace_cleanup (void)
        }
 }
 
-/**
- * mono_trace:
- *
- *     @level: Verbose level of the specified message
- *     @mask: Type of the specified message
- *
- * Traces a new message, depending on the current logging level
- * and trace mask.
- */
-void
-mono_trace(GLogLevelFlags level, MonoTraceMask mask, const char *format, ...) 
-{
-       if(level_stack == NULL)
-               mono_trace_init();
-
-       if(level <= current_level && mask & current_mask) {
-               va_list args;
-               va_start (args, format);
-               g_logv (mono_log_domain, level, format, args);
-               va_end (args);
-       }
-}
-
 /**
  * mono_tracev:
  *
@@ -85,13 +63,15 @@ mono_trace(GLogLevelFlags level, MonoTraceMask mask, const char *format, ...)
  * and trace mask.
  */
 void 
-mono_tracev (GLogLevelFlags level, MonoTraceMask mask, const char *format, va_list args)
+mono_tracev_inner (GLogLevelFlags level, MonoTraceMask mask, const char *format, va_list args)
 {
-       if (level_stack == NULL)
+       if (level_stack == NULL) {
                mono_trace_init ();
+               if(level > mono_internal_current_level || !(mask & mono_internal_current_mask))
+                       return;
+       }
 
-       if(level <= current_level && mask & current_mask)
-               g_logv (mono_log_domain, level, format, args);
+       g_logv (mono_log_domain, level, format, args);
 }
 
 /**
@@ -109,7 +89,7 @@ mono_trace_set_level (GLogLevelFlags level)
        if(level_stack == NULL)
                mono_trace_init();
 
-       current_level = level;
+       mono_internal_current_level = level;
 }
 
 /**
@@ -127,7 +107,7 @@ mono_trace_set_mask (MonoTraceMask mask)
        if(level_stack == NULL)
                mono_trace_init();
 
-       current_mask    = mask;
+       mono_internal_current_mask      = mask;
 }
 
 /**
@@ -146,15 +126,15 @@ mono_trace_push (GLogLevelFlags level, MonoTraceMask mask)
                g_error("%s: cannot use mono_trace_push without calling mono_trace_init first.", __func__);
        else {
                MonoLogLevelEntry *entry = (MonoLogLevelEntry *) g_malloc(sizeof(MonoLogLevelEntry));
-               entry->level    = current_level;
-               entry->mask             = current_mask;
+               entry->level    = mono_internal_current_level;
+               entry->mask             = mono_internal_current_mask;
 
                g_queue_push_head (level_stack, (gpointer)entry);
 
                /* Set the new level and mask
                 */
-               current_level = level;
-               current_mask  = mask;
+               mono_internal_current_level = level;
+               mono_internal_current_mask  = mask;
        }
 }
 
@@ -174,8 +154,8 @@ mono_trace_pop (void)
 
                        /*      Restore previous level and mask
                         */
-                       current_level = entry->level;
-                       current_mask  = entry->mask;
+                       mono_internal_current_level = entry->level;
+                       mono_internal_current_mask  = entry->mask;
 
                        g_free (entry);
                }
@@ -213,10 +193,10 @@ mono_trace_set_mask_string (const char *value)
        const char *tok;
        guint32 flags = 0;
 
-       const char *valid_flags[] = {"asm", "type", "dll", "gc", "cfg", "aot", "security", "threadpool", "io-threadpool", "all", NULL};
+       const char *valid_flags[] = {"asm", "type", "dll", "gc", "cfg", "aot", "security", "threadpool", "io-threadpool", "io-layer", "all", NULL};
        const MonoTraceMask     valid_masks[] = {MONO_TRACE_ASSEMBLY, MONO_TRACE_TYPE, MONO_TRACE_DLLIMPORT,
                                                 MONO_TRACE_GC, MONO_TRACE_CONFIG, MONO_TRACE_AOT, MONO_TRACE_SECURITY,
-                                                MONO_TRACE_THREADPOOL, MONO_TRACE_IO_THREADPOOL, MONO_TRACE_ALL };
+                                                MONO_TRACE_THREADPOOL, MONO_TRACE_IO_THREADPOOL, MONO_TRACE_IO_LAYER, MONO_TRACE_ALL };
 
        if(!value)
                return;
@@ -253,7 +233,7 @@ mono_trace_set_mask_string (const char *value)
 gboolean
 mono_trace_is_traced (GLogLevelFlags level, MonoTraceMask mask)
 {
-       return (level <= current_level && mask & current_mask);
+       return (level <= mono_internal_current_level && mask & mono_internal_current_mask);
 }
 
 static MonoLogCallback log_callback;