[profiler] Introduce runtime control API.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Sat, 15 Jul 2017 17:43:38 +0000 (19:43 +0200)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Sat, 15 Jul 2017 21:08:12 +0000 (23:08 +0200)
mcs/class/Mono.Profiler.Log/Mono.Profiler.Log.dll.sources
mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogEnums.cs
mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogProfiler.cs [new file with mode: 0644]
mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogRuntimeProfiler.cs [deleted file]
mono/profiler/log-args.c
mono/profiler/log.c
mono/profiler/log.h

index bfb0fea4fed677f224858316c34d9385fd981bcf..27b58318f270e2455b5216ce3dcf0c91af7c5bf5 100644 (file)
@@ -8,7 +8,7 @@ Mono.Profiler.Log/LogEventVisitor.cs
 Mono.Profiler.Log/LogEvents.cs
 Mono.Profiler.Log/LogException.cs
 Mono.Profiler.Log/LogProcessor.cs
+Mono.Profiler.Log/LogProfiler.cs
 Mono.Profiler.Log/LogReader.cs
-Mono.Profiler.Log/LogRuntimeProfiler.cs
 Mono.Profiler.Log/LogStream.cs
 Mono.Profiler.Log/LogStreamHeader.cs
index 01ce114093b4a42a3a3f06b0e6b5060953fd7efd..0dbc72eb003e86e24f6447831ccfb8bd08f06b56 100644 (file)
@@ -195,4 +195,20 @@ namespace Mono.Profiler.Log {
                WorldStop = 1,
                WorldStart = 2,
        }
+
+       // mono/metadata/profiler.h : MonoProfilerSampleMode
+       public enum LogSampleMode {
+               None = 0,
+               Process = 1,
+               Real = 2,
+       }
+
+       // mono/profiler/log.h : MonoProfilerHeapshotMode
+       public enum LogHeapshotMode {
+               None = 0,
+               EveryMajor = 1,
+               OnDemand = 2,
+               Milliseconds = 3,
+               Collections = 4,
+       }
 }
