Example #1
0
        /// <summary>
        /// Setups the aggregated metric listener.
        /// </summary>
        /// <param name="providerGuid">The provider unique identifier.</param>
        /// <param name="etlFileName">The name of the etw file from when read data. If null, realtime session will be used.</param>
        /// <param name="metricProducedAction">The when metric available.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="activeCollector">The active collector.</param>
        private static void SetupAggregatedMetricListener(
            Guid providerGuid,
            string etlFileName,
            Action <ILocalAggregatedMetric> metricProducedAction,
            CancellationToken cancellationToken,
            out ActiveCollector activeCollector)
        {
            var providers = new Dictionary <Guid, ProviderConfiguration>
            {
                {
                    providerGuid,
                    new ProviderConfiguration(providerGuid, EtwTraceLevel.Verbose, 0, 0)
                }
            };

            var etwSessionConfig = new CollectorConfiguration(EtwSessionsPrefix + "aggregated-")
            {
                SessionType = SessionType.Realtime,
                Providers   = providers
            };

            activeCollector = new ActiveCollector(etwSessionConfig.Name);
            activeCollector.StartCollector(etwSessionConfig);

            RawListener etwListener = null;

            try
            {
                etwListener = string.IsNullOrWhiteSpace(etlFileName)
                                  ? CreateRealTimeListener(providerGuid, etwSessionConfig.Name, metricProducedAction, 1, cancellationToken)
                                  : CreateFileListener(providerGuid, etlFileName, metricProducedAction, 1, cancellationToken);

                // TODO: Better to check providers periodically and retry several times.
                if (!ActiveCollector.TryUpdateProviders(etwSessionConfig))
                {
                    Logger.Log(LoggerLevel.Error, LogId, "Main", "Failed to update ETW providers. Terminating.");
                    return;
                }

                try
                {
                    etwListener.Process();
                }
                finally
                {
                    Logger.Log(
                        cancellationToken.IsCancellationRequested ? LoggerLevel.Info : LoggerLevel.Error,
                        LogId,
                        "SetupEtwDataPipeline",
                        "ETW Thread terminated unexpectedly, typically indicates that the ETW session was stopped.");
                }
            }
            finally
            {
                if (etwListener != null)
                {
                    etwListener.Dispose();
                }
            }
        }
Example #2
0
 /// <summary>
 /// Stops the etw session.
 /// </summary>
 /// <param name="activeCollector">The active collector.</param>
 private static void StopEtwSession(ActiveCollector activeCollector)
 {
     if (activeCollector != null)
     {
         ActiveCollector.StopCollector(activeCollector.Name);
     }
 }
 public object[] CollectSearchCriteria()
 {
     if (ActiveCollector == null)
     {
         return(null);
     }
     return(ActiveCollector.CollectSearchCriteria());
 }
 public bool AfterClosing()
 {
     if (ActiveCollector != null)
     {
         return(ActiveCollector.AfterClosing());
     }
     return(false);
 }
 public bool BeforeClosing()
 {
     if (ActiveCollector != null)
     {
         return(ActiveCollector.BeforeClosing());
     }
     return(false);
 }
 public bool CreateNew()
 {
     if (ActiveCollector != null)
     {
         return(ActiveCollector.CreateNew());
     }
     return(false);
 }
 public bool BeforeCreatingNew()
 {
     if (ActiveCollector != null)
     {
         return(ActiveCollector.BeforeCreatingNew());
     }
     return(false);
 }
 public bool Delete(IDBCommon entity)
 {
     if (ActiveCollector == null)
     {
         return(false);
     }
     return(ActiveCollector.Delete(entity));
 }
 public bool Close()
 {
     if (ActiveCollector != null)
     {
         return(ActiveCollector.Close());
     }
     return(false);
 }
        public bool AddToParent()
        {
            if (ActiveCollector != null)
            {
                ActiveCollector.AddToParent();
            }

            return(false);
        }
        public bool CheckIfActiveDBItemExists()
        {
            if (ActiveCollector != null)
            {
                return(ActiveCollector.CheckIfActiveDBItemExists());
            }

            return(false);
        }
