コード例 #1
0
        /// <summary>
        /// Creates a new QueryMetrics from the backend delimited string and ClientSideMetrics.
        /// </summary>
        /// <param name="delimitedString">The backend delimited string to deserialize from.</param>
        /// <param name="clientSideMetrics">The additional client side metrics.</param>
        /// <returns>A new QueryMetrics.</returns>
        internal static QueryMetrics CreateFromDelimitedStringAndClientSideMetrics(string delimitedString, ClientSideMetrics clientSideMetrics)
        {
            Dictionary <string, double> metrics = QueryMetricsUtils.ParseDelimitedString(delimitedString);
            double indexHitRatio;
            double retrievedDocumentCount;

            metrics.TryGetValue(QueryMetricsConstants.IndexHitRatio, out indexHitRatio);
            metrics.TryGetValue(QueryMetricsConstants.RetrievedDocumentCount, out retrievedDocumentCount);
            long   indexHitCount = (long)(indexHitRatio * retrievedDocumentCount);
            double outputDocumentCount;

            metrics.TryGetValue(QueryMetricsConstants.OutputDocumentCount, out outputDocumentCount);
            double outputDocumentSize;

            metrics.TryGetValue(QueryMetricsConstants.OutputDocumentSize, out outputDocumentSize);
            double retrievedDocumentSize;

            metrics.TryGetValue(QueryMetricsConstants.RetrievedDocumentSize, out retrievedDocumentSize);
            TimeSpan totalQueryExecutionTime = QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.TotalQueryExecutionTimeInMs);

            return(new QueryMetrics(
                       (long)retrievedDocumentCount,
                       (long)retrievedDocumentSize,
                       (long)outputDocumentCount,
                       (long)outputDocumentSize,
                       indexHitCount,
                       totalQueryExecutionTime,
                       QueryPreparationTimes.CreateFromDelimitedString(delimitedString),
                       QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.IndexLookupTimeInMs),
                       QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.DocumentLoadTimeInMs),
                       QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.VMExecutionTimeInMs),
                       RuntimeExecutionTimes.CreateFromDelimitedString(delimitedString),
                       QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.DocumentWriteTimeInMs),
                       clientSideMetrics));
        }
コード例 #2
0
        /// <summary>
        /// Creates a new QueryMetrics that is the sum of all elements in an IEnumerable.
        /// </summary>
        /// <param name="queryMetricsList">The IEnumerable to aggregate.</param>
        /// <returns>A new QueryMetrics that is the sum of all elements in an IEnumerable.</returns>
        internal static QueryMetrics CreateFromIEnumerable(IEnumerable <QueryMetrics> queryMetricsList)
        {
            if (queryMetricsList == null)
            {
                throw new ArgumentNullException("queryMetricsList");
            }

            long     retrievedDocumentCount  = 0;
            long     retrievedDocumentSize   = 0;
            long     outputDocumentCount     = 0;
            long     outputDocumentSize      = 0;
            long     indexHitDocumentCount   = 0;
            TimeSpan totalQueryExecutionTime = new TimeSpan();
            List <QueryPreparationTimes> queryPreparationTimesList = new List <QueryPreparationTimes>();
            TimeSpan indexLookupTime  = new TimeSpan();
            TimeSpan documentLoadTime = new TimeSpan();
            TimeSpan vmExecutionTime  = new TimeSpan();
            List <RuntimeExecutionTimes> runtimeExecutionTimesList = new List <RuntimeExecutionTimes>();
            TimeSpan documentWriteTime = new TimeSpan();
            List <ClientSideMetrics> clientSideMetricsList = new List <ClientSideMetrics>();

            foreach (QueryMetrics queryMetrics in queryMetricsList)
            {
                if (queryMetrics == null)
                {
                    throw new ArgumentNullException("queryMetricsList can not have null elements");
                }

                retrievedDocumentCount  += queryMetrics.retrievedDocumentCount;
                retrievedDocumentSize   += queryMetrics.retrievedDocumentSize;
                outputDocumentCount     += queryMetrics.outputDocumentCount;
                outputDocumentSize      += queryMetrics.outputDocumentSize;
                indexHitDocumentCount   += queryMetrics.indexHitDocumentCount;
                totalQueryExecutionTime += queryMetrics.totalQueryExecutionTime;
                queryPreparationTimesList.Add(queryMetrics.queryPreparationTimes);
                indexLookupTime  += queryMetrics.indexLookupTime;
                documentLoadTime += queryMetrics.documentLoadTime;
                vmExecutionTime  += queryMetrics.vmExecutionTime;
                runtimeExecutionTimesList.Add(queryMetrics.runtimeExecutionTimes);
                documentWriteTime += queryMetrics.documentWriteTime;
                clientSideMetricsList.Add(queryMetrics.clientSideMetrics);
            }

            return(new QueryMetrics(
                       retrievedDocumentCount,
                       retrievedDocumentSize,
                       outputDocumentCount,
                       outputDocumentSize,
                       indexHitDocumentCount,
                       totalQueryExecutionTime,
                       QueryPreparationTimes.CreateFromIEnumerable(queryPreparationTimesList),
                       indexLookupTime,
                       documentLoadTime,
                       vmExecutionTime,
                       RuntimeExecutionTimes.CreateFromIEnumerable(runtimeExecutionTimesList),
                       documentWriteTime,
                       ClientSideMetrics.CreateFromIEnumerable(clientSideMetricsList)));
        }
