[threads] Ensure thread is still alive when detaching it
[mono-project.git] / samples / profiler / sample.c
blob45c46da07d983742adb54409ac23b3aeea64e873
1 #include <mono/metadata/profiler.h>
3 /*
4 * Bare bones profiler. Compile with:
5 *
6 * linux : gcc -shared -o mono-profiler-sample.so sample.c `pkg-config --cflags --libs mono`
7 * mac : gcc sample.c -o mono-profiler-sample.dylib -Dmono_free=free -lz `pkg-config --cflags mono-2` -undefined suppress -flat_namespace
9 * Install the binary where the dynamic loader can find it. eg /usr/lib etc
10 * Then run mono with:
11 * mono --profile=sample your_application.exe
13 * Note if you name a profiler with more than 8 characters (eg sample6789) appears to not work
16 struct _MonoProfiler {
17 int ncalls;
20 /* called at the end of the program */
21 static void
22 sample_shutdown (MonoProfiler *prof)
24 g_print ("total number of calls: %d\n", prof->ncalls);
27 static void
28 sample_method_enter (MonoProfiler *prof, MonoMethod *method)
30 prof->ncalls++;
33 static void
34 sample_method_leave (MonoProfiler *prof, MonoMethod *method)
38 /* the entry point */
39 void
40 mono_profiler_startup (const char *desc)
42 MonoProfiler *prof;
44 prof = g_new0 (MonoProfiler, 1);
46 mono_profiler_install (prof, sample_shutdown);
48 mono_profiler_install_enter_leave (sample_method_enter, sample_method_leave);
50 mono_profiler_set_events (MONO_PROFILE_ENTER_LEAVE);