X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fprofiler-private.h;h=38e353b5b35b30f08789a6804df6fff176775f5e;hb=f9ae98ab88f522219cd6be6fd282ef30adbc5365;hp=5888b90fca925bdcfd35082990fa52a0fa83fb4d;hpb=12461baf50da00c5d30f757af0e1891d7ebbef3b;p=mono.git diff --git a/mono/metadata/profiler-private.h b/mono/metadata/profiler-private.h index 5888b90fca9..38e353b5b35 100644 --- a/mono/metadata/profiler-private.h +++ b/mono/metadata/profiler-private.h @@ -1,88 +1,172 @@ +/* + * Licensed to the .NET Foundation under one or more agreements. + * The .NET Foundation licenses this file to you under the MIT license. + * See the LICENSE file in the project root for more information. + */ #ifndef __MONO_PROFILER_PRIVATE_H__ #define __MONO_PROFILER_PRIVATE_H__ +#define MONO_PROFILER_UNSTABLE_GC_ROOTS #include -#include "mono/utils/mono-compiler.h" -#include - -extern MonoProfileFlags mono_profiler_events; - -enum { - MONO_PROFILE_START_LOAD, - MONO_PROFILE_END_LOAD, - MONO_PROFILE_START_UNLOAD, - MONO_PROFILE_END_UNLOAD +#include +#include +#include +#include + +struct _MonoProfilerDesc { + MonoProfilerHandle next; + MonoProfiler *prof; + volatile gpointer coverage_filter; + volatile gpointer call_instrumentation_filter; + +#define _MONO_PROFILER_EVENT(name) \ + volatile gpointer name ## _cb; +#define MONO_PROFILER_EVENT_0(name, type) \ + _MONO_PROFILER_EVENT(name) +#define MONO_PROFILER_EVENT_1(name, type, arg1_type, arg1_name) \ + _MONO_PROFILER_EVENT(name) +#define MONO_PROFILER_EVENT_2(name, type, arg1_type, arg1_name, arg2_type, arg2_name) \ + _MONO_PROFILER_EVENT(name) +#define MONO_PROFILER_EVENT_3(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name) \ + _MONO_PROFILER_EVENT(name) +#define MONO_PROFILER_EVENT_4(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name) \ + _MONO_PROFILER_EVENT(name) +#include +#undef MONO_PROFILER_EVENT_0 +#undef MONO_PROFILER_EVENT_1 +#undef MONO_PROFILER_EVENT_2 +#undef MONO_PROFILER_EVENT_3 +#undef MONO_PROFILER_EVENT_4 +#undef _MONO_PROFILER_EVENT }; typedef struct { - int entries; - struct { - guchar* cil_code; - int count; - } data [1]; -} MonoProfileCoverageInfo; - -void mono_profiler_shutdown (void); - -void mono_profiler_method_enter (MonoMethod *method); -void mono_profiler_method_leave (MonoMethod *method); -void mono_profiler_method_jit (MonoMethod *method); -void mono_profiler_method_end_jit (MonoMethod *method, MonoJitInfo* jinfo, int result); -void mono_profiler_method_free (MonoMethod *method); -void mono_profiler_method_start_invoke (MonoMethod *method); -void mono_profiler_method_end_invoke (MonoMethod *method); - -void mono_profiler_code_transition (MonoMethod *method, int result); -void mono_profiler_allocation (MonoObject *obj); -void mono_profiler_monitor_event (MonoObject *obj, MonoProfilerMonitorEvent event); -void mono_profiler_stat_hit (guchar *ip, void *context); -void mono_profiler_stat_call_chain (int call_chain_depth, guchar **ips, void *context); -int mono_profiler_stat_get_call_chain_depth (void); -MonoProfilerCallChainStrategy mono_profiler_stat_get_call_chain_strategy (void); -void mono_profiler_thread_start (gsize tid); -void mono_profiler_thread_end (gsize tid); -void mono_profiler_thread_name (gsize tid, const char *name); - -void mono_profiler_exception_thrown (MonoObject *exception); -void mono_profiler_exception_method_leave (MonoMethod *method); -void mono_profiler_exception_clause_handler (MonoMethod *method, int clause_type, int clause_num); - -void mono_profiler_assembly_event (MonoAssembly *assembly, int code); -void mono_profiler_assembly_loaded (MonoAssembly *assembly, int result); - -void mono_profiler_module_event (MonoImage *image, int code); -void mono_profiler_module_loaded (MonoImage *image, int result); - -void mono_profiler_class_event (MonoClass *klass, int code); -void mono_profiler_class_loaded (MonoClass *klass, int result); - -void mono_profiler_appdomain_event (MonoDomain *domain, int code); -void mono_profiler_appdomain_loaded (MonoDomain *domain, int result); -void mono_profiler_appdomain_name (MonoDomain *domain, const char *name); + gboolean startup_done; + + MonoProfilerHandle profilers; + + mono_lazy_init_t coverage_status; + mono_mutex_t coverage_mutex; + GHashTable *coverage_hash; + + MonoProfilerHandle sampling_owner; + MonoSemType sampling_semaphore; + MonoProfilerSampleMode sample_mode; + guint32 sample_freq; + + gboolean allocations; + + gboolean call_contexts; + void (*context_enable) (void); + gpointer (*context_get_this) (MonoProfilerCallContext *); + gpointer (*context_get_argument) (MonoProfilerCallContext *, guint32); + gpointer (*context_get_local) (MonoProfilerCallContext *, guint32); + gpointer (*context_get_result) (MonoProfilerCallContext *); + gpointer (*context_free_buffer) (gpointer); + +#define _MONO_PROFILER_EVENT(name) \ + volatile gint32 name ## _count; +#define MONO_PROFILER_EVENT_0(name, type) \ + _MONO_PROFILER_EVENT(name) +#define MONO_PROFILER_EVENT_1(name, type, arg1_type, arg1_name) \ + _MONO_PROFILER_EVENT(name) +#define MONO_PROFILER_EVENT_2(name, type, arg1_type, arg1_name, arg2_type, arg2_name) \ + _MONO_PROFILER_EVENT(name) +#define MONO_PROFILER_EVENT_3(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name) \ + _MONO_PROFILER_EVENT(name) +#define MONO_PROFILER_EVENT_4(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name) \ + _MONO_PROFILER_EVENT(name) +#include +#undef MONO_PROFILER_EVENT_0 +#undef MONO_PROFILER_EVENT_1 +#undef MONO_PROFILER_EVENT_2 +#undef MONO_PROFILER_EVENT_3 +#undef MONO_PROFILER_EVENT_4 +#undef _MONO_PROFILER_EVENT +} MonoProfilerState; + +extern MonoProfilerState mono_profiler_state; -void mono_profiler_context_loaded (MonoAppContext *context); -void mono_profiler_context_unloaded (MonoAppContext *context); - -void mono_profiler_iomap (char *report, const char *pathname, const char *new_pathname); - -MonoProfileCoverageInfo* mono_profiler_coverage_alloc (MonoMethod *method, int entries); -void mono_profiler_coverage_free (MonoMethod *method); - -void mono_profiler_gc_event (MonoGCEvent e, int generation); -void mono_profiler_gc_heap_resize (gint64 new_size); -void mono_profiler_gc_moves (void **objects, int num); -void mono_profiler_gc_handle (int op, int type, uintptr_t handle, MonoObject *obj); -void mono_profiler_gc_roots (int num, void **objects, int *root_types, uintptr_t *extra_info); - -void mono_profiler_code_chunk_new (gpointer chunk, int size); -void mono_profiler_code_chunk_destroy (gpointer chunk); -void mono_profiler_code_buffer_new (gpointer buffer, int size, MonoProfilerCodeBufferType type, gconstpointer data); - -void mono_profiler_runtime_initialized (void); - -int64_t mono_profiler_get_sampling_rate (void); -MonoProfileSamplingMode mono_profiler_get_sampling_mode (void); - -#endif /* __MONO_PROFILER_PRIVATE_H__ */ +typedef struct { + guint32 entries; + struct { + guchar *cil_code; + guint32 count; + } data [1]; +} MonoProfilerCoverageInfo; + +void mono_profiler_started (void); +void mono_profiler_cleanup (void); + +static inline gboolean +mono_profiler_installed (void) +{ + return !!mono_profiler_state.profilers; +} + +MonoProfilerCoverageInfo *mono_profiler_coverage_alloc (MonoMethod *method, guint32 entries); +void mono_profiler_coverage_free (MonoMethod *method); + +struct _MonoProfilerCallContext { + /* + * Must be the first field (the JIT relies on it). Only filled out if this + * is a JIT frame; otherwise, zeroed. + */ + MonoContext context; + /* + * A non-NULL MonoInterpFrameHandle if this is an interpreter frame. + */ + gpointer interp_frame; + MonoMethod *method; + /* + * Points to the return value for an epilogue context. For a prologue, this + * is set to NULL. + */ + gpointer return_value; +}; +MonoProfilerCallInstrumentationFlags mono_profiler_get_call_instrumentation_flags (MonoMethod *method); + +gboolean mono_profiler_sampling_enabled (void); +void mono_profiler_sampling_thread_post (void); +void mono_profiler_sampling_thread_wait (void); + +static inline gboolean +mono_profiler_allocations_enabled (void) +{ + return mono_profiler_state.allocations; +} + +#define _MONO_PROFILER_EVENT(name, ...) \ + void mono_profiler_raise_ ## name (__VA_ARGS__); +#define MONO_PROFILER_EVENT_0(name, type) \ + _MONO_PROFILER_EVENT(name, void) +#define MONO_PROFILER_EVENT_1(name, type, arg1_type, arg1_name) \ + _MONO_PROFILER_EVENT(name, arg1_type arg1_name) +#define MONO_PROFILER_EVENT_2(name, type, arg1_type, arg1_name, arg2_type, arg2_name) \ + _MONO_PROFILER_EVENT(name, arg1_type arg1_name, arg2_type arg2_name) +#define MONO_PROFILER_EVENT_3(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name) \ + _MONO_PROFILER_EVENT(name, arg1_type arg1_name, arg2_type arg2_name, arg3_type arg3_name) +#define MONO_PROFILER_EVENT_4(name, type, arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name, arg4_type, arg4_name) \ + _MONO_PROFILER_EVENT(name, arg1_type arg1_name, arg2_type arg2_name, arg3_type arg3_name, arg4_type arg4_name) +#include +#undef MONO_PROFILER_EVENT_0 +#undef MONO_PROFILER_EVENT_1 +#undef MONO_PROFILER_EVENT_2 +#undef MONO_PROFILER_EVENT_3 +#undef MONO_PROFILER_EVENT_4 +#undef _MONO_PROFILER_EVENT + +// These are the macros the rest of the runtime should use. + +#define MONO_PROFILER_ENABLED(name) \ + G_UNLIKELY (mono_profiler_state.name ## _count) + +#define MONO_PROFILER_RAISE(name, args) \ + do { \ + if (MONO_PROFILER_ENABLED (name)) \ + mono_profiler_raise_ ## name args; \ + } while (0) + +#endif // __MONO_PROFILER_PRIVATE_H__