コード例 #3
0
        private void WriteQueryPreparationTimes(QueryPreparationTimes queryPreparationTimes)
        {
            this.WriteBeforeQueryPreparationTimes();

            this.WriteQueryCompilationTime(queryPreparationTimes.QueryCompilationTime);
            this.WriteLogicalPlanBuildTime(queryPreparationTimes.LogicalPlanBuildTime);
            this.WritePhysicalPlanBuildTime(queryPreparationTimes.PhysicalPlanBuildTime);
            this.WriteQueryOptimizationTime(queryPreparationTimes.QueryOptimizationTime);

            this.WriteAfterQueryPreparationTimes();
        }
コード例 #4
0
        internal QueryMetrics(
            List <Guid> activityIds,
            long retrievedDocumentCount,
            long retrievedDocumentSize,
            long outputDocumentCount,
            long outputDocumentSize,
            long indexHitDocumentCount,
            TimeSpan totalQueryExecutionTime,
            QueryPreparationTimes queryPreparationTimes,
            TimeSpan indexLookupTime,
            TimeSpan documentLoadTime,
            TimeSpan vmExecutionTime,
            RuntimeExecutionTimes runtimeExecutionTimes,
            TimeSpan documentWriteTime,
            ClientSideMetrics clientSideMetrics)
        {
            if (activityIds == null)
            {
                throw new ArgumentNullException($"{nameof(activityIds)} can not be null.");
            }

            if (queryPreparationTimes == null)
            {
                throw new ArgumentNullException($"{nameof(queryPreparationTimes)} can not be null.");
            }

            if (runtimeExecutionTimes == null)
            {
                throw new ArgumentNullException($"{nameof(runtimeExecutionTimes)} can not be null.");
            }

            if (clientSideMetrics == null)
            {
                throw new ArgumentNullException($"{nameof(clientSideMetrics)} can not be null.");
            }

            this.ActivityIds             = activityIds;
            this.RetrievedDocumentCount  = retrievedDocumentCount;
            this.RetrievedDocumentSize   = retrievedDocumentSize;
            this.OutputDocumentCount     = outputDocumentCount;
            this.OutputDocumentSize      = outputDocumentSize;
            this.IndexHitDocumentCount   = indexHitDocumentCount;
            this.TotalQueryExecutionTime = totalQueryExecutionTime;
            this.QueryPreparationTimes   = queryPreparationTimes;
            this.IndexLookupTime         = indexLookupTime;
            this.DocumentLoadTime        = documentLoadTime;
            this.VMExecutionTime         = vmExecutionTime;
            this.RuntimeExecutionTimes   = runtimeExecutionTimes;
            this.DocumentWriteTime       = documentWriteTime;
            this.ClientSideMetrics       = clientSideMetrics;
        }
