[eglib] Prefer <langinfo.h> to <localcharset.h>
[mono.git] / mono / profiler / mono-codeanalyst.c
1 /*
2  * mono-codeanalyst.c: AMD CodeAnalyst profiler
3  *
4  * Author:
5  *   Jonathan Chambers (joncham@gmail.com)
6  *
7  * (C) 2011 Jonathan Chambers
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28 #include <mono/metadata/profiler.h>
29 #include <mono/metadata/tokentype.h>
30 #include <mono/metadata/tabledefs.h>
31 #include <mono/metadata/debug-helpers.h>
32 #include <mono/metadata/assembly.h>
33 #include <string.h>
34 #include <glib.h>
35
36 #define bool char
37
38 #include "CAJITNTFLib.h"
39
40 /* called at the end of the program */
41 static void
42 codeanalyst_shutdown (MonoProfiler *prof)
43 {
44         CAJIT_CompleteJITLog ();
45 }
46
47 static void
48 method_jit_result (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo, int result) {
49         if (result == MONO_PROFILE_OK) {
50                 gunichar2* name_utf16;
51                 MonoClass *klass = mono_method_get_class (method);
52                 char *signature = mono_signature_get_desc (mono_method_signature (method), TRUE);
53                 char *name = g_strdup_printf ("%s.%s.%s (%s)", mono_class_get_namespace (klass), mono_class_get_name (klass), mono_method_get_name (method), signature);
54                 gpointer code_start = mono_jit_info_get_code_start (jinfo);
55                 int code_size = mono_jit_info_get_code_size (jinfo);
56                 
57                 name_utf16 = g_utf8_to_utf16 (name, strlen (name), NULL, NULL, NULL);
58                 
59                 CAJIT_LogJITCode ((uintptr_t)code_start, code_size, (wchar_t*)name_utf16);
60                 
61                 g_free (signature);
62                 g_free (name);
63                 g_free (name_utf16);
64         }
65 }
66
67 void
68 mono_profiler_startup (const char *desc);
69
70 /* the entry point */
71 void
72 mono_profiler_startup (const char *desc)
73 {
74         CAJIT_Initialize ();
75
76         mono_profiler_install (NULL, codeanalyst_shutdown);
77         mono_profiler_install_jit_end (method_jit_result);
78         mono_profiler_set_events (MONO_PROFILE_JIT_COMPILATION);
79 }
80
81