Permalink
Browse files

Implement the runtime side of disabling performance counters.

  • Loading branch information...
kumpera committed Nov 7, 2012
1 parent 1d4d9f9 commit cd474ecbbf2ec950b5c3b83eb7b3618961a40ff4
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 ();
@@ -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
@@ -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
@@ -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
@@ -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;
Oops, something went wrong.

0 comments on commit cd474ec

Please sign in to comment.