コード例 #1
0
        public DataSet Calculate(AnalyzerTaskResult analyzerResult)
        {
            #region Argument exceptions

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

            #endregion

            var store = new DataSet();

            EventsNotifier.Instance.Notify(ProcedureEvents.ProcedureAnalyzeStepCalculateResult);

            store.Tables.Add(_procedureContext.ToExecutionInfoTable());

            switch (_procedureContext.ExecutionMode)
            {
            case ProcedureExecutionMode.Live:
                var bag = new ConcurrentBag <DataTable>();

                using (var task = Task.Factory.StartNew(() =>
                {
                    Task.Factory.StartNew(() => bag.Add(analyzerResult.Profiler.ToEnginePerformanceTable()), TaskCreationOptions.AttachedToParent);
                    Task.Factory.StartNew(() => bag.Add(analyzerResult.Profiler.ToAggregationsReadTable()), TaskCreationOptions.AttachedToParent);
                    Task.Factory.StartNew(() => bag.Add(analyzerResult.Profiler.ToPartitionsReadTable()), TaskCreationOptions.AttachedToParent);
                    Task.Factory.StartNew(() => bag.Add(analyzerResult.Profiler.ToCachesReadTable()), TaskCreationOptions.AttachedToParent);

                    store.Tables.Add(analyzerResult.QueryResult.ToQueryResultTable());
                    foreach (var table in analyzerResult.Performance.ToTables())
                    {
                        store.Tables.Add(table);
                    }
                    foreach (var table in analyzerResult.Profiler.ToTables())
                    {
                        store.Tables.Add(table);
                    }
                }))
                {
                    task.Wait();
                }

                foreach (var table in bag)
                {
                    store.Tables.Add(table);
                }
                break;

            case ProcedureExecutionMode.Batch:
                BatchHelper.Calculate(_procedureContext);
                break;
            }

            EventsNotifier.Instance.Notify(ProcedureEvents.ProcedureAnalyzeStepSendResult);
            store.Tables.Add(EventsNotifier.Instance.NotifiedEvents.ToProcedureEventTable());

            return(store);
        }
コード例 #2
0
        private static AnalyzerTaskResult InternalAnalyzeAsync(ProcedureContext procedureContext, AdomdClient.AdomdConnection connection)
        {
            var queryResult       = default(DataTable);
            var profilerResult    = default(ProfilerResult);
            var performanceResult = default(PerformanceResult);

            using (var collectorsSynchronizer = CollectorsSynchronizer.Create(procedureContext.CancellationToken))
                using (var performanceTask = PerformanceCollector.StartAsync(procedureContext, collectorsSynchronizer))
                {
                    try
                    {
                        if (!performanceTask.IsFaulted && !procedureContext.IsCancellationRequested)
                        {
                            #region profiler collector

                            using (var profilerCancellation = CancellationTokenSource.CreateLinkedTokenSource(procedureContext.CancellationToken))
                                using (var profilerTask = ProfilerCollector.StartAsync(procedureContext, collectorsSynchronizer, profilerCancellation.Token))
                                {
                                    try
                                    {
                                        if (!profilerTask.IsFaulted && !profilerCancellation.IsCancellationRequested)
                                        {
                                            try
                                            {
                                                queryResult = AdomdClientHelper.ExecuteDataTable(
                                                    connection,
                                                    procedureContext.CancellationToken,
                                                    procedureContext.Statement,
                                                    activityID: procedureContext.ClientActivityID,
                                                    rowsLimit: procedureContext.QueryResultRowLimit,
                                                    beforeStart: () => EventsNotifier.Instance.Notify(ProcedureEvents.ProcedureAnalyzeStepExecuteStatement),
                                                    beforeWait: () => EventsNotifier.Instance.Notify(ProcedureEvents.ProcedureAnalyzeStepPendingOutcome)
                                                    );
                                            }
                                            finally
                                            {
                                                profilerCancellation.Cancel();
                                            }
                                        }
                                    }
                                    finally
                                    {
                                        profilerResult = profilerTask.Result;
                                    }
                                }

                            #endregion
                        }
                    }
                    finally
                    {
                        performanceResult = performanceTask.Result;
                    }
                }

            return(AnalyzerTaskResult.Create(queryResult, profilerResult, performanceResult));
        }
コード例 #3
0
        public DataSet CalculateForPrepare()
        {
            EventsNotifier.Instance.Notify(ProcedureEvents.ProcedureAnalyzeStepPrepare);

            var store = Calculate(AnalyzerTaskResult.CreateForPrepare(_procedureContext));

            Debug.Assert(store.Tables.Cast <DataTable>()
                         .Select(t => t.Rows.Count)
                         .Sum() == 0);

            return(store);
        }