New test.
[mono.git] / samples / profiler / sample.c
1 #include <mono/metadata/profiler.h>
2
3 /*
4  * Bare bones profiler. Compile with:
5  * gcc -shared -o mono-profiler-sample.so sample.c `pkg-config --cflags --libs mono`
6  * Install the binary where the dynamic loader can find it.
7  * Then run mono with:
8  * mono --profile=sample your_application.exe
9  */
10
11 struct _MonoProfiler {
12         int ncalls;
13 };
14
15 /* called at the end of the program */
16 static void
17 sample_shutdown (MonoProfiler *prof)
18 {
19         g_print ("total number of calls: %d\n", prof->ncalls);
20 }
21
22 static void
23 sample_method_enter (MonoProfiler *prof, MonoMethod *method)
24 {
25         prof->ncalls++;
26 }
27
28 static void
29 sample_method_leave (MonoProfiler *prof, MonoMethod *method)
30 {
31 }
32
33 /* the entry point */
34 void
35 mono_profiler_startup (const char *desc)
36 {
37         MonoProfiler *prof;
38
39         prof = g_new0 (MonoProfiler, 1);
40
41         mono_profiler_install (prof, sample_shutdown);
42         
43         mono_profiler_install_enter_leave (sample_method_enter, sample_method_leave);
44
45         mono_profiler_set_events (MONO_PROFILE_ENTER_LEAVE);
46 }
47
48