[runtime] New profiler API.
[mono.git] / samples / profiler / sample.c
index 49af781a55a1001be19f135c4a7e8bf24192f597..75e2f779590a3d43267625f2650644de75be969c 100644 (file)
@@ -2,10 +2,15 @@
 
 /*
  * Bare bones profiler. Compile with:
- * gcc -shared -o mono-profiler-sample.so sample.c `pkg-config --cflags --libs mono`
- * Install the binary where the dynamic loader can find it.
+ * 
+ * linux : gcc -shared -o mono-profiler-sample.so sample.c `pkg-config --cflags --libs mono`
+ * mac : gcc sample.c -o mono-profiler-sample.dylib -Dmono_free=free -lz `pkg-config --cflags mono-2` -undefined suppress -flat_namespace  
+ *
+ * Install the binary where the dynamic loader can find it. eg /usr/lib etc
  * Then run mono with:
  * mono --profile=sample your_application.exe
+ *
+ * Note if you name a profiler with more than 8 characters (eg sample6789) appears to not work
  */
 
 struct _MonoProfiler {
@@ -30,19 +35,25 @@ sample_method_leave (MonoProfiler *prof, MonoMethod *method)
 {
 }
 
+static MonoProfilerCallInstrumentationFlags
+sample_instrumentation_filter (MonoProfiler *prof, MonoMethod *method)
+{
+       return MONO_PROFILER_CALL_INSTRUMENTATION_PROLOGUE | MONO_PROFILER_CALL_INSTRUMENTATION_EPILOGUE;
+}
+
 /* the entry point */
 void
-mono_profiler_startup (const char *desc)
+mono_profiler_init (const char *desc)
 {
        MonoProfiler *prof;
 
        prof = g_new0 (MonoProfiler, 1);
 
-       mono_profiler_install (prof, sample_shutdown);
-       
-       mono_profiler_install_enter_leave (sample_method_enter, sample_method_leave);
-
-       mono_profiler_set_events (MONO_PROFILE_ENTER_LEAVE);
+       MonoProfilerHandle handle = mono_profiler_install (prof);
+       mono_profiler_set_runtime_shutdown_callback (handle, sample_shutdown);
+       mono_profiler_set_call_instrumentation_filter_callback (handle, sample_instrumentation_filter);
+       mono_profiler_set_method_enter_callback (handle, sample_method_enter);
+       mono_profiler_set_method_leave_callback (handle, sample_method_leave);
 }