Skip to content
Browse files

Implement the runtime side of disabling performance counters.

  • Loading branch information...
1 parent 1d4d9f9 commit cd474ecbbf2ec950b5c3b83eb7b3618961a40ff4 @kumpera kumpera committed Nov 7, 2012
View
8 mono/metadata/boehm-gc.c
@@ -208,7 +208,9 @@ mono_gc_collect (int generation)
{
MONO_GC_BEGIN (generation);
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->gc_induced++;
+#endif
GC_gcollect ();
MONO_GC_END (generation);
@@ -410,11 +412,14 @@ on_gc_notification (GCEventType event)
mono_thread_info_suspend_unlock ();
if (e == MONO_GC_EVENT_START) {
+#ifndef DISABLE_PERFCOUNTERS
if (mono_perfcounters)
mono_perfcounters->gc_collections0++;
+#endif
gc_stats.major_gc_count ++;
gc_start_time = mono_100ns_ticks ();
} else if (e == MONO_GC_EVENT_END) {
+#ifndef DISABLE_PERFCOUNTERS
if (mono_perfcounters) {
guint64 heap_size = GC_get_heap_size ();
guint64 used_size = heap_size - GC_get_free_bytes ();
@@ -423,6 +428,7 @@ on_gc_notification (GCEventType event)
mono_perfcounters->gc_reserved_bytes = heap_size;
mono_perfcounters->gc_gen0size = heap_size;
}
+#endif
gc_stats.major_gc_time_usecs += (mono_100ns_ticks () - gc_start_time) / 10;
mono_trace_message (MONO_TRACE_GC, "gc took %d usecs", (mono_100ns_ticks () - gc_start_time) / 10);
}
@@ -433,11 +439,13 @@ static void
on_gc_heap_resize (size_t new_size)
{
guint64 heap_size = GC_get_heap_size ();
+#ifndef DISABLE_PERFCOUNTERS
if (mono_perfcounters) {
mono_perfcounters->gc_committed_bytes = heap_size;
mono_perfcounters->gc_reserved_bytes = heap_size;
mono_perfcounters->gc_gen0size = heap_size;
}
+#endif
mono_profiler_gc_heap_resize (new_size);
}
View
12 mono/metadata/domain.c
@@ -1227,8 +1227,10 @@ mono_domain_create (void)
domain_id_alloc (domain);
mono_appdomains_unlock ();
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->loader_appdomains++;
mono_perfcounters->loader_total_appdomains++;
+#endif
mono_debug_domain_create (domain);
@@ -1274,7 +1276,9 @@ mono_init_internal (const char *filename, const char *exe_filename, const char *
wapi_init ();
#endif
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters_init ();
+#endif
mono_counters_register ("Max native code in a domain", MONO_COUNTER_INT|MONO_COUNTER_JIT, &max_domain_code_size);
mono_counters_register ("Max code space allocated in a domain", MONO_COUNTER_INT|MONO_COUNTER_JIT, &max_domain_code_alloc);
@@ -2050,7 +2054,9 @@ mono_domain_free (MonoDomain *domain, gboolean force)
mono_mempool_invalidate (domain->mp);
mono_code_manager_invalidate (domain->code_mp);
#else
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->loader_bytes -= mono_mempool_get_allocated (domain->mp);
+#endif
mono_mempool_destroy (domain->mp);
domain->mp = NULL;
mono_code_manager_destroy (domain->code_mp);
@@ -2094,7 +2100,9 @@ mono_domain_free (MonoDomain *domain, gboolean force)
mono_gc_free_fixed (domain);
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->loader_appdomains--;
+#endif
if (domain == mono_root_domain)
mono_root_domain = NULL;
@@ -2138,7 +2146,9 @@ mono_domain_alloc (MonoDomain *domain, guint size)
gpointer res;
mono_domain_lock (domain);
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->loader_bytes += size;
+#endif
res = mono_mempool_alloc (domain->mp, size);
mono_domain_unlock (domain);
@@ -2156,7 +2166,9 @@ mono_domain_alloc0 (MonoDomain *domain, guint size)
gpointer res;
mono_domain_lock (domain);
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->loader_bytes += size;
+#endif
res = mono_mempool_alloc0 (domain->mp, size);
mono_domain_unlock (domain);
View
4 mono/metadata/gc.c
@@ -733,7 +733,9 @@ alloc_handle (HandleData *handles, MonoObject *obj, gboolean track)
mono_gc_weak_link_add (&(handles->entries [slot]), obj, track);
}
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->gc_num_handles++;
+#endif
unlock_handles (handles);
/*g_print ("allocated entry %d of type %d to object %p (in slot: %p)\n", slot, handles->type, obj, handles->entries [slot]);*/
res = (slot << 3) | (handles->type + 1);
@@ -941,7 +943,9 @@ mono_gchandle_free (guint32 gchandle)
} else {
/* print a warning? */
}
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->gc_num_handles--;
+#endif
/*g_print ("freed entry %d of type %d\n", slot, handles->type);*/
unlock_handles (handles);
mono_profiler_gc_handle (MONO_PROFILER_GC_HANDLE_DESTROYED, handles->type, gchandle, NULL);
View
8 mono/metadata/image.c
@@ -1729,7 +1729,9 @@ mono_image_close_finish (MonoImage *image)
if (image->modules)
g_free (image->modules);
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->loader_bytes -= mono_mempool_get_allocated (image->mempool);
+#endif
if (!image->dynamic) {
if (debug_assembly_unload)
@@ -2225,7 +2227,9 @@ mono_image_alloc (MonoImage *image, guint size)
{
gpointer res;
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->loader_bytes += size;
+#endif
mono_image_lock (image);
res = mono_mempool_alloc (image->mempool, size);
mono_image_unlock (image);
@@ -2238,7 +2242,9 @@ mono_image_alloc0 (MonoImage *image, guint size)
{
gpointer res;
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->loader_bytes += size;
+#endif
mono_image_lock (image);
res = mono_mempool_alloc0 (image->mempool, size);
mono_image_unlock (image);
@@ -2251,7 +2257,9 @@ mono_image_strdup (MonoImage *image, const char *s)
{
char *res;
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->loader_bytes += strlen (s);
+#endif
mono_image_lock (image);
res = mono_mempool_strdup (image->mempool, s);
mono_image_unlock (image);
View
10 mono/metadata/monitor.c
@@ -242,7 +242,9 @@ mon_finalize (MonoThreadsSync *mon)
mon->data = monitor_freelist;
monitor_freelist = mon;
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->gc_sync_blocks--;
+#endif
}
/* LOCKING: this is called with monitor_mutex held */
@@ -310,7 +312,9 @@ mon_new (gsize id)
new->owner = id;
new->nest = 1;
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->gc_sync_blocks++;
+#endif
return new;
}
@@ -536,7 +540,9 @@ mono_monitor_try_enter_internal (MonoObject *obj, guint32 ms, gboolean allow_int
}
/* The object must be locked by someone else... */
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->thread_contentions++;
+#endif
/* If ms is 0 we don't block, but just fail straight away */
if (ms == 0) {
@@ -612,8 +618,10 @@ mono_monitor_try_enter_internal (MonoObject *obj, guint32 ms, gboolean allow_int
InterlockedIncrement (&mon->entry_count);
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->thread_queue_len++;
mono_perfcounters->thread_queue_max++;
+#endif
thread = mono_thread_internal_current ();
mono_thread_set_state (thread, ThreadState_WaitSleepJoin);
@@ -627,7 +635,9 @@ mono_monitor_try_enter_internal (MonoObject *obj, guint32 ms, gboolean allow_int
mono_thread_clr_state (thread, ThreadState_WaitSleepJoin);
InterlockedDecrement (&mon->entry_count);
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->thread_queue_len--;
+#endif
if (ms != INFINITE) {
now = mono_msec_ticks ();
View
74 mono/metadata/mono-perfcounters.c
@@ -52,6 +52,7 @@ struct _MonoCounterSample {
int counterType;
};
+#ifndef DISABLE_PERFCOUNTERS
/* map of PerformanceCounterType.cs */
enum {
NumberOfItemsHEX32=0x00000000,
@@ -1689,4 +1690,77 @@ mono_perfcounter_instance_names (MonoString *category, MonoString *machine)
return mono_array_new (mono_domain_get (), mono_get_string_class (), 0);
}
}
+#else
+void*
+mono_perfcounter_get_impl (MonoString* category, MonoString* counter, MonoString* instance, MonoString* machine, int *type, MonoBoolean *custom)
+{
+ g_assert_not_reached ();
+}
+
+MonoBoolean
+mono_perfcounter_get_sample (void *impl, MonoBoolean only_value, MonoCounterSample *sample)
+{
+ g_assert_not_reached ();
+}
+
+gint64
+mono_perfcounter_update_value (void *impl, MonoBoolean do_incr, gint64 value)
+{
+ g_assert_not_reached ();
+}
+
+void
+mono_perfcounter_free_data (void *impl)
+{
+ g_assert_not_reached ();
+}
+
+/* Category icalls */
+MonoBoolean
+mono_perfcounter_category_del (MonoString *name)
+{
+ g_assert_not_reached ();
+}
+
+MonoString*
+mono_perfcounter_category_help (MonoString *category, MonoString *machine)
+{
+ g_assert_not_reached ();
+}
+MonoBoolean
+mono_perfcounter_category_exists (MonoString *counter, MonoString *category, MonoString *machine)
+{
+ g_assert_not_reached ();
+}
+
+MonoBoolean
+mono_perfcounter_create (MonoString *category, MonoString *help, int type, MonoArray *items)
+{
+ g_assert_not_reached ();
+}
+
+int
+mono_perfcounter_instance_exists (MonoString *instance, MonoString *category, MonoString *machine)
+{
+ g_assert_not_reached ();
+}
+
+MonoArray*
+mono_perfcounter_category_names (MonoString *machine)
+{
+ g_assert_not_reached ();
+}
+
+MonoArray*
+mono_perfcounter_counter_names (MonoString *category, MonoString *machine)
+{
+ g_assert_not_reached ();
+}
+
+MonoArray*
+mono_perfcounter_instance_names (MonoString *category, MonoString *machine)
+{
+ g_assert_not_reached ();
+}
+#endif
View
2 mono/metadata/object.c
@@ -2538,7 +2538,9 @@ mono_remote_class (MonoDomain *domain, MonoString *class_name, MonoClass *proxy_
rc->default_vtable = NULL;
rc->xdomain_vtable = NULL;
rc->proxy_class_name = name;
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->loader_bytes += mono_string_length (class_name) + 1;
+#endif
g_hash_table_insert (domain->proxy_vtable_hash, key, rc);
View
2 mono/metadata/pedump.c
@@ -649,7 +649,9 @@ main (int argc, char *argv [])
if (!file)
usage ();
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters_init ();
+#endif
mono_metadata_init ();
mono_images_init ();
mono_assemblies_init ();
View
4 mono/metadata/sgen-gc.c
@@ -2293,7 +2293,9 @@ collect_nursery (void)
verify_nursery ();
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->gc_collections0++;
+#endif
current_collection_generation = GENERATION_NURSERY;
if (sgen_collection_is_parallel ())
@@ -2537,7 +2539,9 @@ major_do_collection (const char *reason)
MONO_GC_BEGIN (GENERATION_OLD);
current_collection_generation = GENERATION_OLD;
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->gc_collections1++;
+#endif
current_object_ops = major_collector.major_ops;
View
12 mono/metadata/threadpool.c
@@ -683,7 +683,9 @@ threadpool_start_idle_threads (ThreadPool *tp)
if (InterlockedCompareExchange (&tp->nthreads, n + 1, n) == n)
break;
}
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
+#endif
mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, stack_size);
SleepEx (100, TRUE);
} while (1);
@@ -700,6 +702,7 @@ threadpool_init (ThreadPool *tp, int min_threads, int max_threads, void (*async_
MONO_SEM_INIT (&tp->new_job, 0);
}
+#ifndef DISABLE_PERFCOUNTERS
static void *
init_perf_counter (const char *category, const char *counter)
{
@@ -718,6 +721,7 @@ init_perf_counter (const char *category, const char *counter)
machine = mono_string_new (root, ".");
return mono_perfcounter_get_impl (category_str, counter_str, NULL, machine, &type, &custom);
}
+#endif
#ifdef DEBUG
static void
@@ -856,6 +860,7 @@ mono_thread_pool_init ()
wsqs = g_ptr_array_sized_new (MAX (100 * cpu_count, thread_count));
mono_wsq_init ();
+#ifndef DISABLE_PERFCOUNTERS
async_tp.pc_nitems = init_perf_counter ("Mono Threadpool", "Work Items Added");
g_assert (async_tp.pc_nitems);
@@ -867,6 +872,7 @@ mono_thread_pool_init ()
async_io_tp.pc_nthreads = init_perf_counter ("Mono Threadpool", "# of IO Threads");
g_assert (async_io_tp.pc_nthreads);
+#endif
tp_inited = 2;
#ifdef DEBUG
signal (SIGALRM, signal_handler);
@@ -1019,7 +1025,9 @@ threadpool_start_thread (ThreadPool *tp)
stack_size = (!tp->is_io) ? 0 : SMALL_STACK;
while (!mono_runtime_is_shutting_down () && (n = tp->nthreads) < tp->max_threads) {
if (InterlockedCompareExchange (&tp->nthreads, n + 1, n) == n) {
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
+#endif
mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, stack_size);
return TRUE;
}
@@ -1077,7 +1085,9 @@ threadpool_append_jobs (ThreadPool *tp, MonoObject **jobs, gint njobs)
o->add_time = mono_100ns_ticks ();
}
threadpool_jobs_inc (ar);
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounter_update_value (tp->pc_nitems, TRUE, 1);
+#endif
if (!tp->is_io && mono_wsq_local_push (ar))
continue;
@@ -1545,7 +1555,9 @@ async_invoke_thread (gpointer data)
if (!down && nt <= tp->min_threads)
break;
if (down || InterlockedCompareExchange (&tp->nthreads, nt - 1, nt) == nt) {
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounter_update_value (tp->pc_nthreads, TRUE, -1);
+#endif
if (!tp->is_io) {
remove_wsq (wsq);
}
View
8 mono/mini/mini-exceptions.c
@@ -1366,7 +1366,9 @@ mono_handle_exception_internal_first_pass (MonoContext *ctx, gpointer obj, gint3
if (ei->flags == MONO_EXCEPTION_CLAUSE_FILTER) {
gboolean is_user_frame = ji->method->wrapper_type == MONO_WRAPPER_NONE || ji->method->wrapper_type == MONO_WRAPPER_DYNAMIC_METHOD;
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->exceptions_filters++;
+#endif
mono_debugger_call_exception_handler (ei->data.filter, MONO_CONTEXT_GET_SP (ctx), ex_obj);
/*
@@ -1723,7 +1725,9 @@ mono_handle_exception_internal (MonoContext *ctx, gpointer obj, gboolean resume,
mono_debugger_call_exception_handler (ei->handler_start, MONO_CONTEXT_GET_SP (ctx), ex_obj);
MONO_CONTEXT_SET_IP (ctx, ei->handler_start);
*(mono_get_lmf_addr ()) = lmf;
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->exceptions_depth += frame_count;
+#endif
if (obj == domain->stack_overflow_ex)
jit_tls->handling_stack_ovf = FALSE;
@@ -1747,7 +1751,9 @@ mono_handle_exception_internal (MonoContext *ctx, gpointer obj, gboolean resume,
mono_profiler_exception_clause_handler (ji->method, ei->flags, i);
jit_tls->orig_ex_ctx_set = FALSE;
mono_debugger_call_exception_handler (ei->handler_start, MONO_CONTEXT_GET_SP (ctx), ex_obj);
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->exceptions_finallys++;
+#endif
*(mono_get_lmf_addr ()) = lmf;
if (ji->from_llvm) {
/*
@@ -1900,7 +1906,9 @@ mono_debugger_run_finally (MonoContext *start_ctx)
gboolean
mono_handle_exception (MonoContext *ctx, gpointer obj)
{
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->exceptions_thrown++;
+#endif
return mono_handle_exception_internal (ctx, obj, FALSE, NULL);
}
View
2 mono/mini/mini.c
@@ -5060,8 +5060,10 @@ mini_method_compile (MonoMethod *method, guint32 opts, MonoDomain *domain, gbool
}
/* collect statistics */
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->jit_methods++;
mono_perfcounters->jit_bytes += header->code_size;
+#endif
mono_jit_stats.allocated_code_size += cfg->code_len;
code_size_ratio = cfg->code_len;
if (code_size_ratio > mono_jit_stats.biggest_method_size && mono_jit_stats.enabled) {

0 comments on commit cd474ec

Please sign in to comment.
Something went wrong with that request. Please try again.