Imported Upstream version 5.10.0.47

Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-24 17:04:36 +00:00
parent 88ff76fe28
commit e46a49ecf1
5927 changed files with 226314 additions and 129848 deletions

View File

@@ -1,56 +1,76 @@
/*
* Bare bones profiler showing how a profiler module should be structured.
*
* Compilation:
* - Linux: gcc -fPIC -shared -o libmono-profiler-sample.so sample.c `pkg-config --cflags mono-2`
* - OS X: clang -undefined suppress -flat_namespace -o mono-profiler-sample.dylib sample.c `pkg-config --cflags mono-2`
*
* If you're using a custom prefix for your Mono installation (e.g. /opt/mono),
* pkg-config must be invoked like this: PKG_CONFIG_PATH=/opt/mono pkg-config --cflags mono-2
*
* Install the resulting shared library where the dynamic loader can find it,
* e.g. /usr/local/lib or /opt/mono (custom prefix).
*
* To use the module: mono --profile=sample hello.exe
*/
#include <mono/metadata/profiler.h>
/*
* Bare bones profiler. Compile with:
*
* linux : gcc -fPIC -shared -o libmono-profiler-sample.so sample.c `pkg-config --cflags --libs mono-2`
* mac : gcc -o mono-profiler-sample.dylib sample.c -lz `pkg-config --cflags mono-2` -undefined suppress -flat_namespace
* linux with a custom prefix (e.g. --prefix=/opt/my-mono-build):
* gcc -fPIC -shared -o libmono-profiler-sample.so sample.c `PKG_CONFIG_PATH=/opt/my-mono-build/lib/pkgconfig/ pkg-config --cflags --libs mono-2`
*
* Install the binary where the dynamic loader can find it. eg /usr/lib etc.
* For a custom prefix build, <prefix>/lib would also work.
* 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
* Defining a type called _MonoProfiler will complete the opaque MonoProfiler
* type, which is used throughout the profiler API.
*/
struct _MonoProfiler {
/* Handle obtained from mono_profiler_create (). */
MonoProfilerHandle handle;
/* Counts the number of calls observed. */
unsigned long long ncalls;
};
static MonoProfiler prof_instance;
/*
* Use static storage for the profiler structure for simplicity. The structure
* can be allocated dynamically as well, if needed.
*/
static MonoProfiler profiler;
/* called at the end of the program */
/*
* Callback invoked after the runtime finishes shutting down. Managed code can
* no longer run and most runtime services are unavailable.
*/
static void
sample_shutdown (MonoProfiler *prof)
sample_shutdown_end (MonoProfiler *prof)
{
printf("total number of calls: %llu\n", prof->ncalls);
printf ("Total number of calls: %llu\n", prof->ncalls);
}
/*
* Method enter callback invoked on entry to all instrumented methods.
*/
static void
sample_method_enter (MonoProfiler *prof, MonoMethod *method, MonoProfilerCallContext *ctx)
{
prof->ncalls++;
}
/*
* Filter callback that decides which methods to instrument and how.
*/
static MonoProfilerCallInstrumentationFlags
sample_instrumentation_filter (MonoProfiler *prof, MonoMethod *method)
sample_call_instrumentation_filter (MonoProfiler *prof, MonoMethod *method)
{
return MONO_PROFILER_CALL_INSTRUMENTATION_ENTER;
}
/* the entry point */
/*
* The entry point function invoked by the Mono runtime.
*/
void
mono_profiler_init_sample (const char *desc)
{
MonoProfiler *prof = &prof_instance;
profiler.handle = mono_profiler_create (&profiler);
MonoProfilerHandle handle = mono_profiler_create (prof);
mono_profiler_set_runtime_shutdown_end_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_runtime_shutdown_end_callback (profiler.handle, sample_shutdown_end);
mono_profiler_set_call_instrumentation_filter_callback (profiler.handle, sample_call_instrumentation_filter);
mono_profiler_set_method_enter_callback (profiler.handle, sample_method_enter);
}