Exemplo n.º 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="indexUtilization">The index utilization from the backend</param>
        /// <param name="clientSideMetrics">The additional client side metrics.</param>
        /// <returns>A new QueryMetrics.</returns>
        internal static QueryMetrics CreateFromDelimitedStringAndClientSideMetrics(string delimitedString, string indexUtilization, ClientSideMetrics clientSideMetrics)
        {
            Dictionary <string, double> metrics = QueryMetricsUtils.ParseDelimitedString(delimitedString);

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

            metrics.TryGetValue(QueryMetricsConstants.OutputDocumentCount, out double outputDocumentCount);
            metrics.TryGetValue(QueryMetricsConstants.OutputDocumentSize, out double outputDocumentSize);
            metrics.TryGetValue(QueryMetricsConstants.RetrievedDocumentSize, out double retrievedDocumentSize);
            TimeSpan totalQueryExecutionTime = QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.TotalQueryExecutionTimeInMs);

            IndexUtilizationInfo.TryCreateFromDelimitedString(indexUtilization, out IndexUtilizationInfo indexUtilizationInfo);
            return(new QueryMetrics(
                       (long)retrievedDocumentCount,
                       (long)retrievedDocumentSize,
                       (long)outputDocumentCount,
                       (long)outputDocumentSize,
                       indexHitCount,
                       indexUtilizationInfo,
                       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));
        }
        /// <summary>
        /// Creates a new QueryPreparationTimes from the backend delimited string.
        /// </summary>
        /// <param name="delimitedString">The backend delimited string to deserialize from.</param>
        /// <returns>A new QueryPreparationTimes from the backend delimited string.</returns>
        internal static QueryPreparationTimes CreateFromDelimitedString(string delimitedString)
        {
            Dictionary <string, double> metrics = QueryMetricsUtils.ParseDelimitedString(delimitedString);

            return(new QueryPreparationTimes(
                       QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.QueryCompileTimeInMs),
                       QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.LogicalPlanBuildTimeInMs),
                       QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.PhysicalPlanBuildTimeInMs),
                       QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.QueryOptimizationTimeInMs)));
        }
        public static TimeSpan TimeSpanFromMetrics(Dictionary <string, double> metrics, string key)
        {
            double   timeSpanInMilliseconds;
            TimeSpan timeSpanFromMetrics;

            if (metrics.TryGetValue(key, out timeSpanInMilliseconds))
            {
                // Can not use TimeSpan.FromMilliseconds since double has a loss of precision
                timeSpanFromMetrics = QueryMetricsUtils.DoubleMillisecondsToTimeSpan(timeSpanInMilliseconds);
            }
            else
            {
                timeSpanFromMetrics = default(TimeSpan);
            }

            return(timeSpanFromMetrics);
        }
        /// <summary>
        /// Creates a new RuntimeExecutionTimes from the backend delimited string.
        /// </summary>
        /// <param name="delimitedString">The backend delimited string to deserialize from.</param>
        /// <returns>A new RuntimeExecutionTimes from the backend delimited string.</returns>
        internal static RuntimeExecutionTimes CreateFromDelimitedString(string delimitedString)
        {
            Dictionary <string, double> metrics = QueryMetricsUtils.ParseDelimitedString(delimitedString);

            TimeSpan vmExecutionTime = QueryMetricsUtils.TimeSpanFromMetrics(
                metrics,
                QueryMetricsConstants.VMExecutionTimeInMs);
            TimeSpan indexLookupTime = QueryMetricsUtils.TimeSpanFromMetrics(
                metrics,
                QueryMetricsConstants.IndexLookupTimeInMs);
            TimeSpan documentLoadTime = QueryMetricsUtils.TimeSpanFromMetrics(
                metrics,
                QueryMetricsConstants.DocumentLoadTimeInMs);
            TimeSpan documentWriteTime = QueryMetricsUtils.TimeSpanFromMetrics(
                metrics,
                QueryMetricsConstants.DocumentWriteTimeInMs);

            return(new RuntimeExecutionTimes(
                       vmExecutionTime - indexLookupTime - documentLoadTime - documentWriteTime,
                       QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.SystemFunctionExecuteTimeInMs),
                       QueryMetricsUtils.TimeSpanFromMetrics(metrics, QueryMetricsConstants.UserDefinedFunctionExecutionTimeInMs)));
        }