private static void InitializeGCEventListener(ListenerConfiguration configuration)
        {
            try
            {
                lock (m_ListenerLock)
                {
                    if (m_GCEventListener == null && (configuration.EnableGCEvents))
                    {
                        m_GCEventListener = new GCEventListener();
                    }

                    System.Threading.Monitor.PulseAll(m_ListenerLock);
                }
            }
            catch (Exception ex)
            {
                GC.KeepAlive(ex);

                if (!Log.SilentMode)
                {
                    Log.Write(LogMessageSeverity.Error, LogWriteMode.Queued, ex, true, "Gibraltar.Agent",
                              "Unable to initialize Common Language Runtime Listener due to " + ex.GetBaseException().GetType().Name,
                              "While attempting to do a routine initialization / re-initialization of the CLR listener, an exception was thrown: {0}", ex.Message);
                }
            }
        }
Exemple #2
0
 public GCEventProfiler(Func <GCEventStatistics, Task> onEventEmit, Action <Exception> onEventError)
 {
     // enable only emit callback is exists.
     if (onEventEmit != null)
     {
         listener = new GCEventListener(onEventEmit, onEventError);
     }
 }
        public async Task Run(CancellationToken cancelToken)
        {
            try
            {
                _listener = new GCEventListener(OnGarbageCollected);

                while (!cancelToken.IsCancellationRequested)
                {
                    lock (_outputHealthLock)
                    {
                        OutputHealthInfo();
                    }

                    await Task.Delay(monitorInterval, cancelToken);
                }
            }
            catch (OperationCanceledException)
            {
                _listener.Dispose();
                _listener = null;
            }
        }