diff --git a/mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogProfiler.cs b/mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogProfiler.cs
new file mode 100644 (file)
index 0000000..289b180
--- /dev/null
@@ -0,0 +1,261 @@
+// 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.
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+namespace Mono.Profiler.Log {
+
+       public static class LogProfiler {
+
+               static bool? _attached;
+
+               public static bool IsAttached {
+                       get {
+                               if (_attached != null)
+                                       return (bool) _attached;
+
+                               try {
+                                       GetMaxStackTraceFrames ();
+                                       return (bool) (_attached = true);
+                               } catch (MissingMethodException) {
+                                       return (bool) (_attached = false);
+                               }
+                       }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static int GetMaxStackTraceFrames ();
+
+               public static int MaxStackTraceFrames {
+                       get { return GetMaxStackTraceFrames (); }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static int GetStackTraceFrames ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetStackTraceFrames (int value);
+
+               public static int StackTraceFrames {
+                       get { return GetStackTraceFrames (); }
+                       set {
+                               var max = MaxStackTraceFrames;
+
+                               if (value < 0 || value > max)
+                                       throw new ArgumentOutOfRangeException (nameof (value), value, $"Value must be between 0 and {max}.");
+
+                               SetStackTraceFrames (value);
+                       }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static LogHeapshotMode GetHeapshotMode ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetHeapshotMode (LogHeapshotMode value);
+
+               public static LogHeapshotMode HeapshotMode {
+                       get { return GetHeapshotMode (); }
+                       set {
+                               if (!Enum.IsDefined (typeof (LogHeapshotMode), value))
+                                       throw new ArgumentException ("Invalid heapshot mode.", nameof (value));
+
+                               SetHeapshotMode (value);
+                       }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static int GetHeapshotMillisecondsFrequency ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetHeapshotMillisecondsFrequency (int value);
+
+               public static int HeapshotMillisecondsFrequency {
+                       get { return GetHeapshotMillisecondsFrequency (); }
+                       set {
+                               if (value < 0)
+                                       throw new ArgumentOutOfRangeException (nameof (value), value, "Value must be non-negative.");
+
+                               SetHeapshotMillisecondsFrequency (value);
+                       }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static int GetHeapshotCollectionsFrequency ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetHeapshotCollectionsFrequency (int value);
+
+               public static int HeapshotCollectionsFrequency {
+                       get { return GetHeapshotCollectionsFrequency (); }
+                       set {
+                               if (value < 0)
+                                       throw new ArgumentOutOfRangeException (nameof (value), value, "Value must be non-negative.");
+
+                               SetHeapshotCollectionsFrequency (value);
+                       }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static int GetCallDepth ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetCallDepth (int value);
+
+               public static int CallDepth {
+                       get { return GetCallDepth (); }
+                       set {
+                               if (value < 0)
+                                       throw new ArgumentOutOfRangeException (nameof (value), value, "Value must be non-negative.");
+
+                               SetCallDepth (value);
+                       }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void GetSampleMode (out LogSampleMode mode, out int frequency);
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static bool SetSampleMode (LogSampleMode value, int frequency);
+
+               public static LogSampleMode SampleMode {
+                       get {
+                               GetSampleMode (out var mode, out var _);
+
+                               return mode;
+                       }
+               }
+
+               public static int SampleFrequency {
+                       get {
+                               GetSampleMode (out var _, out var frequency);
+
+                               return frequency;
+                       }
+               }
+
+               public static bool SetSampleParameters (LogSampleMode mode, int frequency)
+               {
+                       if (!Enum.IsDefined (typeof (LogSampleMode), mode))
+                               throw new ArgumentException ("Invalid sample mode.", nameof (mode));
+
+                       if (frequency < 1)
+                               throw new ArgumentOutOfRangeException (nameof (frequency), frequency, "Frequency must be positive.");
+
+                       return SetSampleMode (mode, frequency);
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static bool GetExceptionEvents ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetExceptionEvents (bool value);
+
+               public static bool ExceptionEventsEnabled {
+                       get { return GetExceptionEvents (); }
+                       set { SetExceptionEvents (value); }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static bool GetMonitorEvents ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetMonitorEvents (bool value);
+
+               public static bool MonitorEventsEnabled {
+                       get { return GetMonitorEvents (); }
+                       set { SetMonitorEvents (value); }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static bool GetGCEvents ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetGCEvents (bool value);
+
+               public static bool GCEventsEnabled {
+                       get { return GetGCEvents (); }
+                       set { SetGCEvents (value); }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static bool GetGCAllocationEvents ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetGCAllocationEvents (bool value);
+
+               public static bool GCAllocationEventsEnabled {
+                       get { return GetGCAllocationEvents (); }
+                       set { SetGCAllocationEvents (value); }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static bool GetGCMoveEvents ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetGCMoveEvents (bool value);
+
+               public static bool GCMoveEventsEnabled {
+                       get { return GetGCMoveEvents (); }
+                       set { SetGCMoveEvents (value); }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static bool GetGCRootEvents ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetGCRootEvents (bool value);
+
+               public static bool GCRootEventsEnabled {
+                       get { return GetGCRootEvents (); }
+                       set { SetGCRootEvents (value); }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static bool GetGCHandleEvents ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetGCHandleEvents (bool value);
+
+               public static bool GCHandleEventsEnabled {
+                       get { return GetGCHandleEvents (); }
+                       set { SetGCHandleEvents (value); }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static bool GetGCFinalizationEvents ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetGCFinalizationEvents (bool value);
+
+               public static bool GCFinalizationEventsEnabled {
+                       get { return GetGCFinalizationEvents (); }
+                       set { SetGCFinalizationEvents (value); }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static bool GetCounterEvents ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetCounterEvents (bool value);
+
+               public static bool CounterEventsEnabled {
+                       get { return GetCounterEvents (); }
+                       set { SetCounterEvents (value); }
+               }
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static bool GetJitEvents ();
+
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               extern static void SetJitEvents (bool value);
+
+               public static bool JitEventsEnabled {
+                       get { return GetJitEvents (); }
+                       set { SetJitEvents (value); }
+               }
+       }
+}
diff --git a/mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogRuntimeProfiler.cs b/mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogRuntimeProfiler.cs
deleted file mode 100644 (file)
index 8ed0993..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// 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.
-
-using System.Runtime.InteropServices;
-
-namespace Mono.Profiler.Log {
-
-       public static class LogRuntimeProfiler {
-
-               // TODO: Runtime profiler interface.
-       }
-}
index 398bcc9b159cf113937a8422f6ede7bbf4e5a0b6..8f56a644ac7bb9678f3405b6ebd154fea8f85ed3 100644 (file)
@@ -20,7 +20,7 @@ static NameAndMask event_list[] = {
        { "gcmove", PROFLOG_GC_MOVE_EVENTS },
        { "gcroot", PROFLOG_GC_ROOT_EVENTS },
        { "gchandle", PROFLOG_GC_HANDLE_EVENTS },
-       { "finalization", PROFLOG_FINALIZATION_EVENTS },
+       { "finalization", PROFLOG_GC_FINALIZATION_EVENTS },
        { "counter", PROFLOG_COUNTER_EVENTS },
        { "jit", PROFLOG_JIT_EVENTS },
 
index b1cfa1ed0ad46eeb77107c6a5444ed2a39f34371..3b75deb6146e43fb6627c2fca40a4add9c79ef50 100644 (file)
 
 #include <config.h>
 #include <mono/metadata/assembly.h>
+#include <mono/metadata/class-internals.h>
 #include <mono/metadata/debug-helpers.h>
-#include "../metadata/metadata-internals.h"
+#include <mono/metadata/loader.h>
+#include <mono/metadata/metadata-internals.h>
 #include <mono/metadata/mono-config.h>
 #include <mono/metadata/mono-gc.h>
 #include <mono/metadata/mono-perfcounters.h>
@@ -23,6 +25,7 @@
 #include <mono/utils/lock-free-alloc.h>
 #include <mono/utils/lock-free-queue.h>
 #include <mono/utils/mono-conc-hashtable.h>
+#include <mono/utils/mono-coop-mutex.h>
 #include <mono/utils/mono-counters.h>
 #include <mono/utils/mono-logger-internals.h>
 #include <mono/utils/mono-linked-list-set.h>
@@ -210,7 +213,9 @@ process_id (void)
 #endif
 }
 
-#define ENABLED(EVT) (log_config.effective_mask & (EVT))
+#define ENABLED(EVT) (!!(log_config.effective_mask & (EVT)))
+#define ENABLE(EVT) do { log_config.effective_mask |= (EVT); } while (0)
+#define DISABLE(EVT) do { log_config.effective_mask &= ~(EVT); } while (0)
 
 /*
  * These macros should be used when writing an event to a log buffer. They
@@ -358,6 +363,8 @@ struct _MonoProfiler {
 
        guint32 coverage_previous_offset;
        guint32 coverage_method_id;
+
+       MonoCoopMutex api_mutex;
 };
 
 static ProfilerConfig log_config;
@@ -1543,7 +1550,7 @@ static void
 finalize_end (MonoProfiler *prof)
 {
        trigger_on_demand_heapshot ();
-       if (ENABLED (PROFLOG_FINALIZATION_EVENTS)) {
+       if (ENABLED (PROFLOG_GC_FINALIZATION_EVENTS)) {
                ENTER_LOG (&finalize_ends_ctr, buf,
                        EVENT_SIZE /* event */
                );
@@ -3615,6 +3622,8 @@ log_shutdown (MonoProfiler *prof)
                mono_os_mutex_destroy (&log_profiler.coverage_mutex);
        }
 
+       mono_coop_mutex_destroy (&log_profiler.api_mutex);
+
        PROF_TLS_FREE ();
 
        g_free (prof->args);
@@ -4106,6 +4115,325 @@ register_counter (const char *name, gint32 *counter)
        mono_counters_register (name, MONO_COUNTER_UINT | MONO_COUNTER_PROFILER | MONO_COUNTER_MONOTONIC, counter);
 }
 
+ICALL_EXPORT gint32
+proflog_icall_GetMaxStackTraceFrames (void)
+{
+       return MAX_FRAMES;
+}
+
+ICALL_EXPORT gint32
+proflog_icall_GetStackTraceFrames (void)
+{
+       return log_config.num_frames;
+}
+
+ICALL_EXPORT void
+proflog_icall_SetStackTraceFrames (gint32 value)
+{
+       log_config.num_frames = value;
+}
+
+ICALL_EXPORT MonoProfilerHeapshotMode
+proflog_icall_GetHeapshotMode (void)
+{
+       return log_config.hs_mode;
+}
+
+ICALL_EXPORT void
+proflog_icall_SetHeapshotMode (MonoProfilerHeapshotMode value)
+{
+       log_config.hs_mode = value;
+}
+
+ICALL_EXPORT gint32
+proflog_icall_GetHeapshotMillisecondsFrequency (void)
+{
+       return log_config.hs_freq_ms;
+}
+
+ICALL_EXPORT void
+proflog_icall_SetHeapshotMillisecondsFrequency (gint32 value)
+{
+       log_config.hs_freq_ms = value;
+}
+
+ICALL_EXPORT gint32
+proflog_icall_GetHeapshotCollectionsFrequency (void)
+{
+       return log_config.hs_freq_gc;
+}
+
+ICALL_EXPORT void
+proflog_icall_SetHeapshotCollectionsFrequency (gint32 value)
+{
+       log_config.hs_freq_gc = value;
+}
+
+ICALL_EXPORT gint32
+proflog_icall_GetCallDepth (void)
+{
+       return log_config.max_call_depth;
+}
+
+ICALL_EXPORT void
+proflog_icall_SetCallDepth (gint32 value)
+{
+       log_config.max_call_depth = value;
+}
+
+ICALL_EXPORT void
+proflog_icall_GetSampleMode (MonoProfilerSampleMode *mode, gint32 *frequency)
+{
+       guint64 freq;
+
+       mono_profiler_get_sample_mode (log_profiler.handle, mode, &freq);
+
+       *frequency = freq;
+}
+
+ICALL_EXPORT MonoBoolean
+proflog_icall_SetSampleMode (MonoProfilerSampleMode mode, gint32 frequency)
+{
+       mono_coop_mutex_lock (&log_profiler.api_mutex);
+
+       mono_bool result = mono_profiler_set_sample_mode (log_profiler.handle, mode, frequency);
+
+       if (mode != MONO_PROFILER_SAMPLE_MODE_NONE) {
+               ENABLE (PROFLOG_SAMPLE_EVENTS);
+               mono_profiler_set_sample_hit_callback (log_profiler.handle, mono_sample_hit);
+       } else {
+               DISABLE (PROFLOG_SAMPLE_EVENTS);
+               mono_profiler_set_sample_hit_callback (log_profiler.handle, NULL);
+       }
+
+       mono_coop_mutex_unlock (&log_profiler.api_mutex);
+
+       return result;
+}
+
+ICALL_EXPORT MonoBoolean
+proflog_icall_GetExceptionEvents (void)
+{
+       return ENABLED (PROFLOG_EXCEPTION_EVENTS);
+}
+
+ICALL_EXPORT void
+proflog_icall_SetExceptionEvents (MonoBoolean value)
+{
+       mono_coop_mutex_lock (&log_profiler.api_mutex);
+
+       if (value) {
+               ENABLE (PROFLOG_EXCEPTION_EVENTS);
+               mono_profiler_set_exception_throw_callback (log_profiler.handle, throw_exc);
+               mono_profiler_set_exception_clause_callback (log_profiler.handle, clause_exc);
+       } else {
+               DISABLE (PROFLOG_EXCEPTION_EVENTS);
+               mono_profiler_set_exception_throw_callback (log_profiler.handle, NULL);
+               mono_profiler_set_exception_clause_callback (log_profiler.handle, NULL);
+       }
+
+       mono_coop_mutex_unlock (&log_profiler.api_mutex);
+}
+
+ICALL_EXPORT MonoBoolean
+proflog_icall_GetMonitorEvents (void)
+{
+       return ENABLED (PROFLOG_MONITOR_EVENTS);
+}
+
+ICALL_EXPORT void
+proflog_icall_SetMonitorEvents (MonoBoolean value)
+{
+       mono_coop_mutex_lock (&log_profiler.api_mutex);
+
+       if (value) {
+               ENABLE (PROFLOG_EXCEPTION_EVENTS);
+               mono_profiler_set_monitor_contention_callback (log_profiler.handle, monitor_contention);
+               mono_profiler_set_monitor_acquired_callback (log_profiler.handle, monitor_acquired);
+               mono_profiler_set_monitor_failed_callback (log_profiler.handle, monitor_failed);
+       } else {
+               DISABLE (PROFLOG_EXCEPTION_EVENTS);
+               mono_profiler_set_monitor_contention_callback (log_profiler.handle, NULL);
+               mono_profiler_set_monitor_acquired_callback (log_profiler.handle, NULL);
+               mono_profiler_set_monitor_failed_callback (log_profiler.handle, NULL);
+       }
+
+       mono_coop_mutex_unlock (&log_profiler.api_mutex);
+}
+
+ICALL_EXPORT MonoBoolean
+proflog_icall_GetGCEvents (void)
+{
+       return ENABLED (PROFLOG_GC_EVENTS);
+}
+
+ICALL_EXPORT void
+proflog_icall_SetGCEvents (MonoBoolean value)
+{
+       mono_coop_mutex_lock (&log_profiler.api_mutex);
+
+       if (value)
+               ENABLE (PROFLOG_GC_EVENTS);
+       else
+               DISABLE (PROFLOG_GC_EVENTS);
+
+       mono_coop_mutex_unlock (&log_profiler.api_mutex);
+}
+
+ICALL_EXPORT MonoBoolean
+proflog_icall_GetGCAllocationEvents (void)
+{
+       return ENABLED (PROFLOG_GC_ALLOCATION_EVENTS);
+}
+
+ICALL_EXPORT void
+proflog_icall_SetGCAllocationEvents (MonoBoolean value)
+{
+       mono_coop_mutex_lock (&log_profiler.api_mutex);
+
+       if (value) {
+               ENABLE (PROFLOG_GC_ALLOCATION_EVENTS);
+               mono_profiler_set_gc_allocation_callback (log_profiler.handle, gc_alloc);
+       } else {
+               DISABLE (PROFLOG_GC_ALLOCATION_EVENTS);
+               mono_profiler_set_gc_allocation_callback (log_profiler.handle, NULL);
+       }
+
+       mono_coop_mutex_unlock (&log_profiler.api_mutex);
+}
+
+ICALL_EXPORT MonoBoolean
+proflog_icall_GetGCMoveEvents (void)
+{
+       return ENABLED (PROFLOG_GC_MOVE_EVENTS);
+}
+
+ICALL_EXPORT void
+proflog_icall_SetGCMoveEvents (MonoBoolean value)
+{
+       mono_coop_mutex_lock (&log_profiler.api_mutex);
+
+       if (value) {
+               ENABLE (PROFLOG_GC_MOVE_EVENTS);
+               mono_profiler_set_gc_moves_callback (log_profiler.handle, gc_moves);
+       } else {
+               DISABLE (PROFLOG_GC_MOVE_EVENTS);
+               mono_profiler_set_gc_moves_callback (log_profiler.handle, NULL);
+       }
+
+       mono_coop_mutex_unlock (&log_profiler.api_mutex);
+}
+
+ICALL_EXPORT MonoBoolean
+proflog_icall_GetGCRootEvents (void)
+{
+       return ENABLED (PROFLOG_GC_ROOT_EVENTS);
+}
+
+ICALL_EXPORT void
+proflog_icall_SetGCRootEvents (MonoBoolean value)
+{
+       mono_coop_mutex_lock (&log_profiler.api_mutex);
+
+       if (value)
+               ENABLE (PROFLOG_GC_ROOT_EVENTS);
+       else
+               DISABLE (PROFLOG_GC_ROOT_EVENTS);
+
+       mono_coop_mutex_unlock (&log_profiler.api_mutex);
+}
+
+ICALL_EXPORT MonoBoolean
+proflog_icall_GetGCHandleEvents (void)
+{
+       return ENABLED (PROFLOG_GC_HANDLE_EVENTS);
+}
+
+ICALL_EXPORT void
+proflog_icall_SetGCHandleEvents (MonoBoolean value)
+{
+       mono_coop_mutex_lock (&log_profiler.api_mutex);
+
+       if (value) {
+               ENABLE (PROFLOG_GC_HANDLE_EVENTS);
+               mono_profiler_set_gc_handle_created_callback (log_profiler.handle, gc_handle_created);
+               mono_profiler_set_gc_handle_deleted_callback (log_profiler.handle, gc_handle_deleted);
+       } else {
+               DISABLE (PROFLOG_GC_HANDLE_EVENTS);
+               mono_profiler_set_gc_handle_created_callback (log_profiler.handle, NULL);
+               mono_profiler_set_gc_handle_deleted_callback (log_profiler.handle, NULL);
+       }
+
+       mono_coop_mutex_unlock (&log_profiler.api_mutex);
+}
+
+ICALL_EXPORT MonoBoolean
+proflog_icall_GetGCFinalizationEvents (void)
+{
+       return ENABLED (PROFLOG_GC_FINALIZATION_EVENTS);
+}
+
+ICALL_EXPORT void
+proflog_icall_SetGCFinalizationEvents (MonoBoolean value)
+{
+       mono_coop_mutex_lock (&log_profiler.api_mutex);
+
+       if (value) {
+               ENABLE (PROFLOG_GC_FINALIZATION_EVENTS);
+               mono_profiler_set_gc_finalizing_callback (log_profiler.handle, finalize_begin);
+               mono_profiler_set_gc_finalizing_object_callback (log_profiler.handle, finalize_object_begin);
+               mono_profiler_set_gc_finalized_object_callback (log_profiler.handle, finalize_object_end);
+       } else {
+               DISABLE (PROFLOG_GC_FINALIZATION_EVENTS);
+               mono_profiler_set_gc_finalizing_callback (log_profiler.handle, NULL);
+               mono_profiler_set_gc_finalizing_object_callback (log_profiler.handle, NULL);
+               mono_profiler_set_gc_finalized_object_callback (log_profiler.handle, NULL);
+       }
+
+       mono_coop_mutex_unlock (&log_profiler.api_mutex);
+}
+
+ICALL_EXPORT MonoBoolean
+proflog_icall_GetCounterEvents (void)
+{
+       return ENABLED (PROFLOG_COUNTER_EVENTS);
+}
+
+ICALL_EXPORT void
+proflog_icall_SetCounterEvents (MonoBoolean value)
+{
+       mono_coop_mutex_lock (&log_profiler.api_mutex);
+
+       if (value)
+               ENABLE (PROFLOG_COUNTER_EVENTS);
+       else
+               DISABLE (PROFLOG_COUNTER_EVENTS);
+
+       mono_coop_mutex_unlock (&log_profiler.api_mutex);
+}
+
+ICALL_EXPORT MonoBoolean
+proflog_icall_GetJitEvents (void)
+{
+       return ENABLED (PROFLOG_JIT_EVENTS);
+}
+
+ICALL_EXPORT void
+proflog_icall_SetJitEvents (MonoBoolean value)
+{
+       mono_coop_mutex_lock (&log_profiler.api_mutex);
+
+       if (value) {
+               ENABLE (PROFLOG_JIT_EVENTS);
+               mono_profiler_set_jit_code_buffer_callback (log_profiler.handle, code_buffer_new);
+       } else {
+               DISABLE (PROFLOG_JIT_EVENTS);
+               mono_profiler_set_jit_code_buffer_callback (log_profiler.handle, NULL);
+       }
+
+       mono_coop_mutex_unlock (&log_profiler.api_mutex);
+}
+
 static void
 runtime_initialized (MonoProfiler *profiler)
 {
@@ -4173,6 +4501,47 @@ runtime_initialized (MonoProfiler *profiler)
        start_helper_thread ();
        start_writer_thread ();
        start_dumper_thread ();
+
+       mono_coop_mutex_init (&log_profiler.api_mutex);
+
+#define ADD_ICALL(NAME) \
+       mono_add_internal_call ("Mono.Profiler.Log.LogProfiler::" EGLIB_STRINGIFY (NAME), proflog_icall_ ## NAME);
+
+       ADD_ICALL (GetMaxStackTraceFrames);
+       ADD_ICALL (GetStackTraceFrames);
+       ADD_ICALL (SetStackTraceFrames);
+       ADD_ICALL (GetHeapshotMode);
+       ADD_ICALL (SetHeapshotMode);
+       ADD_ICALL (GetHeapshotMillisecondsFrequency);
+       ADD_ICALL (SetHeapshotMillisecondsFrequency);
+       ADD_ICALL (GetHeapshotCollectionsFrequency);
+       ADD_ICALL (SetHeapshotCollectionsFrequency);
+       ADD_ICALL (GetCallDepth);
+       ADD_ICALL (SetCallDepth);
+       ADD_ICALL (GetSampleMode);
+       ADD_ICALL (SetSampleMode);
+       ADD_ICALL (GetExceptionEvents);
+       ADD_ICALL (SetExceptionEvents);
+       ADD_ICALL (GetMonitorEvents);
+       ADD_ICALL (SetMonitorEvents);
+       ADD_ICALL (GetGCEvents);
+       ADD_ICALL (SetGCEvents);
+       ADD_ICALL (GetGCAllocationEvents);
+       ADD_ICALL (SetGCAllocationEvents);
+       ADD_ICALL (GetGCMoveEvents);
+       ADD_ICALL (SetGCMoveEvents);
+       ADD_ICALL (GetGCRootEvents);
+       ADD_ICALL (SetGCRootEvents);
+       ADD_ICALL (GetGCHandleEvents);
+       ADD_ICALL (SetGCHandleEvents);
+       ADD_ICALL (GetGCFinalizationEvents);
+       ADD_ICALL (SetGCFinalizationEvents);
+       ADD_ICALL (GetCounterEvents);
+       ADD_ICALL (SetCounterEvents);
+       ADD_ICALL (GetJitEvents);
+       ADD_ICALL (SetJitEvents);
+
+#undef ADD_ICALL
 }
 
 static void
@@ -4350,10 +4719,8 @@ mono_profiler_init (const char *desc)
        if (ENABLED (PROFLOG_GC_EVENTS))
                mono_profiler_set_gc_resize_callback (handle, gc_resize);
 
-       if (ENABLED (PROFLOG_GC_ALLOCATION_EVENTS)) {
-               mono_profiler_enable_allocations ();
+       if (ENABLED (PROFLOG_GC_ALLOCATION_EVENTS))
                mono_profiler_set_gc_allocation_callback (handle, gc_alloc);
-       }
 
        if (ENABLED (PROFLOG_GC_MOVE_EVENTS))
                mono_profiler_set_gc_moves_callback (handle, gc_moves);
@@ -4366,16 +4733,15 @@ mono_profiler_init (const char *desc)
                mono_profiler_set_gc_handle_deleted_callback (handle, gc_handle_deleted);
        }
 
-       if (ENABLED (PROFLOG_FINALIZATION_EVENTS)) {
+       if (ENABLED (PROFLOG_GC_FINALIZATION_EVENTS)) {
                mono_profiler_set_gc_finalizing_callback (handle, finalize_begin);
                mono_profiler_set_gc_finalized_callback (handle, finalize_end);
                mono_profiler_set_gc_finalizing_object_callback (handle, finalize_object_begin);
-               mono_profiler_set_gc_finalized_object_callback (handle, finalize_object_end);
-       } else if (log_config.hs_mode == MONO_PROFILER_HEAPSHOT_ON_DEMAND) {
-               //On Demand heapshot uses the finalizer thread to force a collection and thus a heapshot
-               mono_profiler_set_gc_finalized_callback (handle, finalize_end);
        }
 
+       //On Demand heapshot uses the finalizer thread to force a collection and thus a heapshot
+       mono_profiler_set_gc_finalized_callback (handle, finalize_end);
+
        if (ENABLED (PROFLOG_SAMPLE_EVENTS))
                mono_profiler_set_sample_hit_callback (handle, mono_sample_hit);
 
@@ -4392,6 +4758,7 @@ mono_profiler_init (const char *desc)
        if (log_config.collect_coverage)
                mono_profiler_set_coverage_filter_callback (handle, coverage_filter);
 
+       mono_profiler_enable_allocations ();
        mono_profiler_enable_sampling (handle);
 
        /*
index 1979e8baab6435e507b6640a5a71d8dbc8d5aeda..d8182d90ee27dfc7d3b266e31124bd7f3dae2baa 100644 (file)
@@ -467,14 +467,14 @@ typedef enum {
 #define PROFLOG_GC_MOVE_EVENTS (1 << 4)
 #define PROFLOG_GC_ROOT_EVENTS (1 << 5)
 #define PROFLOG_GC_HANDLE_EVENTS (1 << 6)
-#define PROFLOG_FINALIZATION_EVENTS (1 << 7)
+#define PROFLOG_GC_FINALIZATION_EVENTS (1 << 7)
 #define PROFLOG_COUNTER_EVENTS (1 << 8)
 #define PROFLOG_SAMPLE_EVENTS (1 << 9)
 #define PROFLOG_JIT_EVENTS (1 << 10)
 
 #define PROFLOG_ALLOC_ALIAS (PROFLOG_GC_EVENTS | PROFLOG_GC_ALLOCATION_EVENTS | PROFLOG_GC_MOVE_EVENTS)
 #define PROFLOG_HEAPSHOT_ALIAS (PROFLOG_GC_EVENTS | PROFLOG_GC_ROOT_EVENTS)
-#define PROFLOG_LEGACY_ALIAS (PROFLOG_EXCEPTION_EVENTS | PROFLOG_MONITOR_EVENTS | PROFLOG_GC_EVENTS | PROFLOG_GC_MOVE_EVENTS | PROFLOG_GC_ROOT_EVENTS | PROFLOG_GC_HANDLE_EVENTS | PROFLOG_FINALIZATION_EVENTS | PROFLOG_COUNTER_EVENTS)
+#define PROFLOG_LEGACY_ALIAS (PROFLOG_EXCEPTION_EVENTS | PROFLOG_MONITOR_EVENTS | PROFLOG_GC_EVENTS | PROFLOG_GC_MOVE_EVENTS | PROFLOG_GC_ROOT_EVENTS | PROFLOG_GC_HANDLE_EVENTS | PROFLOG_GC_FINALIZATION_EVENTS | PROFLOG_COUNTER_EVENTS)
 
 typedef struct {
        //Events explicitly enabled