Fix roslyn install with AOT disabled.
[mono-project.git] / mono / metadata / profiler.h
blob84dc1bb83b1bca0dbdf7309649757483a5fbe593
1 #ifndef __MONO_PROFILER_H__
2 #define __MONO_PROFILER_H__
4 #include <mono/metadata/object.h>
5 #include <mono/metadata/appdomain.h>
7 MONO_BEGIN_DECLS
9 #define MONO_PROFILER_MAX_STAT_CALL_CHAIN_DEPTH 128
11 typedef enum {
12 MONO_PROFILE_NONE = 0,
13 MONO_PROFILE_APPDOMAIN_EVENTS = 1 << 0,
14 MONO_PROFILE_ASSEMBLY_EVENTS = 1 << 1,
15 MONO_PROFILE_MODULE_EVENTS = 1 << 2,
16 MONO_PROFILE_CLASS_EVENTS = 1 << 3,
17 MONO_PROFILE_JIT_COMPILATION = 1 << 4,
18 MONO_PROFILE_INLINING = 1 << 5,
19 MONO_PROFILE_EXCEPTIONS = 1 << 6,
20 MONO_PROFILE_ALLOCATIONS = 1 << 7,
21 MONO_PROFILE_GC = 1 << 8,
22 MONO_PROFILE_THREADS = 1 << 9,
23 MONO_PROFILE_REMOTING = 1 << 10,
24 MONO_PROFILE_TRANSITIONS = 1 << 11,
25 MONO_PROFILE_ENTER_LEAVE = 1 << 12,
26 MONO_PROFILE_COVERAGE = 1 << 13,
27 MONO_PROFILE_INS_COVERAGE = 1 << 14,
28 MONO_PROFILE_STATISTICAL = 1 << 15,
29 MONO_PROFILE_METHOD_EVENTS = 1 << 16,
30 MONO_PROFILE_MONITOR_EVENTS = 1 << 17,
31 MONO_PROFILE_IOMAP_EVENTS = 1 << 18, /* this should likely be removed, too */
32 MONO_PROFILE_GC_MOVES = 1 << 19,
33 MONO_PROFILE_GC_ROOTS = 1 << 20,
34 MONO_PROFILE_CONTEXT_EVENTS = 1 << 21,
35 MONO_PROFILE_GC_FINALIZATION = 1 << 22
36 } MonoProfileFlags;
38 typedef enum {
39 MONO_PROFILE_OK,
40 MONO_PROFILE_FAILED
41 } MonoProfileResult;
43 // Keep somewhat in sync with libgc/include/gc.h:enum GC_EventType
44 typedef enum {
45 MONO_GC_EVENT_START,
46 MONO_GC_EVENT_MARK_START,
47 MONO_GC_EVENT_MARK_END,
48 MONO_GC_EVENT_RECLAIM_START,
49 MONO_GC_EVENT_RECLAIM_END,
50 MONO_GC_EVENT_END,
52 * This is the actual arrival order of the following events:
54 * MONO_GC_EVENT_PRE_STOP_WORLD
55 * MONO_GC_EVENT_PRE_STOP_WORLD_LOCKED
56 * MONO_GC_EVENT_POST_STOP_WORLD
57 * MONO_GC_EVENT_PRE_START_WORLD
58 * MONO_GC_EVENT_POST_START_WORLD_UNLOCKED
59 * MONO_GC_EVENT_POST_START_WORLD
61 * The LOCKED and UNLOCKED events guarantee that, by the time they arrive,
62 * the GC and suspend locks will both have been acquired and released,
63 * respectively.
65 MONO_GC_EVENT_PRE_STOP_WORLD,
66 MONO_GC_EVENT_POST_STOP_WORLD,
67 MONO_GC_EVENT_PRE_START_WORLD,
68 MONO_GC_EVENT_POST_START_WORLD,
69 MONO_GC_EVENT_PRE_STOP_WORLD_LOCKED,
70 MONO_GC_EVENT_POST_START_WORLD_UNLOCKED
71 } MonoGCEvent;
73 /* coverage info */
74 typedef struct {
75 MonoMethod *method;
76 int iloffset;
77 int counter;
78 const char *filename;
79 int line;
80 int col;
81 } MonoProfileCoverageEntry;
83 /* executable code buffer info */
84 typedef enum {
85 MONO_PROFILER_CODE_BUFFER_UNKNOWN,
86 MONO_PROFILER_CODE_BUFFER_METHOD,
87 MONO_PROFILER_CODE_BUFFER_METHOD_TRAMPOLINE,
88 MONO_PROFILER_CODE_BUFFER_UNBOX_TRAMPOLINE,
89 MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE,
90 MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE,
91 MONO_PROFILER_CODE_BUFFER_SPECIFIC_TRAMPOLINE,
92 MONO_PROFILER_CODE_BUFFER_HELPER,
93 MONO_PROFILER_CODE_BUFFER_MONITOR,
94 MONO_PROFILER_CODE_BUFFER_DELEGATE_INVOKE,
95 MONO_PROFILER_CODE_BUFFER_EXCEPTION_HANDLING,
96 MONO_PROFILER_CODE_BUFFER_LAST
97 } MonoProfilerCodeBufferType;
99 typedef struct _MonoProfiler MonoProfiler;
101 typedef enum {
102 MONO_PROFILER_MONITOR_CONTENTION = 1,
103 MONO_PROFILER_MONITOR_DONE = 2,
104 MONO_PROFILER_MONITOR_FAIL = 3
105 } MonoProfilerMonitorEvent;
107 typedef enum {
108 MONO_PROFILER_CALL_CHAIN_NONE = 0,
109 MONO_PROFILER_CALL_CHAIN_NATIVE = 1,
110 MONO_PROFILER_CALL_CHAIN_GLIBC = 2,
111 MONO_PROFILER_CALL_CHAIN_MANAGED = 3,
112 MONO_PROFILER_CALL_CHAIN_INVALID = 4
113 } MonoProfilerCallChainStrategy;
115 typedef enum {
116 MONO_PROFILER_GC_HANDLE_CREATED,
117 MONO_PROFILER_GC_HANDLE_DESTROYED
118 } MonoProfileGCHandleEvent;
120 typedef enum {
121 MONO_PROFILE_GC_ROOT_PINNING = 1 << 8,
122 MONO_PROFILE_GC_ROOT_WEAKREF = 2 << 8,
123 MONO_PROFILE_GC_ROOT_INTERIOR = 4 << 8,
124 /* the above are flags, the type is in the low 2 bytes */
125 MONO_PROFILE_GC_ROOT_STACK = 0,
126 MONO_PROFILE_GC_ROOT_FINALIZER = 1,
127 MONO_PROFILE_GC_ROOT_HANDLE = 2,
128 MONO_PROFILE_GC_ROOT_OTHER = 3,
129 MONO_PROFILE_GC_ROOT_MISC = 4, /* could be stack, handle, etc. */
130 MONO_PROFILE_GC_ROOT_TYPEMASK = 0xff
131 } MonoProfileGCRootType;
134 * Functions that the runtime will call on the profiler.
137 typedef void (*MonoProfileFunc) (MonoProfiler *prof);
139 typedef void (*MonoProfileAppDomainFunc) (MonoProfiler *prof, MonoDomain *domain);
140 typedef void (*MonoProfileContextFunc) (MonoProfiler *prof, MonoAppContext *context);
141 typedef void (*MonoProfileMethodFunc) (MonoProfiler *prof, MonoMethod *method);
142 typedef void (*MonoProfileClassFunc) (MonoProfiler *prof, MonoClass *klass);
143 typedef void (*MonoProfileModuleFunc) (MonoProfiler *prof, MonoImage *module);
144 typedef void (*MonoProfileAssemblyFunc) (MonoProfiler *prof, MonoAssembly *assembly);
145 typedef void (*MonoProfileMonitorFunc) (MonoProfiler *prof, MonoObject *obj, MonoProfilerMonitorEvent event);
147 typedef void (*MonoProfileExceptionFunc) (MonoProfiler *prof, MonoObject *object);
148 typedef void (*MonoProfileExceptionClauseFunc) (MonoProfiler *prof, MonoMethod *method, int clause_type, int clause_num);
150 typedef void (*MonoProfileAppDomainResult)(MonoProfiler *prof, MonoDomain *domain, int result);
151 typedef void (*MonoProfileAppDomainFriendlyNameFunc) (MonoProfiler *prof, MonoDomain *domain, const char *name);
152 typedef void (*MonoProfileMethodResult) (MonoProfiler *prof, MonoMethod *method, int result);
153 typedef void (*MonoProfileJitResult) (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo, int result);
154 typedef void (*MonoProfileClassResult) (MonoProfiler *prof, MonoClass *klass, int result);
155 typedef void (*MonoProfileModuleResult) (MonoProfiler *prof, MonoImage *module, int result);
156 typedef void (*MonoProfileAssemblyResult) (MonoProfiler *prof, MonoAssembly *assembly, int result);
158 typedef void (*MonoProfileMethodInline) (MonoProfiler *prof, MonoMethod *parent, MonoMethod *child, int *ok);
160 typedef void (*MonoProfileThreadFunc) (MonoProfiler *prof, uintptr_t tid);
161 typedef void (*MonoProfileThreadNameFunc) (MonoProfiler *prof, uintptr_t tid, const char *name);
162 typedef void (*MonoProfileAllocFunc) (MonoProfiler *prof, MonoObject *obj, MonoClass *klass);
163 typedef void (*MonoProfileStatFunc) (MonoProfiler *prof, mono_byte *ip, void *context);
164 typedef void (*MonoProfileStatCallChainFunc) (MonoProfiler *prof, int call_chain_depth, mono_byte **ip, void *context);
165 typedef void (*MonoProfileGCFunc) (MonoProfiler *prof, MonoGCEvent event, int generation);
166 typedef void (*MonoProfileGCMoveFunc) (MonoProfiler *prof, void **objects, int num);
167 typedef void (*MonoProfileGCResizeFunc) (MonoProfiler *prof, int64_t new_size);
168 typedef void (*MonoProfileGCHandleFunc) (MonoProfiler *prof, int op, int type, uintptr_t handle, MonoObject *obj);
169 typedef void (*MonoProfileGCRootFunc) (MonoProfiler *prof, int num_roots, void **objects, int *root_types, uintptr_t *extra_info);
171 typedef void (*MonoProfileGCFinalizeFunc) (MonoProfiler *prof);
172 typedef void (*MonoProfileGCFinalizeObjectFunc) (MonoProfiler *prof, MonoObject *obj);
174 typedef void (*MonoProfileIomapFunc) (MonoProfiler *prof, const char *report, const char *pathname, const char *new_pathname);
176 typedef mono_bool (*MonoProfileCoverageFilterFunc) (MonoProfiler *prof, MonoMethod *method);
178 typedef void (*MonoProfileCoverageFunc) (MonoProfiler *prof, const MonoProfileCoverageEntry *entry);
180 typedef void (*MonoProfilerCodeChunkNew) (MonoProfiler *prof, void* chunk, int size);
181 typedef void (*MonoProfilerCodeChunkDestroy) (MonoProfiler *prof, void* chunk);
182 typedef void (*MonoProfilerCodeBufferNew) (MonoProfiler *prof, void* buffer, int size, MonoProfilerCodeBufferType type, void *data);
185 * Function the profiler may call.
187 MONO_API void mono_profiler_install (MonoProfiler *prof, MonoProfileFunc shutdown_callback);
188 MONO_API void mono_profiler_set_events (MonoProfileFlags events);
190 MONO_API MonoProfileFlags mono_profiler_get_events (void);
192 MONO_API void mono_profiler_install_appdomain (MonoProfileAppDomainFunc start_load, MonoProfileAppDomainResult end_load,
193 MonoProfileAppDomainFunc start_unload, MonoProfileAppDomainFunc end_unload);
194 MONO_API void mono_profiler_install_appdomain_name (MonoProfileAppDomainFriendlyNameFunc domain_name_cb);
195 MONO_API void mono_profiler_install_context (MonoProfileContextFunc load, MonoProfileContextFunc unload);
196 MONO_API void mono_profiler_install_assembly (MonoProfileAssemblyFunc start_load, MonoProfileAssemblyResult end_load,
197 MonoProfileAssemblyFunc start_unload, MonoProfileAssemblyFunc end_unload);
198 MONO_API void mono_profiler_install_module (MonoProfileModuleFunc start_load, MonoProfileModuleResult end_load,
199 MonoProfileModuleFunc start_unload, MonoProfileModuleFunc end_unload);
200 MONO_API void mono_profiler_install_class (MonoProfileClassFunc start_load, MonoProfileClassResult end_load,
201 MonoProfileClassFunc start_unload, MonoProfileClassFunc end_unload);
203 MONO_API void mono_profiler_install_jit_compile (MonoProfileMethodFunc start, MonoProfileMethodResult end);
204 MONO_API void mono_profiler_install_jit_end (MonoProfileJitResult end);
205 MONO_API void mono_profiler_install_method_free (MonoProfileMethodFunc callback);
206 MONO_API void mono_profiler_install_method_invoke (MonoProfileMethodFunc start, MonoProfileMethodFunc end);
207 MONO_API void mono_profiler_install_enter_leave (MonoProfileMethodFunc enter, MonoProfileMethodFunc fleave);
208 MONO_API void mono_profiler_install_thread (MonoProfileThreadFunc start, MonoProfileThreadFunc end);
209 MONO_API void mono_profiler_install_thread_name (MonoProfileThreadNameFunc thread_name_cb);
210 MONO_API void mono_profiler_install_transition (MonoProfileMethodResult callback);
211 MONO_API void mono_profiler_install_allocation (MonoProfileAllocFunc callback);
212 MONO_API void mono_profiler_install_monitor (MonoProfileMonitorFunc callback);
213 MONO_API void mono_profiler_install_statistical (MonoProfileStatFunc callback);
214 MONO_API void mono_profiler_install_statistical_call_chain (MonoProfileStatCallChainFunc callback, int call_chain_depth, MonoProfilerCallChainStrategy call_chain_strategy);
215 MONO_API void mono_profiler_install_exception (MonoProfileExceptionFunc throw_callback, MonoProfileMethodFunc exc_method_leave, MonoProfileExceptionClauseFunc clause_callback);
216 MONO_API void mono_profiler_install_coverage_filter (MonoProfileCoverageFilterFunc callback);
217 MONO_API void mono_profiler_coverage_get (MonoProfiler *prof, MonoMethod *method, MonoProfileCoverageFunc func);
218 MONO_API void mono_profiler_install_gc (MonoProfileGCFunc callback, MonoProfileGCResizeFunc heap_resize_callback);
219 MONO_API void mono_profiler_install_gc_moves (MonoProfileGCMoveFunc callback);
220 MONO_API void mono_profiler_install_gc_roots (MonoProfileGCHandleFunc handle_callback, MonoProfileGCRootFunc roots_callback);
221 MONO_API void mono_profiler_install_gc_finalize (MonoProfileGCFinalizeFunc begin, MonoProfileGCFinalizeObjectFunc begin_obj, MonoProfileGCFinalizeObjectFunc end_obj, MonoProfileGCFinalizeFunc end);
222 MONO_API void mono_profiler_install_runtime_initialized (MonoProfileFunc runtime_initialized_callback);
224 MONO_API void mono_profiler_install_code_chunk_new (MonoProfilerCodeChunkNew callback);
225 MONO_API void mono_profiler_install_code_chunk_destroy (MonoProfilerCodeChunkDestroy callback);
226 MONO_API void mono_profiler_install_code_buffer_new (MonoProfilerCodeBufferNew callback);
228 MONO_API void mono_profiler_install_iomap (MonoProfileIomapFunc callback);
230 MONO_API void mono_profiler_load (const char *desc);
232 typedef enum {
233 /* Elapsed time is tracked by user+kernel time of the process - this is the default*/
234 MONO_PROFILER_STAT_MODE_PROCESS = 0,
235 /* Elapsed time is tracked by wallclock time */
236 MONO_PROFILER_STAT_MODE_REAL = 1,
237 } MonoProfileSamplingMode;
239 MONO_API void mono_profiler_set_statistical_mode (MonoProfileSamplingMode mode, int64_t sampling_frequency_hz);
241 MONO_END_DECLS
243 #endif /* __MONO_PROFILER_H__ */