* profiler.h, profiler-private.h, profiler.c: add a new profiler
[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 } MonoProfileFlags;
29
30 typedef enum {
31         MONO_PROFILE_OK,
32         MONO_PROFILE_FAILED
33 } MonoProfileResult;
34
35 typedef enum {
36         MONO_GC_EVENT_START,
37         MONO_GC_EVENT_MARK_START,
38         MONO_GC_EVENT_MARK_END,
39         MONO_GC_EVENT_RECLAIM_START,
40         MONO_GC_EVENT_RECLAIM_END,
41         MONO_GC_EVENT_END
42 } MonoGCEvent;
43
44 /* coverage info */
45 typedef struct {
46         MonoMethod *method;
47         int iloffset;
48         int counter;
49         const char *filename;
50         int line;
51         int col;
52 } MonoProfileCoverageEntry;
53
54 typedef struct _MonoProfiler MonoProfiler;
55
56
57 /*
58  * Functions that the runtime will call on the profiler.
59  */
60
61 typedef void (*MonoProfileFunc) (MonoProfiler *prof);
62
63 typedef void (*MonoProfileAppDomainFunc) (MonoProfiler *prof, MonoDomain   *domain);
64 typedef void (*MonoProfileMethodFunc)   (MonoProfiler *prof, MonoMethod   *method);
65 typedef void (*MonoProfileClassFunc)    (MonoProfiler *prof, MonoClass    *klass);
66 typedef void (*MonoProfileModuleFunc)   (MonoProfiler *prof, MonoImage    *module);
67 typedef void (*MonoProfileAssemblyFunc) (MonoProfiler *prof, MonoAssembly *assembly);
68
69 typedef void (*MonoProfileExceptionFunc) (MonoProfiler *prof, MonoObject *object);
70 typedef void (*MonoProfileExceptionClauseFunc) (MonoProfiler *prof, MonoMethod *method, int clause_type, int clause_num);
71
72 typedef void (*MonoProfileAppDomainResult)(MonoProfiler *prof, MonoDomain   *domain,   int result);
73 typedef void (*MonoProfileMethodResult)   (MonoProfiler *prof, MonoMethod   *method,   int result);
74 typedef void (*MonoProfileJitResult)      (MonoProfiler *prof, MonoMethod   *method,   MonoJitInfo* jinfo,   int result);
75 typedef void (*MonoProfileClassResult)    (MonoProfiler *prof, MonoClass    *klass,    int result);
76 typedef void (*MonoProfileModuleResult)   (MonoProfiler *prof, MonoImage    *module,   int result);
77 typedef void (*MonoProfileAssemblyResult) (MonoProfiler *prof, MonoAssembly *assembly, int result);
78
79 typedef void (*MonoProfileMethodInline)   (MonoProfiler *prof, MonoMethod   *parent, MonoMethod *child, int *ok);
80
81 typedef void (*MonoProfileThreadFunc)     (MonoProfiler *prof, gsize tid);
82 typedef void (*MonoProfileAllocFunc)      (MonoProfiler *prof, MonoObject *obj, MonoClass *klass);
83 typedef void (*MonoProfileStatFunc)       (MonoProfiler *prof, guchar *ip, void *context);
84 typedef void (*MonoProfileGCFunc)         (MonoProfiler *prof, MonoGCEvent event, int generation);
85 typedef void (*MonoProfileGCResizeFunc)   (MonoProfiler *prof, gint64 new_size);
86
87 typedef gboolean (*MonoProfileCoverageFilterFunc)   (MonoProfiler *prof, MonoMethod *method);
88
89 typedef void (*MonoProfileCoverageFunc)   (MonoProfiler *prof, const MonoProfileCoverageEntry *entry);
90
91 /*
92  * Function the profiler may call.
93  */
94 void mono_profiler_install       (MonoProfiler *prof, MonoProfileFunc shutdown_callback);
95 void mono_profiler_set_events    (MonoProfileFlags events);
96
97 MonoProfileFlags mono_profiler_get_events (void);
98
99 void mono_profiler_install_appdomain   (MonoProfileAppDomainFunc start_load, MonoProfileAppDomainResult end_load,
100                                         MonoProfileAppDomainFunc start_unload, MonoProfileAppDomainFunc end_unload);
101 void mono_profiler_install_assembly    (MonoProfileAssemblyFunc start_load, MonoProfileAssemblyResult end_load,
102                                         MonoProfileAssemblyFunc start_unload, MonoProfileAssemblyFunc end_unload);
103 void mono_profiler_install_module      (MonoProfileModuleFunc start_load, MonoProfileModuleResult end_load,
104                                         MonoProfileModuleFunc start_unload, MonoProfileModuleFunc end_unload);
105 void mono_profiler_install_class       (MonoProfileClassFunc start_load, MonoProfileClassResult end_load,
106                                         MonoProfileClassFunc start_unload, MonoProfileClassFunc end_unload);
107
108 void mono_profiler_install_jit_compile (MonoProfileMethodFunc start, MonoProfileMethodResult end);
109 void mono_profiler_install_jit_end (MonoProfileJitResult end);
110 void mono_profiler_install_method_free (MonoProfileMethodFunc callback);
111 void mono_profiler_install_enter_leave (MonoProfileMethodFunc enter, MonoProfileMethodFunc fleave);
112 void mono_profiler_install_thread      (MonoProfileThreadFunc start, MonoProfileThreadFunc end);
113 void mono_profiler_install_transition  (MonoProfileMethodResult callback);
114 void mono_profiler_install_allocation  (MonoProfileAllocFunc callback);
115 void mono_profiler_install_statistical (MonoProfileStatFunc callback);
116 void mono_profiler_install_exception   (MonoProfileExceptionFunc throw_callback, MonoProfileMethodFunc exc_method_leave, MonoProfileExceptionClauseFunc clause_callback);
117 void mono_profiler_install_coverage_filter (MonoProfileCoverageFilterFunc callback);
118 void mono_profiler_coverage_get  (MonoProfiler *prof, MonoMethod *method, MonoProfileCoverageFunc func);
119 void mono_profiler_install_gc    (MonoProfileGCFunc callback, MonoProfileGCResizeFunc heap_resize_callback);
120
121 void mono_profiler_load             (const char *desc);
122
123 G_END_DECLS
124
125 #endif /* __MONO_PROFILER_H__ */
126