Bare-bones sample loadable profiler.
authorPaolo Molaro <lupus@oddwiz.org>
Thu, 5 Jun 2003 18:08:01 +0000 (18:08 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Thu, 5 Jun 2003 18:08:01 +0000 (18:08 -0000)
svn path=/trunk/mono/; revision=15129

samples/profiler/sample.c [new file with mode: 0644]

diff --git a/samples/profiler/sample.c b/samples/profiler/sample.c
new file mode 100644 (file)
index 0000000..49af781
--- /dev/null
@@ -0,0 +1,48 @@
+#include <mono/metadata/profiler.h>
+
+/*
+ * 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.
+ * Then run mono with:
+ * mono --profile=sample your_application.exe
+ */
+
+struct _MonoProfiler {
+       int ncalls;
+};
+
+/* called at the end of the program */
+static void
+sample_shutdown (MonoProfiler *prof)
+{
+       g_print ("total number of calls: %d\n", prof->ncalls);
+}
+
+static void
+sample_method_enter (MonoProfiler *prof, MonoMethod *method)
+{
+       prof->ncalls++;
+}
+
+static void
+sample_method_leave (MonoProfiler *prof, MonoMethod *method)
+{
+}
+
+/* the entry point */
+void
+mono_profiler_startup (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);
+}
+
+