[profiler] Hide the GC roots callback behind a macro and mark it obsolete.
[mono.git] / mono / profiler / log.h
1 #ifndef __MONO_PROFLOG_H__
2 #define __MONO_PROFLOG_H__
3
4 #include <glib.h>
5 #define MONO_PROFILER_UNSTABLE_GC_ROOTS
6 #include <mono/metadata/profiler.h>
7
8 #define BUF_ID 0x4D504C01
9 #define LOG_HEADER_ID 0x4D505A01
10 #define LOG_VERSION_MAJOR 2
11 #define LOG_VERSION_MINOR 0
12 #define LOG_DATA_VERSION 14
13
14 /*
15  * Changes in major/minor versions:
16  * version 1.0: removed sysid field from header
17  *              added args, arch, os fields to header
18  *
19  * Changes in data versions:
20  * version 2: added offsets in heap walk
21  * version 3: added GC roots
22  * version 4: added sample/statistical profiling
23  * version 5: added counters sampling
24  * version 6: added optional backtrace in sampling info
25  * version 8: added TYPE_RUNTIME and JIT helpers/trampolines
26  * version 9: added MONO_PROFILER_CODE_BUFFER_EXCEPTION_HANDLING
27  * version 10: added TYPE_COVERAGE
28  * version 11: added thread ID to TYPE_SAMPLE_HIT
29                added more load/unload events
30                    unload for class
31                    unload for image
32                    load/unload for appdomain
33                    load/unload for contexts
34                    load/unload/name for assemblies
35                removed TYPE_LOAD_ERR flag (profiler never generated it, now removed from the format itself)
36                added TYPE_GC_HANDLE_{CREATED,DESTROYED}_BT
37                TYPE_JIT events are no longer guaranteed to have code start/size info (can be zero)
38  * version 12: added MONO_COUNTER_PROFILER
39  * version 13: added MONO_GC_EVENT_{PRE_STOP_WORLD_LOCKED,POST_START_WORLD_UNLOCKED}
40                added TYPE_META + TYPE_SYNC_POINT
41                removed il and native offset in TYPE_SAMPLE_HIT
42                methods in backtraces are now encoded as proper method pointers
43                removed flags in backtrace format
44                removed flags in metadata events
45                changed the following fields to a single byte rather than leb128
46                    TYPE_GC_EVENT: event_type, generation
47                    TYPE_HEAP_ROOT: root_type
48                    TYPE_JITHELPER: type
49                    TYPE_SAMPLE_HIT: sample_type
50                    TYPE_CLAUSE: clause_type
51                    TYPE_SAMPLE_COUNTERS_DESC: type, unit, variance
52                    TYPE_SAMPLE_COUNTERS: type
53                added time fields to all events that were missing one
54                    TYPE_HEAP_OBJECT
55                    TYPE_HEAP_ROOT
56                    TYPE_SAMPLE_USYM
57                    TYPE_SAMPLE_COUNTERS_DESC
58                    TYPE_COVERAGE_METHOD
59                    TYPE_COVERAGE_STATEMENT
60                    TYPE_COVERAGE_CLASS
61                    TYPE_COVERAGE_ASSEMBLY
62                moved the time field in TYPE_SAMPLE_HIT to right after the event byte, now encoded as a regular time field
63                changed the time field in TYPE_SAMPLE_COUNTERS to be encoded as a regular time field (in nanoseconds)
64                added TYPE_GC_FINALIZE_{START,END,OBJECT_START,OBJECT_END}
65  * version 14: added event field to TYPE_MONITOR instead of encoding it in the extended info
66                all TYPE_MONITOR events can now contain backtraces
67                changed address field in TYPE_SAMPLE_UBIN to be based on ptr_base
68                added an image pointer field to assembly load events
69                added an exception object field to TYPE_CLAUSE
70                class unload events no longer exist (they were never emitted)
71  */
72
73 enum {
74         TYPE_ALLOC,
75         TYPE_GC,
76         TYPE_METADATA,
77         TYPE_METHOD,
78         TYPE_EXCEPTION,
79         TYPE_MONITOR,
80         TYPE_HEAP,
81         TYPE_SAMPLE,
82         TYPE_RUNTIME,
83         TYPE_COVERAGE,
84         TYPE_META,
85         /* extended type for TYPE_HEAP */
86         TYPE_HEAP_START  = 0 << 4,
87         TYPE_HEAP_END    = 1 << 4,
88         TYPE_HEAP_OBJECT = 2 << 4,
89         TYPE_HEAP_ROOT   = 3 << 4,
90         /* extended type for TYPE_METADATA */
91         TYPE_END_LOAD     = 2 << 4,
92         TYPE_END_UNLOAD   = 4 << 4,
93         /* extended type for TYPE_GC */
94         TYPE_GC_EVENT  = 1 << 4,
95         TYPE_GC_RESIZE = 2 << 4,
96         TYPE_GC_MOVE   = 3 << 4,
97         TYPE_GC_HANDLE_CREATED      = 4 << 4,
98         TYPE_GC_HANDLE_DESTROYED    = 5 << 4,
99         TYPE_GC_HANDLE_CREATED_BT   = 6 << 4,
100         TYPE_GC_HANDLE_DESTROYED_BT = 7 << 4,
101         TYPE_GC_FINALIZE_START = 8 << 4,
102         TYPE_GC_FINALIZE_END = 9 << 4,
103         TYPE_GC_FINALIZE_OBJECT_START = 10 << 4,
104         TYPE_GC_FINALIZE_OBJECT_END = 11 << 4,
105         /* extended type for TYPE_METHOD */
106         TYPE_LEAVE     = 1 << 4,
107         TYPE_ENTER     = 2 << 4,
108         TYPE_EXC_LEAVE = 3 << 4,
109         TYPE_JIT       = 4 << 4,
110         /* extended type for TYPE_EXCEPTION */
111         TYPE_THROW_NO_BT = 0 << 7,
112         TYPE_THROW_BT    = 1 << 7,
113         TYPE_CLAUSE      = 1 << 4,
114         /* extended type for TYPE_ALLOC */
115         TYPE_ALLOC_NO_BT  = 0 << 4,
116         TYPE_ALLOC_BT     = 1 << 4,
117         /* extended type for TYPE_MONITOR */
118         TYPE_MONITOR_NO_BT  = 0 << 7,
119         TYPE_MONITOR_BT     = 1 << 7,
120         /* extended type for TYPE_SAMPLE */
121         TYPE_SAMPLE_HIT           = 0 << 4,
122         TYPE_SAMPLE_USYM          = 1 << 4,
123         TYPE_SAMPLE_UBIN          = 2 << 4,
124         TYPE_SAMPLE_COUNTERS_DESC = 3 << 4,
125         TYPE_SAMPLE_COUNTERS      = 4 << 4,
126         /* extended type for TYPE_RUNTIME */
127         TYPE_JITHELPER = 1 << 4,
128         /* extended type for TYPE_COVERAGE */
129         TYPE_COVERAGE_ASSEMBLY = 0 << 4,
130         TYPE_COVERAGE_METHOD   = 1 << 4,
131         TYPE_COVERAGE_STATEMENT = 2 << 4,
132         TYPE_COVERAGE_CLASS = 3 << 4,
133         /* extended type for TYPE_META */
134         TYPE_SYNC_POINT = 0 << 4,
135         TYPE_END
136 };
137
138 enum {
139         /* metadata type byte for TYPE_METADATA */
140         TYPE_CLASS    = 1,
141         TYPE_IMAGE    = 2,
142         TYPE_ASSEMBLY = 3,
143         TYPE_DOMAIN   = 4,
144         TYPE_THREAD   = 5,
145         TYPE_CONTEXT  = 6,
146 };
147
148 typedef enum {
149         SYNC_POINT_PERIODIC,
150         SYNC_POINT_WORLD_STOP,
151         SYNC_POINT_WORLD_START
152 } MonoProfilerSyncPointType;
153
154 typedef enum {
155         MONO_PROFILER_MONITOR_CONTENTION = 1,
156         MONO_PROFILER_MONITOR_DONE = 2,
157         MONO_PROFILER_MONITOR_FAIL = 3,
158 } MonoProfilerMonitorEvent;
159
160 enum {
161         MONO_PROFILER_GC_HANDLE_CREATED,
162         MONO_PROFILER_GC_HANDLE_DESTROYED,
163 };
164
165 // Sampling sources
166 // Unless you have compiled with --enable-perf-events, only SAMPLE_CYCLES is available
167 enum {
168         SAMPLE_CYCLES = 1,
169         SAMPLE_INSTRUCTIONS,
170         SAMPLE_CACHE_MISSES,
171         SAMPLE_CACHE_REFS,
172         SAMPLE_BRANCHES,
173         SAMPLE_BRANCH_MISSES,
174         SAMPLE_LAST
175 };
176
177
178 // If you alter MAX_FRAMES, you may need to alter SAMPLE_BLOCK_SIZE too.
179 #define MAX_FRAMES 32
180
181 //The following flags control emitting individual events
182 #define PROFLOG_DOMAIN_EVENTS (1 << 0)
183 #define PROFLOG_ASSEMBLY_EVENTS (1 << 1)
184 #define PROFLOG_MODULE_EVENTS (1 << 2)
185 #define PROFLOG_CLASS_EVENTS (1 << 3)
186 #define PROFLOG_JIT_COMPILATION_EVENTS (1 << 4)
187 #define PROFLOG_EXCEPTION_EVENTS (1 << 5)
188 #define PROFLOG_ALLOCATION_EVENTS (1 << 6)
189 #define PROFLOG_GC_EVENTS (1 << 7)
190 #define PROFLOG_THREAD_EVENTS (1 << 8)
191 //This generate enter/leave events
192 #define PROFLOG_CALL_EVENTS (1 << 9)
193 #define PROFLOG_INS_COVERAGE_EVENTS (1 << 10)
194 #define PROFLOG_SAMPLING_EVENTS (1 << 11)
195 #define PROFLOG_MONITOR_EVENTS (1 << 12)
196 #define PROFLOG_GC_MOVES_EVENTS (1 << 13)
197
198 #define PROFLOG_GC_ROOT_EVENTS (1 << 14)
199 #define PROFLOG_CONTEXT_EVENTS (1 << 15)
200 #define PROFLOG_FINALIZATION_EVENTS (1 << 16)
201 #define PROFLOG_COUNTER_EVENTS (1 << 17)
202 #define PROFLOG_GC_HANDLE_EVENTS (1 << 18)
203
204 //The following flags control whole subsystems
205 //Enables code coverage generation
206 #define PROFLOG_CODE_COV_FEATURE (1 << 19)
207 //This enables sampling to be generated
208 #define PROFLOG_SAMPLING_FEATURE (1 << 20)
209 //This enable heap dumping during GCs and filter GCRoots and GCHandle events outside of the dumped collections
210 #define PROFLOG_HEAPSHOT_FEATURE (1 << 21)
211
212
213
214 //The follow flags are the common aliases we want ppl to use
215 #define PROFLOG_TYPELOADING_ALIAS (PROFLOG_DOMAIN_EVENTS | PROFLOG_ASSEMBLY_EVENTS | PROFLOG_MODULE_EVENTS | PROFLOG_CLASS_EVENTS)
216 #define PROFLOG_CODECOV_ALIAS (PROFLOG_INS_COVERAGE_EVENTS | PROFLOG_CODE_COV_FEATURE)
217 #define PROFLOG_PERF_SAMPLING_ALIAS (PROFLOG_TYPELOADING_ALIAS | PROFLOG_THREAD_EVENTS | PROFLOG_SAMPLING_EVENTS | PROFLOG_SAMPLING_FEATURE)
218 #define PROFLOG_GC_ALLOC_ALIAS (PROFLOG_TYPELOADING_ALIAS | PROFLOG_THREAD_EVENTS | PROFLOG_GC_EVENTS | PROFLOG_ALLOCATION_EVENTS)
219 #define PROFLOG_HEAPSHOT_ALIAS (PROFLOG_TYPELOADING_ALIAS | PROFLOG_THREAD_EVENTS | PROFLOG_GC_EVENTS | PROFLOG_GC_ROOT_EVENTS | PROFLOG_HEAPSHOT_FEATURE)
220 #define PROFLOG_LEGACY_ALIAS (PROFLOG_TYPELOADING_ALIAS | PROFLOG_GC_EVENTS | PROFLOG_THREAD_EVENTS | PROFLOG_JIT_COMPILATION_EVENTS | PROFLOG_EXCEPTION_EVENTS | PROFLOG_MONITOR_EVENTS | PROFLOG_GC_ROOT_EVENTS | PROFLOG_CONTEXT_EVENTS | PROFLOG_FINALIZATION_EVENTS | PROFLOG_COUNTER_EVENTS)
221
222
223 typedef struct {
224         //Events explicitly enabled
225         int enable_mask;
226         //Events explicitly disabled
227         int disable_mask;
228
229         //Actual mask the profiler should use
230         int effective_mask;
231
232         //Emit a report at the end of execution
233         gboolean do_report;
234
235         //Enable profiler internal debugging
236         gboolean do_debug;
237
238         //Enable code coverage specific debugging
239         gboolean debug_coverage;
240
241         //Where to compress the output file
242         gboolean use_zip;
243
244         //If true, don't generate stacktraces
245         gboolean notraces;
246
247         //If true, heapshots are generated on demand only
248         gboolean hs_mode_ondemand;
249
250         //HeapShort frequency in milliseconds
251         unsigned int hs_mode_ms;
252
253         //HeapShort frequency in number of collections
254         unsigned int hs_mode_gc;
255
256         //Sample frequency in Hertz
257         int sample_freq;
258
259         //Maximum number of frames to collect
260         int num_frames;
261
262         //Max depth to record enter/leave events
263         int max_call_depth;
264
265         //Name of the generated mlpd file
266         const char *output_filename;
267
268         //Filter files used by the code coverage mode
269         GPtrArray *cov_filter_files;
270
271         //Port to listen for profiling commands
272         int command_port;
273
274         //Max size of the sample hit buffer, we'll drop frames if it's reached
275         int max_allocated_sample_hits;
276
277         MonoProfilerSampleMode sampling_mode;
278 } ProfilerConfig;
279
280 void proflog_parse_args (ProfilerConfig *config, const char *desc);
281
282 #endif /* __MONO_PROFLOG_H__ */