2 * mono-codeanalyst.c: AMD CodeAnalyst profiler
5 * Jonathan Chambers (joncham@gmail.com)
7 * (C) 2011 Jonathan Chambers
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:
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
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.
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>
38 #include "CAJITNTFLib.h"
40 /* called at the end of the program */
42 codeanalyst_shutdown (MonoProfiler *prof)
44 CAJIT_CompleteJITLog ();
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);
57 name_utf16 = g_utf8_to_utf16 (name, strlen (name), NULL, NULL, NULL);
59 CAJIT_LogJITCode ((uintptr_t)code_start, code_size, (wchar_t*)name_utf16);
68 mono_profiler_startup (const char *desc);
72 mono_profiler_startup (const char *desc)
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);