2 * Licensed to the .NET Foundation under one or more agreements.
3 * The .NET Foundation licenses this file to you under the MIT license.
6 #ifndef __MONO_PROFILER_PRIVATE_H__
7 #define __MONO_PROFILER_PRIVATE_H__
9 #include <mono/metadata/class-internals.h>
10 #include <mono/metadata/profiler.h>
11 #include <mono/utils/mono-context.h>
12 #include <mono/utils/mono-os-mutex.h>
13 #include <mono/utils/mono-os-semaphore.h>
14 #include <mono/metadata/icalls.h>
16 struct _MonoProfilerDesc
{
17 MonoProfilerHandle next
;
19 volatile gpointer cleanup_callback
;
20 volatile gpointer coverage_filter
;
21 volatile gpointer call_instrumentation_filter
;
23 #define _MONO_PROFILER_EVENT(name) \
24 volatile gpointer name ## _cb;
25 #define MONO_PROFILER_EVENT_0(name, type) \
26 _MONO_PROFILER_EVENT(name)
27 #define MONO_PROFILER_EVENT_1(name, type, arg1_type, arg1_name) \
28 _MONO_PROFILER_EVENT(name)
29 #define MONO_PROFILER_EVENT_2(name, type, arg1_type, arg1_name, arg2_type, arg2_name) \
30 _MONO_PROFILER_EVENT(name)
31 #define MONO_PROFILER_EVENT_3(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name) \
32 _MONO_PROFILER_EVENT(name)
33 #define MONO_PROFILER_EVENT_4(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name) \
34 _MONO_PROFILER_EVENT(name)
35 #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) \
36 _MONO_PROFILER_EVENT(name)
37 #include <mono/metadata/profiler-events.h>
38 #undef MONO_PROFILER_EVENT_0
39 #undef MONO_PROFILER_EVENT_1
40 #undef MONO_PROFILER_EVENT_2
41 #undef MONO_PROFILER_EVENT_3
42 #undef MONO_PROFILER_EVENT_4
43 #undef MONO_PROFILER_EVENT_5
44 #undef _MONO_PROFILER_EVENT
48 gboolean startup_done
;
50 MonoProfilerHandle profilers
;
52 gboolean code_coverage
;
53 mono_mutex_t coverage_mutex
;
54 GHashTable
*coverage_hash
;
56 MonoProfilerHandle sampling_owner
;
57 MonoSemType sampling_semaphore
;
58 MonoProfilerSampleMode sample_mode
;
65 gboolean call_contexts
;
66 void (*context_enable
) (void);
67 gpointer (*context_get_this
) (MonoProfilerCallContext
*);
68 gpointer (*context_get_argument
) (MonoProfilerCallContext
*, guint32
);
69 gpointer (*context_get_local
) (MonoProfilerCallContext
*, guint32
);
70 gpointer (*context_get_result
) (MonoProfilerCallContext
*);
71 void (*context_free_buffer
) (gpointer
);
73 #define _MONO_PROFILER_EVENT(name) \
74 volatile gint32 name ## _count;
75 #define MONO_PROFILER_EVENT_0(name, type) \
76 _MONO_PROFILER_EVENT(name)
77 #define MONO_PROFILER_EVENT_1(name, type, arg1_type, arg1_name) \
78 _MONO_PROFILER_EVENT(name)
79 #define MONO_PROFILER_EVENT_2(name, type, arg1_type, arg1_name, arg2_type, arg2_name) \
80 _MONO_PROFILER_EVENT(name)
81 #define MONO_PROFILER_EVENT_3(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name) \
82 _MONO_PROFILER_EVENT(name)
83 #define MONO_PROFILER_EVENT_4(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name) \
84 _MONO_PROFILER_EVENT(name)
85 #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) \
86 _MONO_PROFILER_EVENT(name)
87 #include <mono/metadata/profiler-events.h>
88 #undef MONO_PROFILER_EVENT_0
89 #undef MONO_PROFILER_EVENT_1
90 #undef MONO_PROFILER_EVENT_2
91 #undef MONO_PROFILER_EVENT_3
92 #undef MONO_PROFILER_EVENT_4
93 #undef MONO_PROFILER_EVENT_5
94 #undef _MONO_PROFILER_EVENT
97 extern MonoProfilerState mono_profiler_state
;
102 } MonoProfilerCoverageInfoEntry
;
106 MonoProfilerCoverageInfoEntry data
[MONO_ZERO_LEN_ARRAY
];
107 } MonoProfilerCoverageInfo
;
109 void mono_profiler_started (void);
110 void mono_profiler_cleanup (void);
112 static inline gboolean
113 mono_profiler_installed (void)
115 return !!mono_profiler_state
.profilers
;
118 gboolean
mono_profiler_coverage_instrumentation_enabled (MonoMethod
*method
);
119 MonoProfilerCoverageInfo
*mono_profiler_coverage_alloc (MonoMethod
*method
, guint32 entries
);
121 struct _MonoProfilerCallContext
{
123 * Must be the first field (the JIT relies on it). Only filled out if this
124 * is a JIT frame; otherwise, zeroed.
128 * A non-NULL MonoInterpFrameHandle if this is an interpreter frame.
130 gpointer interp_frame
;
133 * Points to the return value for an epilogue context. For a prologue, this
136 gpointer return_value
;
138 * Points to an array of addresses of stack slots holding the arguments.
143 MonoProfilerCallInstrumentationFlags
mono_profiler_get_call_instrumentation_flags (MonoMethod
*method
);
145 gboolean
mono_profiler_sampling_enabled (void);
146 void mono_profiler_sampling_thread_post (void);
147 void mono_profiler_sampling_thread_wait (void);
149 static inline gboolean
150 mono_profiler_allocations_enabled (void)
152 return mono_profiler_state
.allocations
;
155 static inline gboolean
156 mono_profiler_clauses_enabled (void)
158 return mono_profiler_state
.clauses
;
161 #define _MONO_PROFILER_EVENT(name, ...) \
162 ICALL_EXPORT void mono_profiler_raise_ ## name (__VA_ARGS__);
163 #define MONO_PROFILER_EVENT_0(name, type) \
164 _MONO_PROFILER_EVENT(name, void)
165 #define MONO_PROFILER_EVENT_1(name, type, arg1_type, arg1_name) \
166 _MONO_PROFILER_EVENT(name, arg1_type arg1_name)
167 #define MONO_PROFILER_EVENT_2(name, type, arg1_type, arg1_name, arg2_type, arg2_name) \
168 _MONO_PROFILER_EVENT(name, arg1_type arg1_name, arg2_type arg2_name)
169 #define MONO_PROFILER_EVENT_3(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name) \
170 _MONO_PROFILER_EVENT(name, arg1_type arg1_name, arg2_type arg2_name, arg3_type arg3_name)
171 #define MONO_PROFILER_EVENT_4(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name) \
172 _MONO_PROFILER_EVENT(name, arg1_type arg1_name, arg2_type arg2_name, arg3_type arg3_name, arg4_type arg4_name)
173 #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) \
174 _MONO_PROFILER_EVENT(name, arg1_type arg1_name, arg2_type arg2_name, arg3_type arg3_name, arg4_type arg4_name, arg5_type arg5_name)
175 #include <mono/metadata/profiler-events.h>
176 #undef MONO_PROFILER_EVENT_0
177 #undef MONO_PROFILER_EVENT_1
178 #undef MONO_PROFILER_EVENT_2
179 #undef MONO_PROFILER_EVENT_3
180 #undef MONO_PROFILER_EVENT_4
181 #undef MONO_PROFILER_EVENT_5
182 #undef _MONO_PROFILER_EVENT
184 /* These are the macros the rest of the runtime should use. */
186 #define MONO_PROFILER_ENABLED(name) \
187 G_UNLIKELY (mono_profiler_state.name ## _count)
189 #define MONO_PROFILER_RAISE(name, args) \
191 if (MONO_PROFILER_ENABLED (name)) \
192 mono_profiler_raise_ ## name args; \
195 #endif // __MONO_PROFILER_PRIVATE_H__