/// <summary>
        /// Stops the profiling session.
        /// </summary>
        /// <param name="buildAggregatedCallTree">true if the aggregated call is to be built.</param>
        public void Stop(bool buildAggregatedCallTree = true)
        {
            if (etwEventDynamicProcessor != null)
            {
                etwEventDynamicProcessor.Dispose();
                etwEventDynamicProcessor = null;
            }

            eventAggregator.FinishAggregation(buildAggregatedCallTree);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DynamicProfilerEventProcessor"/> class.
        /// </summary>
        /// <param name="sessionId">The session id.</param>
        /// <param name="threshold">The threshold value. The aggregated call tree will only show events greater than this.</param>
        public DynamicProfilerEventProcessor(int sessionId, long threshold = 0)
        {
            if (sessionId == MultipleSessionsId)
            {
                eventAggregator = new MultipleSessionsEventAggregator(threshold);
            }
            else
            {
                eventAggregator = new SingleSessionEventAggregator(sessionId, threshold);
            }

            etwEventDynamicProcessor = new EtwEventDynamicProcessor(ProviderName, eventAggregator.AddEtwEventToAggregatedCallTree);
        }