コード例 #5
0
        internal QueryMetrics(
            long retrievedDocumentCount,
            long retrievedDocumentSize,
            long outputDocumentCount,
            long outputDocumentSize,
            long indexHitDocumentCount,
            TimeSpan totalQueryExecutionTime,
            QueryPreparationTimes queryPreparationTimes,
            TimeSpan indexLookupTime,
            TimeSpan documentLoadTime,
            TimeSpan vmExecutionTime,
            RuntimeExecutionTimes runtimeExecutionTimes,
            TimeSpan documentWriteTime,
            ClientSideMetrics clientSideMetrics)
        {
            if (queryPreparationTimes == null)
            {
                throw new ArgumentNullException($"{nameof(queryPreparationTimes)} can not be null.");
            }

            if (runtimeExecutionTimes == null)
            {
                throw new ArgumentNullException($"{nameof(runtimeExecutionTimes)} can not be null.");
            }

            if (clientSideMetrics == null)
            {
                throw new ArgumentNullException($"{nameof(clientSideMetrics)} can not be null.");
            }

            this.retrievedDocumentCount  = retrievedDocumentCount;
            this.retrievedDocumentSize   = retrievedDocumentSize;
            this.outputDocumentCount     = outputDocumentCount;
            this.outputDocumentSize      = outputDocumentSize;
            this.indexHitDocumentCount   = indexHitDocumentCount;
            this.totalQueryExecutionTime = totalQueryExecutionTime;
            this.queryPreparationTimes   = queryPreparationTimes;
            this.indexLookupTime         = indexLookupTime;
            this.documentLoadTime        = documentLoadTime;
            this.vmExecutionTime         = vmExecutionTime;
            this.runtimeExecutionTimes   = runtimeExecutionTimes;
            this.documentWriteTime       = documentWriteTime;
            this.clientSideMetrics       = clientSideMetrics;
            this.queryEngineTimes        = new QueryEngineTimes(indexLookupTime, documentLoadTime, vmExecutionTime, documentWriteTime, runtimeExecutionTimes);
        }
コード例 #6
0
        /// <summary>
        /// Creates a new QueryMetrics that is the sum of all elements in an IEnumerable.
        /// </summary>
        /// <param name="queryMetricsList">The IEnumerable to aggregate.</param>
        /// <returns>A new QueryMetrics that is the sum of all elements in an IEnumerable.</returns>
        internal static QueryMetrics CreateFromIEnumerable(IEnumerable <QueryMetrics> queryMetricsList)
        {
            if (queryMetricsList == null)
            {
                throw new ArgumentNullException("queryMetricsList");
            }

            List <Guid> activityIds             = new List <Guid>();
            long        retrievedDocumentCount  = 0;
            long        retrievedDocumentSize   = 0;
            long        outputDocumentCount     = 0;
            long        outputDocumentSize      = 0;
            long        indexHitDocumentCount   = 0;
            TimeSpan    totalQueryExecutionTime = new TimeSpan();
            List <QueryPreparationTimes> queryPreparationTimesList = new List <QueryPreparationTimes>();
            TimeSpan indexLookupTime  = new TimeSpan();
            TimeSpan documentLoadTime = new TimeSpan();
            TimeSpan vmExecutionTime  = new TimeSpan();
            List <RuntimeExecutionTimes> runtimeExecutionTimesList = new List <RuntimeExecutionTimes>();
            TimeSpan documentWriteTime = new TimeSpan();
            List <ClientSideMetrics> clientSideMetricsList = new List <ClientSideMetrics>();

            foreach (QueryMetrics queryMetrics in queryMetricsList)
            {
                if (queryMetrics == null)
                {
                    throw new ArgumentNullException("queryMetricsList can not have null elements");
                }

                activityIds              = activityIds.Concat(queryMetrics.ActivityIds.Where((activityId) => activityId != Guid.Empty)).ToList();
                retrievedDocumentCount  += queryMetrics.RetrievedDocumentCount;
                retrievedDocumentSize   += queryMetrics.RetrievedDocumentSize;
                outputDocumentCount     += queryMetrics.OutputDocumentCount;
                outputDocumentSize      += queryMetrics.OutputDocumentSize;
                indexHitDocumentCount   += queryMetrics.IndexHitDocumentCount;
                totalQueryExecutionTime += queryMetrics.TotalQueryExecutionTime;
                queryPreparationTimesList.Add(queryMetrics.QueryPreparationTimes);
                indexLookupTime  += queryMetrics.IndexLookupTime;
                documentLoadTime += queryMetrics.DocumentLoadTime;
                vmExecutionTime  += queryMetrics.VMExecutionTime;
                runtimeExecutionTimesList.Add(queryMetrics.RuntimeExecutionTimes);
                documentWriteTime += queryMetrics.DocumentWriteTime;
                clientSideMetricsList.Add(queryMetrics.ClientSideMetrics);
            }

            return(new QueryMetrics(
                       activityIds,
                       retrievedDocumentCount,
                       retrievedDocumentSize,
                       outputDocumentCount,
                       outputDocumentSize,
                       indexHitDocumentCount,
                       totalQueryExecutionTime,
                       QueryPreparationTimes.CreateFromIEnumerable(queryPreparationTimesList),
                       indexLookupTime,
                       documentLoadTime,
                       vmExecutionTime,
                       RuntimeExecutionTimes.CreateFromIEnumerable(runtimeExecutionTimesList),
                       documentWriteTime,
                       ClientSideMetrics.CreateFromIEnumerable(clientSideMetricsList)));
        }