sample.c 974 B

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