Example #12
0
    public void AddCollectorDestination(GameObject _collector, GameObject _roadHub)
    {
        ActiveCollector instance = ActiveCollector.CreateInstance <ActiveCollector>();

        instance.collector   = _collector;
        instance.destination = _roadHub;

        activeCollectorsList.Add(instance);
    }
        public IEnumerable <TEntity> GetItemsList()
        {
            if (ActiveCollector == null)
            {
                return(null);
            }

            return(ActiveCollector.GetItemsList());
        }
        public void AfterEdit(IDBCommon entity)
        {
            if (ActiveCollector == null)
            {
                return;
            }

            ActiveCollector.BeforeEdit(entity);
        }
        public void Edit(IDBCommon entity)
        {
            if (ActiveCollector == null)
            {
                return;
            }

            ActiveCollector.ActiveDBItem = entity;
            ActiveCollector.Edit(entity);
        }
        public bool ValidateBeforeSave(ref string message)
        {
            if (ActiveCollector != null)
            {
                if (ActiveCollector.ValidateBeforeSave(ref message))
                {
                    return(true);
                }
                MessageToView = ActiveCollector.MessageToView;
            }

            return(false);
        }
        public bool AfterCreateNew()
        {
            if (ActiveCollector != null)
            {
                if (ActiveCollector.AfterCreateNew())
                {
                    ActiveCollector.ActiveViewer.ClearControls();
                    ActiveCollector.ActiveViewer.FillControls();
                }
            }

            return(false);
        }
        public bool AfterSave()
        {
            if (ActiveCollector != null)
            {
                if (ActiveCollector.AfterSave())
                {
                    ActiveCollector.ActiveDBItem = null;
                    return(true);
                }
            }

            return(false);
        }
        public bool SaveChanges(DB_CommonTransactionType commonTransactionType)
        {
            if (ActiveCollector != null)
            {
                ActiveCollector.CommonTransactionType = commonTransactionType;
                if (ActiveCollector.Collect(ActiveCollector) && ActiveCollector.SaveChanges(commonTransactionType))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #20
0
        /// <summary>
        /// Reads the locally aggregated metrics.
        /// </summary>
        /// <param name="metricProducedAction">The action to execute when metric available.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="etlFileName">The name of the etw file from when read data. If null, realtime session will be used.</param>
        /// <returns>
        /// An awaitable <see cref="Task" />.
        /// </returns>
        public Task ReadLocalAggregatedMetricsAsync(
            Action <ILocalAggregatedMetric> metricProducedAction,
            CancellationToken cancellationToken,
            string etlFileName = null)
        {
            if (metricProducedAction == null)
            {
                throw new ArgumentNullException("metricProducedAction");
            }

            if (cancellationToken == null)
            {
                throw new ArgumentNullException("cancellationToken");
            }

            if (!this.EnableVerboseLogging)
            {
                Logger.SetMaxLogLevel(LoggerLevel.Error);
            }

            ActiveCollector activeCollector = null;

            Task task = Task.Factory.StartNew(
                () =>
            {
                try
                {
                    Task.Factory.StartNew(
                        () =>
                        SetupAggregatedMetricListener(
                            AggregatedMetricsProviderGuid,
                            etlFileName,
                            metricProducedAction,
                            cancellationToken,
                            out activeCollector),
                        TaskCreationOptions.LongRunning);

                    cancellationToken.WaitHandle.WaitOne();
                }
                finally
                {
                    StopEtwSession(activeCollector);
                }
            },
                TaskCreationOptions.LongRunning);

            Console.CancelKeyPress += (sender, args) => StopEtwSession(activeCollector);

            return(task);
        }
        /// <summary>
        /// Reads the diagnostic heartbeats.
        /// </summary>
        /// <param name="heartbeatAction">The heartbeat action.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The task listening for ETW events.</returns>
        public Task ReadDiagnosticHeartbeatsAsync(
            Action <IDiagnosticHeartbeat> heartbeatAction,
            CancellationToken cancellationToken)
        {
            if (heartbeatAction == null)
            {
                throw new ArgumentNullException(nameof(heartbeatAction));
            }

            if (cancellationToken == null)
            {
                throw new ArgumentNullException(nameof(cancellationToken));
            }

            if (!this.EnableVerboseLogging)
            {
                Logger.SetMaxLogLevel(LoggerLevel.Error);
            }

            ActiveCollector activeCollector = null;
            Task            task            = Task.Factory.StartNew(
                () =>
            {
                try
                {
                    Task.Factory.StartNew(
                        () =>
                        SetupListener(
                            ProviderGuid,
                            heartbeatAction,
                            cancellationToken,
                            out activeCollector),
                        TaskCreationOptions.LongRunning);

                    cancellationToken.WaitHandle.WaitOne();
                }
                finally
                {
                    StopEtwSession(activeCollector);
                }
            },
                TaskCreationOptions.LongRunning);

            Console.CancelKeyPress += (sender, args) => StopEtwSession(activeCollector);

            return(task);
        }