2 * Licensed to the .NET Foundation under one or more agreements.
3 * The .NET Foundation licenses this file to you under the MIT license.
4 * See the LICENSE file in the project root for more information.
7 #include <mono/metadata/profiler-private.h>
10 * The point of this file is to maintain compatibility with a few profiler API
11 * functions used by Xamarin.{Android,iOS,Mac} so that they keep working
12 * regardless of which system Mono version is used.
14 * TODO: Remove this some day if we're OK with breaking compatibility.
17 typedef void *MonoLegacyProfiler;
19 typedef void (*MonoProfileFunc) (MonoLegacyProfiler *prof);
20 typedef void (*MonoProfileThreadFunc) (MonoLegacyProfiler *prof, uintptr_t tid);
21 typedef void (*MonoProfileGCFunc) (MonoLegacyProfiler *prof, MonoProfilerGCEvent event, int generation);
22 typedef void (*MonoProfileGCResizeFunc) (MonoLegacyProfiler *prof, int64_t new_size);
23 typedef void (*MonoProfileJitResult) (MonoLegacyProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo, int result);
25 struct _MonoProfiler {
26 MonoProfilerHandle handle;
27 MonoLegacyProfiler *profiler;
28 MonoProfileFunc shutdown_callback;
29 MonoProfileThreadFunc thread_start, thread_end;
30 MonoProfileGCFunc gc_event;
31 MonoProfileGCResizeFunc gc_heap_resize;
32 MonoProfileJitResult jit_end2;
35 static MonoProfiler *current;
37 MONO_API void mono_profiler_install (MonoLegacyProfiler *prof, MonoProfileFunc callback);
38 MONO_API void mono_profiler_install_thread (MonoProfileThreadFunc start, MonoProfileThreadFunc end);
39 MONO_API void mono_profiler_install_gc (MonoProfileGCFunc callback, MonoProfileGCResizeFunc heap_resize_callback);
40 MONO_API void mono_profiler_install_jit_end (MonoProfileJitResult end);
41 MONO_API void mono_profiler_set_events (int flags);
44 shutdown_cb (MonoProfiler *prof)
46 prof->shutdown_callback (prof->profiler);
50 mono_profiler_install (MonoLegacyProfiler *prof, MonoProfileFunc callback)
52 current = g_new0 (MonoProfiler, 1);
53 current->handle = mono_profiler_create (current);
54 current->profiler = prof;
55 current->shutdown_callback = callback;
58 mono_profiler_set_runtime_shutdown_end_callback (current->handle, shutdown_cb);
62 thread_start_cb (MonoProfiler *prof, uintptr_t tid)
64 prof->thread_start (prof->profiler, tid);
68 thread_stop_cb (MonoProfiler *prof, uintptr_t tid)
70 prof->thread_end (prof->profiler, tid);
74 mono_profiler_install_thread (MonoProfileThreadFunc start, MonoProfileThreadFunc end)
76 current->thread_start = start;
77 current->thread_end = end;
80 mono_profiler_set_thread_started_callback (current->handle, thread_start_cb);
83 mono_profiler_set_thread_stopped_callback (current->handle, thread_stop_cb);
87 gc_event_cb (MonoProfiler *prof, MonoProfilerGCEvent event, uint32_t generation)
89 prof->gc_event (prof->profiler, event, generation);
93 gc_resize_cb (MonoProfiler *prof, uintptr_t size)
95 prof->gc_heap_resize (prof->profiler, size);
99 mono_profiler_install_gc (MonoProfileGCFunc callback, MonoProfileGCResizeFunc heap_resize_callback)
101 current->gc_event = callback;
102 current->gc_heap_resize = heap_resize_callback;
105 mono_profiler_set_gc_event_callback (current->handle, gc_event_cb);
107 if (heap_resize_callback)
108 mono_profiler_set_gc_resize_callback (current->handle, gc_resize_cb);
112 jit_done_cb (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo)
114 prof->jit_end2 (prof->profiler, method, jinfo, 0);
118 jit_failed_cb (MonoProfiler *prof, MonoMethod *method)
120 prof->jit_end2 (prof->profiler, method, NULL, 1);
124 mono_profiler_install_jit_end (MonoProfileJitResult end)
126 current->jit_end2 = end;
129 mono_profiler_set_jit_done_callback (current->handle, jit_done_cb);
130 mono_profiler_set_jit_failed_callback (current->handle, jit_failed_cb);
135 mono_profiler_set_events (int flags)