2009-09-01 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / metadata / profiler.h
1 #ifndef __MONO_PROFILER_H__
2 #define __MONO_PROFILER_H__
3
4 #include <mono/metadata/object.h>
5 #include <mono/metadata/appdomain.h>
6
7 G_BEGIN_DECLS
8
9 typedef enum {
10         MONO_PROFILE_NONE = 0,
11         MONO_PROFILE_APPDOMAIN_EVENTS = 1 << 0,
12         MONO_PROFILE_ASSEMBLY_EVENTS  = 1 << 1,
13         MONO_PROFILE_MODULE_EVENTS    = 1 << 2,
14         MONO_PROFILE_CLASS_EVENTS     = 1 << 3,
15         MONO_PROFILE_JIT_COMPILATION  = 1 << 4,
16         MONO_PROFILE_INLINING         = 1 << 5,
17         MONO_PROFILE_EXCEPTIONS       = 1 << 6,
18         MONO_PROFILE_ALLOCATIONS      = 1 << 7,
19         MONO_PROFILE_GC               = 1 << 8,
20         MONO_PROFILE_THREADS          = 1 << 9,
21         MONO_PROFILE_REMOTING         = 1 << 10,
22         MONO_PROFILE_TRANSITIONS      = 1 << 11,
23         MONO_PROFILE_ENTER_LEAVE      = 1 << 12,
24         MONO_PROFILE_COVERAGE         = 1 << 13,
25         MONO_PROFILE_INS_COVERAGE     = 1 << 14,
26         MONO_PROFILE_STATISTICAL      = 1 << 15,
27         MONO_PROFILE_METHOD_EVENTS    = 1 << 16,
28         MONO_PROFILE_MONITOR_EVENTS   = 1 << 17
29 } MonoProfileFlags;
30
31 typedef enum {
32         MONO_PROFILE_OK,
33         MONO_PROFILE_FAILED
34 } MonoProfileResult;
35
36 typedef enum {
37         MONO_GC_EVENT_START,
38         MONO_GC_EVENT_MARK_START,
39         MONO_GC_EVENT_MARK_END,
40         MONO_GC_EVENT_RECLAIM_START,
41         MONO_GC_EVENT_RECLAIM_END,
42         MONO_GC_EVENT_END,
43         MONO_GC_EVENT_PRE_STOP_WORLD,
44         MONO_GC_EVENT_POST_STOP_WORLD,
45         MONO_GC_EVENT_PRE_START_WORLD,
46         MONO_GC_EVENT_POST_START_WORLD
47 } MonoGCEvent;
48
49 /* coverage info */
50 typedef struct {
51         MonoMethod *method;
52         int iloffset;
53         int counter;
54         const char *filename;
55         int line;
56         int col;
57 } MonoProfileCoverageEntry;
58
59 /* executable code buffer info */
60 typedef enum {
61         MONO_PROFILER_CODE_BUFFER_UNKNOWN,
62         MONO_PROFILER_CODE_BUFFER_METHOD,
63         MONO_PROFILER_CODE_BUFFER_LAST
64 } MonoProfilerCodeBufferType;
65
66 typedef struct _MonoProfiler MonoProfiler;
67
68 typedef enum {
69         MONO_PROFILER_MONITOR_CONTENTION = 1,
70         MONO_PROFILER_MONITOR_DONE = 2,
71         MONO_PROFILER_MONITOR_FAIL = 3
72 } MonoProfilerMonitorEvent;
73
74 /*
75  * Functions that the runtime will call on the profiler.
76  */
77
78 typedef void (*MonoProfileFunc) (MonoProfiler *prof);
79
80 typedef void (*MonoProfileAppDomainFunc) (MonoProfiler *prof, MonoDomain   *domain);
81 typedef void (*MonoProfileMethodFunc)   (MonoProfiler *prof, MonoMethod   *method);
82 typedef void (*MonoProfileClassFunc)    (MonoProfiler *prof, MonoClass    *klass);
83 typedef void (*MonoProfileModuleFunc)   (MonoProfiler *prof, MonoImage    *module);
84 typedef void (*MonoProfileAssemblyFunc) (MonoProfiler *prof, MonoAssembly *assembly);
85 typedef void (*MonoProfileMonitorFunc)  (MonoProfiler *prof, MonoObject *obj, MonoProfilerMonitorEvent event);
86
87 typedef void (*MonoProfileExceptionFunc) (MonoProfiler *prof, MonoObject *object);
88 typedef void (*MonoProfileExceptionClauseFunc) (MonoProfiler *prof, MonoMethod *method, int clause_type, int clause_num);
89
90 typedef void (*MonoProfileAppDomainResult)(MonoProfiler *prof, MonoDomain   *domain,   int result);
91 typedef void (*MonoProfileMethodResult)   (MonoProfiler *prof, MonoMethod   *method,   int result);
92 typedef void (*MonoProfileJitResult)      (MonoProfiler *prof, MonoMethod   *method,   MonoJitInfo* jinfo,   int result);
93 typedef void (*MonoProfileClassResult)    (MonoProfiler *prof, MonoClass    *klass,    int result);
94 typedef void (*MonoProfileModuleResult)   (MonoProfiler *prof, MonoImage    *module,   int result);
95 typedef void (*MonoProfileAssemblyResult) (MonoProfiler *prof, MonoAssembly *assembly, int result);
96
97 typedef void (*MonoProfileMethodInline)   (MonoProfiler *prof, MonoMethod   *parent, MonoMethod *child, int *ok);
98
99 typedef void (*MonoProfileThreadFunc)     (MonoProfiler *prof, gsize tid);
100 typedef void (*MonoProfileAllocFunc)      (MonoProfiler *prof, MonoObject *obj, MonoClass *klass);
101 typedef void (*MonoProfileStatFunc)       (MonoProfiler *prof, guchar *ip, void *context);
102 typedef void (*MonoProfileStatCallChainFunc) (MonoProfiler *prof, int call_chain_depth, guchar **ip, void *context);
103 typedef void (*MonoProfileGCFunc)         (MonoProfiler *prof, MonoGCEvent event, int generation);
104 typedef void (*MonoProfileGCResizeFunc)   (MonoProfiler *prof, gint64 new_size);
105
106 typedef gboolean (*MonoProfileCoverageFilterFunc)   (MonoProfiler *prof, MonoMethod *method);
107
108 typedef void (*MonoProfileCoverageFunc)   (MonoProfiler *prof, const MonoProfileCoverageEntry *entry);
109
110
111 typedef void (*MonoProfilerCodeChunkNew) (MonoProfiler *prof, gpointer chunk, int size);
112 typedef void (*MonoProfilerCodeChunkDestroy) (MonoProfiler *prof, gpointer chunk);
113 typedef void (*MonoProfilerCodeBufferNew) (MonoProfiler *prof, gpointer buffer, int size, MonoProfilerCodeBufferType type, void *data);
114
115 /*
116  * Function the profiler may call.
117  */
118 void mono_profiler_install       (MonoProfiler *prof, MonoProfileFunc shutdown_callback);
119 void mono_profiler_set_events    (MonoProfileFlags events);
120
121 MonoProfileFlags mono_profiler_get_events (void);
122
123 void mono_profiler_install_appdomain   (MonoProfileAppDomainFunc start_load, MonoProfileAppDomainResult end_load,
124                                         MonoProfileAppDomainFunc start_unload, MonoProfileAppDomainFunc end_unload);
125 void mono_profiler_install_assembly    (MonoProfileAssemblyFunc start_load, MonoProfileAssemblyResult end_load,
126                                         MonoProfileAssemblyFunc start_unload, MonoProfileAssemblyFunc end_unload);
127 void mono_profiler_install_module      (MonoProfileModuleFunc start_load, MonoProfileModuleResult end_load,
128                                         MonoProfileModuleFunc start_unload, MonoProfileModuleFunc end_unload);
129 void mono_profiler_install_class       (MonoProfileClassFunc start_load, MonoProfileClassResult end_load,
130                                         MonoProfileClassFunc start_unload, MonoProfileClassFunc end_unload);
131
132 void mono_profiler_install_jit_compile (MonoProfileMethodFunc start, MonoProfileMethodResult end);
133 void mono_profiler_install_jit_end (MonoProfileJitResult end);
134 void mono_profiler_install_method_free (MonoProfileMethodFunc callback);
135 void mono_profiler_install_enter_leave (MonoProfileMethodFunc enter, MonoProfileMethodFunc fleave);
136 void mono_profiler_install_thread      (MonoProfileThreadFunc start, MonoProfileThreadFunc end);
137 void mono_profiler_install_transition  (MonoProfileMethodResult callback);
138 void mono_profiler_install_allocation  (MonoProfileAllocFunc callback);
139 void mono_profiler_install_monitor     (MonoProfileMonitorFunc callback);
140 void mono_profiler_install_statistical (MonoProfileStatFunc callback);
141 void mono_profiler_install_statistical_call_chain (MonoProfileStatCallChainFunc callback, int call_chain_depth);
142 void mono_profiler_install_exception   (MonoProfileExceptionFunc throw_callback, MonoProfileMethodFunc exc_method_leave, MonoProfileExceptionClauseFunc clause_callback);
143 void mono_profiler_install_coverage_filter (MonoProfileCoverageFilterFunc callback);
144 void mono_profiler_coverage_get  (MonoProfiler *prof, MonoMethod *method, MonoProfileCoverageFunc func);
145 void mono_profiler_install_gc    (MonoProfileGCFunc callback, MonoProfileGCResizeFunc heap_resize_callback);
146 void mono_profiler_install_runtime_initialized (MonoProfileFunc runtime_initialized_callback);
147
148 void mono_profiler_install_code_chunk_new (MonoProfilerCodeChunkNew callback);
149 void mono_profiler_install_code_chunk_destroy (MonoProfilerCodeChunkDestroy callback);
150 void mono_profiler_install_code_buffer_new (MonoProfilerCodeBufferNew callback);
151
152 void mono_profiler_load             (const char *desc);
153
154 G_END_DECLS
155
156 #endif /* __MONO_PROFILER_H__ */
157