#include #include #include #include #include #include struct _MonoProfiler { MonoProfileFlags flags; }; static MonoProfiler *profiler; static void method_jit_result (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo, int result) { if (result == MONO_PROFILE_OK) { MonoClass *klass = mono_method_get_class (method); char *signature = mono_signature_get_desc (mono_method_signature (method), TRUE); 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); gpointer code_start = mono_jit_info_get_code_start (jinfo); int code_size = mono_jit_info_get_code_size (jinfo); if (op_write_native_code (name, code_start, code_size)) { g_warning ("Problem calling op_write_native_code\n"); } g_free (signature); g_free (name); } } static void profiler_shutdown (MonoProfiler *prof) { mono_profiler_set_events (0); g_free (profiler); profiler = NULL; op_close_agent (); } void mono_profiler_startup (const char *desc) { profiler = g_new0 (MonoProfiler, 1); profiler->flags |= MONO_PROFILE_JIT_COMPILATION; if (op_open_agent ()) { g_error ("Problem calling op_open_agent\n"); } mono_profiler_install (profiler, profiler_shutdown); mono_profiler_install_jit_end (method_jit_result); mono_profiler_set_events (profiler->flags); }