diff options
author | Paolo Molaro <lupus@oddwiz.org> | 2003-06-05 22:08:01 +0400 |
---|---|---|
committer | Paolo Molaro <lupus@oddwiz.org> | 2003-06-05 22:08:01 +0400 |
commit | c19e0bae313b58b3047fb2172ea4b294b48e14c1 (patch) | |
tree | 70c9982e74b5eaa0a3a98914a23eb90bae71f99f /samples | |
parent | 20693e93ead6949fdfef94b6d498007d2b65801b (diff) |
Bare-bones sample loadable profiler.
svn path=/trunk/mono/; revision=15129
Diffstat (limited to 'samples')
-rw-r--r-- | samples/profiler/sample.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/samples/profiler/sample.c b/samples/profiler/sample.c new file mode 100644 index 00000000000..49af781a55a --- /dev/null +++ b/samples/profiler/sample.c @@ -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); +} + + |