remove GenericVectorTests from rsp (#17366)
[mono-project.git] / mono / metadata / profiler-private.h
blob389a98f9fbea0ed7bb5b49f95a75bd19943fd10b
1 /*
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.
5 */
7 #ifndef __MONO_PROFILER_PRIVATE_H__
8 #define __MONO_PROFILER_PRIVATE_H__
10 #include <mono/metadata/class-internals.h>
11 #include <mono/metadata/profiler.h>
12 #include <mono/utils/mono-context.h>
13 #include <mono/utils/mono-os-mutex.h>
14 #include <mono/utils/mono-os-semaphore.h>
15 #include <mono/metadata/icalls.h>
17 struct _MonoProfilerDesc {
18 MonoProfilerHandle next;
19 MonoProfiler *prof;
20 volatile gpointer cleanup_callback;
21 volatile gpointer coverage_filter;
22 volatile gpointer call_instrumentation_filter;
24 #define _MONO_PROFILER_EVENT(name) \
25 volatile gpointer name ## _cb;
26 #define MONO_PROFILER_EVENT_0(name, type) \
27 _MONO_PROFILER_EVENT(name)
28 #define MONO_PROFILER_EVENT_1(name, type, arg1_type, arg1_name) \
29 _MONO_PROFILER_EVENT(name)
30 #define MONO_PROFILER_EVENT_2(name, type, arg1_type, arg1_name, arg2_type, arg2_name) \
31 _MONO_PROFILER_EVENT(name)
32 #define MONO_PROFILER_EVENT_3(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name) \
33 _MONO_PROFILER_EVENT(name)
34 #define MONO_PROFILER_EVENT_4(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name) \
35 _MONO_PROFILER_EVENT(name)
36 #define MONO_PROFILER_EVENT_5(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name, arg5_type, arg5_name) \
37 _MONO_PROFILER_EVENT(name)
38 #include <mono/metadata/profiler-events.h>
39 #undef MONO_PROFILER_EVENT_0
40 #undef MONO_PROFILER_EVENT_1
41 #undef MONO_PROFILER_EVENT_2
42 #undef MONO_PROFILER_EVENT_3
43 #undef MONO_PROFILER_EVENT_4
44 #undef MONO_PROFILER_EVENT_5
45 #undef _MONO_PROFILER_EVENT
48 typedef struct {
49 gboolean startup_done;
51 MonoProfilerHandle profilers;
53 gboolean code_coverage;
54 mono_mutex_t coverage_mutex;
55 GHashTable *coverage_hash;
57 MonoProfilerHandle sampling_owner;
58 MonoSemType sampling_semaphore;
59 MonoProfilerSampleMode sample_mode;
60 guint32 sample_freq;
62 gboolean allocations;
64 gboolean clauses;
66 gboolean call_contexts;
67 void (*context_enable) (void);
68 gpointer (*context_get_this) (MonoProfilerCallContext *);
69 gpointer (*context_get_argument) (MonoProfilerCallContext *, guint32);
70 gpointer (*context_get_local) (MonoProfilerCallContext *, guint32);
71 gpointer (*context_get_result) (MonoProfilerCallContext *);
72 void (*context_free_buffer) (gpointer);
74 #define _MONO_PROFILER_EVENT(name) \
75 volatile gint32 name ## _count;
76 #define MONO_PROFILER_EVENT_0(name, type) \
77 _MONO_PROFILER_EVENT(name)
78 #define MONO_PROFILER_EVENT_1(name, type, arg1_type, arg1_name) \
79 _MONO_PROFILER_EVENT(name)
80 #define MONO_PROFILER_EVENT_2(name, type, arg1_type, arg1_name, arg2_type, arg2_name) \
81 _MONO_PROFILER_EVENT(name)
82 #define MONO_PROFILER_EVENT_3(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name) \
83 _MONO_PROFILER_EVENT(name)
84 #define MONO_PROFILER_EVENT_4(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name) \
85 _MONO_PROFILER_EVENT(name)
86 #define MONO_PROFILER_EVENT_5(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name, arg5_type, arg5_name) \
87 _MONO_PROFILER_EVENT(name)
88 #include <mono/metadata/profiler-events.h>
89 #undef MONO_PROFILER_EVENT_0
90 #undef MONO_PROFILER_EVENT_1
91 #undef MONO_PROFILER_EVENT_2
92 #undef MONO_PROFILER_EVENT_3
93 #undef MONO_PROFILER_EVENT_4
94 #undef MONO_PROFILER_EVENT_5
95 #undef _MONO_PROFILER_EVENT
96 } MonoProfilerState;
98 extern MonoProfilerState mono_profiler_state;
100 typedef struct {
101 guint32 entries;
102 struct {
103 guchar *cil_code;
104 guint32 count;
105 } data [1];
106 } MonoProfilerCoverageInfo;
108 void mono_profiler_started (void);
109 void mono_profiler_cleanup (void);
111 static inline gboolean
112 mono_profiler_installed (void)
114 return !!mono_profiler_state.profilers;
117 gboolean mono_profiler_coverage_instrumentation_enabled (MonoMethod *method);
118 MonoProfilerCoverageInfo *mono_profiler_coverage_alloc (MonoMethod *method, guint32 entries);
120 struct _MonoProfilerCallContext {
122 * Must be the first field (the JIT relies on it). Only filled out if this
123 * is a JIT frame; otherwise, zeroed.
125 MonoContext context;
127 * A non-NULL MonoInterpFrameHandle if this is an interpreter frame.
129 gpointer interp_frame;
130 MonoMethod *method;
132 * Points to the return value for an epilogue context. For a prologue, this
133 * is set to NULL.
135 gpointer return_value;
137 * Points to an array of addresses of stack slots holding the arguments.
139 gpointer *args;
142 MonoProfilerCallInstrumentationFlags mono_profiler_get_call_instrumentation_flags (MonoMethod *method);
144 gboolean mono_profiler_sampling_enabled (void);
145 void mono_profiler_sampling_thread_post (void);
146 void mono_profiler_sampling_thread_wait (void);
148 static inline gboolean
149 mono_profiler_allocations_enabled (void)
151 return mono_profiler_state.allocations;
154 static inline gboolean
155 mono_profiler_clauses_enabled (void)
157 return mono_profiler_state.clauses;
160 #define _MONO_PROFILER_EVENT(name, ...) \
161 ICALL_DECL_EXPORT void mono_profiler_raise_ ## name (__VA_ARGS__);
162 #define MONO_PROFILER_EVENT_0(name, type) \
163 _MONO_PROFILER_EVENT(name, void)
164 #define MONO_PROFILER_EVENT_1(name, type, arg1_type, arg1_name) \
165 _MONO_PROFILER_EVENT(name, arg1_type arg1_name)
166 #define MONO_PROFILER_EVENT_2(name, type, arg1_type, arg1_name, arg2_type, arg2_name) \
167 _MONO_PROFILER_EVENT(name, arg1_type arg1_name, arg2_type arg2_name)
168 #define MONO_PROFILER_EVENT_3(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name) \
169 _MONO_PROFILER_EVENT(name, arg1_type arg1_name, arg2_type arg2_name, arg3_type arg3_name)
170 #define MONO_PROFILER_EVENT_4(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name) \
171 _MONO_PROFILER_EVENT(name, arg1_type arg1_name, arg2_type arg2_name, arg3_type arg3_name, arg4_type arg4_name)
172 #define MONO_PROFILER_EVENT_5(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name, arg5_type, arg5_name) \
173 _MONO_PROFILER_EVENT(name, arg1_type arg1_name, arg2_type arg2_name, arg3_type arg3_name, arg4_type arg4_name, arg5_type arg5_name)
174 #include <mono/metadata/profiler-events.h>
175 #undef MONO_PROFILER_EVENT_0
176 #undef MONO_PROFILER_EVENT_1
177 #undef MONO_PROFILER_EVENT_2
178 #undef MONO_PROFILER_EVENT_3
179 #undef MONO_PROFILER_EVENT_4
180 #undef MONO_PROFILER_EVENT_5
181 #undef _MONO_PROFILER_EVENT
183 /* These are the macros the rest of the runtime should use. */
185 #define MONO_PROFILER_ENABLED(name) \
186 G_UNLIKELY (mono_profiler_state.name ## _count)
188 #define MONO_PROFILER_RAISE(name, args) \
189 do { \
190 if (MONO_PROFILER_ENABLED (name)) \
191 mono_profiler_raise_ ## name args; \
192 } while (0)
194 #endif // __MONO_PROFILER_PRIVATE_H__