2
0

sample.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <mono/metadata/profiler.h>
  2. /*
  3. * Bare bones profiler. Compile with:
  4. *
  5. * linux : gcc -shared -o mono-profiler-sample.so sample.c `pkg-config --cflags --libs mono`
  6. * mac : gcc sample.c -o mono-profiler-sample.dylib -Dmono_free=free -lz `pkg-config --cflags mono-2` -undefined suppress -flat_namespace
  7. *
  8. * Install the binary where the dynamic loader can find it. eg /usr/lib etc
  9. * Then run mono with:
  10. * mono --profile=sample your_application.exe
  11. *
  12. * Note if you name a profiler with more than 8 characters (eg sample6789) appears to not work
  13. */
  14. struct _MonoProfiler {
  15. int ncalls;
  16. };
  17. /* called at the end of the program */
  18. static void
  19. sample_shutdown (MonoProfiler *prof)
  20. {
  21. g_print ("total number of calls: %d\n", prof->ncalls);
  22. }
  23. static void
  24. sample_method_enter (MonoProfiler *prof, MonoMethod *method)
  25. {
  26. prof->ncalls++;
  27. }
  28. static void
  29. sample_method_leave (MonoProfiler *prof, MonoMethod *method)
  30. {
  31. }
  32. /* the entry point */
  33. void
  34. mono_profiler_startup (const char *desc)
  35. {
  36. MonoProfiler *prof;
  37. prof = g_new0 (MonoProfiler, 1);
  38. mono_profiler_install (prof, sample_shutdown);
  39. mono_profiler_install_enter_leave (sample_method_enter, sample_method_leave);
  40. mono_profiler_set_events (MONO_PROFILE_ENTER_LEAVE);
  41. }