In mono_thread_info_suspend_lock in non-coop, don't assert MonoThreadInfo* is non...
[mono.git] / mono / profiler / mono-profiler-vtune.c
index dafd100acccb3d1361ec5fbe75f68af16a978d09..2ed52c541fda284f3e81b05fa0e6f81dde8a3e6c 100644 (file)
 #include <mono/metadata/debug-helpers.h>
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/mono-debug.h>
-#include <mono/metadata/debug-mono-symfile.h>
+#include <mono/metadata/debug-internals.h>
 #include <string.h>
 #include <glib.h>
 
 #define bool char
 
-#include "jitprofiling.h"
+#include <jitprofiling.h>
+
+static const char*
+code_buffer_desc (MonoProfilerCodeBufferType type)
+{
+       switch (type) {
+       case MONO_PROFILER_CODE_BUFFER_METHOD:
+               return "code_buffer_method";
+       case MONO_PROFILER_CODE_BUFFER_METHOD_TRAMPOLINE:
+               return "code_buffer_method_trampoline";
+       case MONO_PROFILER_CODE_BUFFER_UNBOX_TRAMPOLINE:
+               return "code_buffer_unbox_trampoline";
+       case MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE:
+               return "code_buffer_imt_trampoline";
+       case MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE:
+               return "code_buffer_generics_trampoline";
+       case MONO_PROFILER_CODE_BUFFER_SPECIFIC_TRAMPOLINE:
+               return "code_buffer_specific_trampoline";
+       case MONO_PROFILER_CODE_BUFFER_HELPER:
+               return "code_buffer_misc_helper";
+       case MONO_PROFILER_CODE_BUFFER_MONITOR:
+               return "code_buffer_monitor";
+       case MONO_PROFILER_CODE_BUFFER_DELEGATE_INVOKE:
+               return "code_buffer_delegate_invoke";
+       case MONO_PROFILER_CODE_BUFFER_EXCEPTION_HANDLING:
+               return "code_buffer_exception_handling";
+       default:
+               return "unspecified";
+       }
+}
 
 /* called at the end of the program */
 static void
@@ -51,7 +80,6 @@ method_jit_result (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo, i
        if (result == MONO_PROFILE_OK) {
                int i;
                MonoDebugSourceLocation *sourceLoc;
-               MonoDebugMethodInfo *methodDebugInfo;
                MonoDebugMethodJitInfo *dmji;
                MonoClass *klass = mono_method_get_class (method);
                char *signature = mono_signature_get_desc (mono_method_signature (method), TRUE);
@@ -81,7 +109,7 @@ method_jit_result (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo, i
                                sourceLoc = mono_debug_lookup_source_location (method, dmji->line_numbers[i].native_offset, mono_domain_get());
                                if (sourceLoc == NULL)
                                {
-                                       free(vtuneMethod.line_number_table);
+                                       g_free (vtuneMethod.line_number_table);
                                        vtuneMethod.line_number_table = NULL;
                                        vtuneMethod.line_number_size = 0;
                                        break;
@@ -98,9 +126,9 @@ method_jit_result (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo, i
                iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, &vtuneMethod);
 
                if (vtuneMethod.source_file_name != NULL)
-                       free(vtuneMethod.source_file_name);
+                       g_free (vtuneMethod.source_file_name);
                if (vtuneMethod.line_number_table != NULL)
-                       free(vtuneMethod.line_number_table);
+                       g_free (vtuneMethod.line_number_table);
        
                g_free (signature);
                g_free (name);
@@ -108,6 +136,30 @@ method_jit_result (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo, i
        }
 }
 
+static void
+code_buffer_new (MonoProfiler *prof, void *buffer, int size, MonoProfilerCodeBufferType type, void *data)
+{
+       char *name;
+       iJIT_Method_Load vtuneMethod;
+
+       if (type == MONO_PROFILER_CODE_BUFFER_SPECIFIC_TRAMPOLINE)
+               name = g_strdup_printf ("code_buffer_specific_trampoline_%s", (char*) data);
+       else
+               name = (char*) code_buffer_desc (type);
+
+       memset (&vtuneMethod, 0, sizeof (vtuneMethod));
+       vtuneMethod.method_id = iJIT_GetNewMethodID ();
+       vtuneMethod.method_name = name;
+       vtuneMethod.method_load_address = buffer;
+       vtuneMethod.method_size = size;
+
+       iJIT_NotifyEvent (iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, &vtuneMethod);
+
+       if (type == MONO_PROFILER_CODE_BUFFER_SPECIFIC_TRAMPOLINE) {
+               g_free (name);
+       }
+}
+
 /* the entry point */
 void
 mono_profiler_startup (const char *desc)
@@ -117,6 +169,7 @@ mono_profiler_startup (const char *desc)
        {
                mono_profiler_install (NULL, codeanalyst_shutdown);
                mono_profiler_install_jit_end (method_jit_result);
+               mono_profiler_install_code_buffer_new (code_buffer_new);
                mono_profiler_set_events (MONO_PROFILE_JIT_COMPILATION);
        }
 }