* Author:
* Paolo Molaro (lupus@ximian.com)
*
- * (C) 2001-2003 Ximian, Inc.
- * (C) 2003-2006 Novell, Inc.
+ * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
*/
#include "config.h"
static MonoProfileMethodFunc jit_start;
static MonoProfileMethodResult jit_end;
static MonoProfileJitResult jit_end2;
+static MonoProfileMethodFunc method_free;
static MonoProfileMethodResult man_unman_transition;
static MonoProfileAllocFunc allocation_cb;
static MonoProfileStatFunc statistical_cb;
+static MonoProfileStatCallChainFunc statistical_call_chain_cb;
+static int statistical_call_chain_depth;
static MonoProfileMethodFunc method_enter;
static MonoProfileMethodFunc method_leave;
static MonoProfileGCFunc gc_event;
static MonoProfileGCResizeFunc gc_heap_resize;
+static MonoProfileFunc runtime_initialized_event;
+
#define mono_profiler_coverage_lock() EnterCriticalSection (&profiler_coverage_mutex)
#define mono_profiler_coverage_unlock() LeaveCriticalSection (&profiler_coverage_mutex)
static CRITICAL_SECTION profiler_coverage_mutex;
jit_end2 = end;
}
+void
+mono_profiler_install_method_free (MonoProfileMethodFunc callback)
+{
+ method_free = callback;
+}
+
void
mono_profiler_install_thread (MonoProfileThreadFunc start, MonoProfileThreadFunc end)
{
statistical_cb = callback;
}
+void
+mono_profiler_install_statistical_call_chain (MonoProfileStatCallChainFunc callback, int call_chain_depth) {
+ statistical_call_chain_cb = callback;
+ statistical_call_chain_depth = call_chain_depth;
+ if (statistical_call_chain_depth > MONO_PROFILER_MAX_STAT_CALL_CHAIN_DEPTH) {
+ statistical_call_chain_depth = MONO_PROFILER_MAX_STAT_CALL_CHAIN_DEPTH;
+ }
+}
+
+int
+mono_profiler_stat_get_call_chain_depth (void) {
+ if (statistical_call_chain_cb != NULL) {
+ return statistical_call_chain_depth;
+ } else {
+ return 0;
+ }
+}
+
void mono_profiler_install_exception (MonoProfileExceptionFunc throw_callback, MonoProfileMethodFunc exc_method_leave, MonoProfileExceptionClauseFunc clause_callback)
{
exception_throw_cb = throw_callback;
}
}
+void
+mono_profiler_method_free (MonoMethod *method)
+{
+ if ((mono_profiler_events & MONO_PROFILE_METHOD_EVENTS) && method_free)
+ method_free (current_profiler, method);
+}
+
void
mono_profiler_code_transition (MonoMethod *method, int result)
{
statistical_cb (current_profiler, ip, context);
}
+void
+mono_profiler_stat_call_chain (int call_chain_depth, guchar **ips, void *context)
+{
+ if ((mono_profiler_events & MONO_PROFILE_STATISTICAL) && statistical_call_chain_cb)
+ statistical_call_chain_cb (current_profiler, call_chain_depth, ips, context);
+}
+
void
mono_profiler_exception_thrown (MonoObject *exception)
{
gc_heap_resize = heap_resize_callback;
}
+void
+mono_profiler_install_runtime_initialized (MonoProfileFunc runtime_initialized_callback)
+{
+ runtime_initialized_event = runtime_initialized_callback;
+}
+
+void
+mono_profiler_runtime_initialized (void) {
+ if (runtime_initialized_event)
+ runtime_initialized_event (current_profiler);
+}
+
+
static GHashTable *coverage_hash = NULL;
MonoProfileCoverageInfo*
m = method_get_name (p->method);
fprintf (poutput, "########################\n");
fprintf (poutput, "% 8.3f ", (double) (p->total * 1000));
- fprintf (poutput, "%7" G_GUINT64_FORMAT " ", (unsigned long long)p->count);
+ fprintf (poutput, "%7" G_GUINT64_FORMAT " ", (guint64)p->count);
fprintf (poutput, "% 8.3f ", (double) (p->total * 1000)/(double)p->count);
fprintf (poutput, " %s\n", m);
/* callers */
output_callers (p);
}
- fprintf (poutput, "Total number of calls: %" G_GINT64_FORMAT "\n", (long long)total_calls);
+ fprintf (poutput, "Total number of calls: %" G_GINT64_FORMAT "\n", (gint64)total_calls);
}
typedef struct {
simple_appdomain_unload (MonoProfiler *prof, MonoDomain *domain)
{
/* FIXME: we should actually record partial data for each domain,
- * since the ip->ji->method mappings are going away at domain unload time.
+ * but at this point it's must easier using the new logging profiler.
*/
- if (domain == mono_get_root_domain ())
- stat_prof_report ();
+ mono_profiler_shutdown ();
}
+static gint32 simple_shutdown_done = FALSE;
+
static void
simple_shutdown (MonoProfiler *prof)
{
MonoProfiler *tprof;
GSList *tmp;
char *str;
+ gint32 see_shutdown_done;
+
+#ifndef PLATFORM_WIN32
+ mono_thread_attach(mono_get_root_domain());
+#endif
+
+ // Make sure we execute simple_shutdown only once
+ see_shutdown_done = InterlockedExchange(& simple_shutdown_done, TRUE);
+ if (see_shutdown_done)
+ return;
+ if (mono_profiler_events & MONO_PROFILE_STATISTICAL) {
+ stat_prof_report ();
+ }
+
+ // Stop all incoming events
+ mono_profiler_set_events (0);
+
for (tmp = prof->per_thread; tmp; tmp = tmp->next) {
tprof = tmp->data;
merge_thread_data (prof, tprof);
for (ptr = args; ptr && *ptr; ptr++) {
const char *arg = *ptr;
+ // Alwais listen to appdomaon events to shutdown at the first unload
+ flags |= MONO_PROFILE_APPDOMAIN_EVENTS;
if (!strcmp (arg, "time"))
flags |= MONO_PROFILE_ENTER_LEAVE | MONO_PROFILE_EXCEPTIONS;
else if (!strcmp (arg, "alloc"))
flags |= MONO_PROFILE_ALLOCATIONS;
else if (!strcmp (arg, "stat"))
- flags |= MONO_PROFILE_STATISTICAL | MONO_PROFILE_APPDOMAIN_EVENTS;
+ flags |= MONO_PROFILE_STATISTICAL;
else if (!strcmp (arg, "jit"))
flags |= MONO_PROFILE_JIT_COMPILATION;
else if (strncmp (arg, "file=", 5) == 0) {