/// <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)); }
/// <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 void AppendMillisecondsToStringBuilder(StringBuilder stringBuilder, string property, double milliseconds, int indentLevel) { const string MillisecondsFormatString = "{0:n2}"; const string MillisecondsUnitString = "milliseconds"; QueryMetricsUtils.AppendToStringBuilder( stringBuilder, property, string.Format(CultureInfo.InvariantCulture, MillisecondsFormatString, milliseconds), MillisecondsUnitString, indentLevel); }
public static void AppendBytesToStringBuilder(StringBuilder stringBuilder, string property, long bytes, int indentLevel) { const string BytesFormatString = "{0:n0}"; const string BytesUnitString = "bytes"; QueryMetricsUtils.AppendToStringBuilder( stringBuilder, property, string.Format(CultureInfo.InvariantCulture, BytesFormatString, bytes), BytesUnitString, indentLevel); }
public static void AppendRUToStringBuilder(StringBuilder stringBuilder, string property, double requestCharge, int indentLevel) { const string RequestChargeFormatString = "{0:n2}"; const string RequestChargeUnitString = "RUs"; QueryMetricsUtils.AppendToStringBuilder( stringBuilder, property, string.Format(CultureInfo.InvariantCulture, RequestChargeFormatString, requestCharge), RequestChargeUnitString, indentLevel); }
public static void AppendPercentageToStringBuilder(StringBuilder stringBuilder, string property, double percentage, int indentLevel) { const string PercentageFormatString = "{0:n2}"; const string PercentageUnitString = "%"; QueryMetricsUtils.AppendToStringBuilder( stringBuilder, property, string.Format(CultureInfo.InvariantCulture, PercentageFormatString, percentage * 100), PercentageUnitString, indentLevel); }
public static void AppendCountToStringBuilder(StringBuilder stringBuilder, string property, long count, int indentLevel) { const string CountFormatString = "{0:n0}"; const string CountUnitString = ""; QueryMetricsUtils.AppendToStringBuilder( stringBuilder, property, string.Format(CultureInfo.InvariantCulture, CountFormatString, count), CountUnitString, indentLevel); }
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> /// Gets a human readable plain text of the QueryPreparationTimes (Please use monospace font). /// </summary> /// <param name="indentLevel">The indent / nesting level of the QueryPreparationTimes object.</param> /// <returns>A human readable plain text of the QueryPreparationTimes.</returns> public string ToTextString(int indentLevel = 0) { if (indentLevel == int.MaxValue) { throw new ArgumentOutOfRangeException("indentLevel", "input must be less than Int32.MaxValue"); } StringBuilder stringBuilder = new StringBuilder(); // Checked block is needed to suppress potential overflow warning ... even though I check it above checked { QueryMetricsUtils.AppendHeaderToStringBuilder( stringBuilder, QueryMetricsConstants.QueryPreparationTimesText, indentLevel); QueryMetricsUtils.AppendMillisecondsToStringBuilder( stringBuilder, QueryMetricsConstants.QueryCompileTimeText, this.QueryCompilationTime.TotalMilliseconds, indentLevel + 1); QueryMetricsUtils.AppendMillisecondsToStringBuilder( stringBuilder, QueryMetricsConstants.LogicalPlanBuildTimeText, this.LogicalPlanBuildTime.TotalMilliseconds, indentLevel + 1); QueryMetricsUtils.AppendMillisecondsToStringBuilder( stringBuilder, QueryMetricsConstants.PhysicalPlanBuildTimeText, this.PhysicalPlanBuildTime.TotalMilliseconds, indentLevel + 1); QueryMetricsUtils.AppendMillisecondsToStringBuilder( stringBuilder, QueryMetricsConstants.QueryOptimizationTimeText, this.QueryOptimizationTime.TotalMilliseconds, indentLevel + 1); } return(stringBuilder.ToString()); }
/// <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))); }
/// <summary> /// Gets a human readable plain text of the RuntimeExecutionTimes (Please use monospace font). /// </summary> /// <param name="indentLevel">The indent / nesting level of the RuntimeExecutionTimes.</param> /// <returns>A human readable plain text of the QueryMetrics.</returns> public string ToTextString(int indentLevel = 0) { if (indentLevel == int.MaxValue) { throw new ArgumentOutOfRangeException("indentLevel", "input must be less than Int32.MaxValue"); } StringBuilder stringBuilder = new StringBuilder(); // Checked block is needed to suppress potential overflow warning ... even though I check it above checked { QueryMetricsUtils.AppendHeaderToStringBuilder( stringBuilder, QueryMetricsConstants.RuntimeExecutionTimesText, indentLevel); QueryMetricsUtils.AppendMillisecondsToStringBuilder( stringBuilder, QueryMetricsConstants.TotalExecutionTimeText, this.QueryEngineExecutionTime.TotalMilliseconds, indentLevel + 1); QueryMetricsUtils.AppendMillisecondsToStringBuilder( stringBuilder, QueryMetricsConstants.SystemFunctionExecuteTimeText, this.SystemFunctionExecutionTime.TotalMilliseconds, indentLevel + 1); QueryMetricsUtils.AppendMillisecondsToStringBuilder( stringBuilder, QueryMetricsConstants.UserDefinedFunctionExecutionTimeText, this.UserDefinedFunctionExecutionTime.TotalMilliseconds, indentLevel + 1); } return(stringBuilder.ToString()); }
public static void AppendNewlineToStringBuilder(StringBuilder stringBuilder) { QueryMetricsUtils.AppendHeaderToStringBuilder(stringBuilder, string.Empty, 0); }
/// <summary> /// Gets a human readable plain text of the QueryMetrics (Please use monospace font). /// </summary> /// <param name="indentLevel">The level of nesting / indenting of this object.</param> /// <returns>A human readable plain text of the QueryMetrics.</returns> internal string ToTextString(int indentLevel = 0) { if (indentLevel == int.MaxValue) { throw new ArgumentOutOfRangeException("indentLevel", "input must be less than Int32.MaxValue"); } StringBuilder stringBuilder = new StringBuilder(); checked { // Top level properties QueryMetricsUtils.AppendCountToStringBuilder( stringBuilder, QueryMetricsConstants.RetrievedDocumentCountText, this.RetrievedDocumentCount, indentLevel); QueryMetricsUtils.AppendBytesToStringBuilder( stringBuilder, QueryMetricsConstants.RetrievedDocumentSizeText, this.RetrievedDocumentSize, indentLevel); QueryMetricsUtils.AppendCountToStringBuilder( stringBuilder, QueryMetricsConstants.OutputDocumentCountText, this.OutputDocumentCount, indentLevel); QueryMetricsUtils.AppendBytesToStringBuilder( stringBuilder, QueryMetricsConstants.OutputDocumentSizeText, this.OutputDocumentSize, indentLevel); QueryMetricsUtils.AppendPercentageToStringBuilder( stringBuilder, QueryMetricsConstants.IndexUtilizationText, this.IndexHitRatio, indentLevel); QueryMetricsUtils.AppendMillisecondsToStringBuilder( stringBuilder, QueryMetricsConstants.TotalQueryExecutionTimeText, this.TotalQueryExecutionTime.TotalMilliseconds, indentLevel); // QueryPreparationTimes stringBuilder.Append(this.QueryPreparationTimes.ToTextString(indentLevel + 1)); QueryMetricsUtils.AppendMillisecondsToStringBuilder( stringBuilder, QueryMetricsConstants.IndexLookupTimeText, this.IndexLookupTime.TotalMilliseconds, indentLevel + 1); QueryMetricsUtils.AppendMillisecondsToStringBuilder( stringBuilder, QueryMetricsConstants.DocumentLoadTimeText, this.DocumentLoadTime.TotalMilliseconds, indentLevel + 1); // VM Execution Time is not emitted since the user does not have any context // RuntimesExecutionTimes stringBuilder.Append(this.RuntimeExecutionTimes.ToTextString(indentLevel + 1)); QueryMetricsUtils.AppendMillisecondsToStringBuilder( stringBuilder, QueryMetricsConstants.WriteOutputTimeText, this.DocumentWriteTime.TotalMilliseconds, indentLevel + 1); // Client Side Metrics stringBuilder.Append(this.ClientSideMetrics.ToTextString(indentLevel + 1)); // Activity Ids QueryMetricsUtils.AppendActivityIdsToStringBuilder(stringBuilder, QueryMetricsConstants.ActivityIds, this.ActivityIds, indentLevel); } return(stringBuilder.ToString()); }
/// <summary> /// Gets a human readable plain text of the ClientSideMetrics (Please use monospace font). /// </summary> /// <param name="indentLevel">The indent / nesting level of the ClientSideMetrics.</param> /// <returns>A human readable plain text of the ClientSideMetrics.</returns> public string ToTextString(int indentLevel = 0) { if (indentLevel == int.MaxValue) { throw new ArgumentOutOfRangeException("indentLevel", "input must be less than Int32.MaxValue"); } StringBuilder stringBuilder = new StringBuilder(); checked { // Properties QueryMetricsUtils.AppendHeaderToStringBuilder( stringBuilder, QueryMetricsConstants.ClientSideQueryMetricsText, indentLevel); QueryMetricsUtils.AppendCountToStringBuilder( stringBuilder, QueryMetricsConstants.RetriesText, this.Retries, indentLevel + 1); QueryMetricsUtils.AppendRUToStringBuilder( stringBuilder, QueryMetricsConstants.RequestChargeText, this.RequestCharge, indentLevel + 1); QueryMetricsUtils.AppendNewlineToStringBuilder(stringBuilder); // Building the table for fetch execution ranges QueryMetricsUtils.AppendHeaderToStringBuilder(stringBuilder, QueryMetricsConstants.FetchExecutionRangesText, 1); QueryMetricsUtils.AppendHeaderToStringBuilder(stringBuilder, PartitionExecutionTimelineTable.TopLine, 1); QueryMetricsUtils.AppendHeaderToStringBuilder(stringBuilder, PartitionExecutionTimelineTable.Header, 1); QueryMetricsUtils.AppendHeaderToStringBuilder(stringBuilder, PartitionExecutionTimelineTable.MiddleLine, 1); foreach (FetchExecutionRange fetchExecutionRange in this.FetchExecutionRanges.OrderBy(fetchExecutionRange => fetchExecutionRange.StartTime)) { QueryMetricsUtils.AppendHeaderToStringBuilder( stringBuilder, PartitionExecutionTimelineTable.GetRow( fetchExecutionRange.PartitionId, fetchExecutionRange.StartTime.ToUniversalTime().ToString("hh:mm:ss.ffffff"), fetchExecutionRange.EndTime.ToUniversalTime().ToString("hh:mm:ss.ffffff"), (fetchExecutionRange.EndTime - fetchExecutionRange.StartTime).TotalMilliseconds.ToString("0.00"), fetchExecutionRange.NumberOfDocuments, fetchExecutionRange.RetryCount), 1); } QueryMetricsUtils.AppendHeaderToStringBuilder(stringBuilder, PartitionExecutionTimelineTable.BottomLine, 1); QueryMetricsUtils.AppendNewlineToStringBuilder(stringBuilder); // Building the table for scheduling metrics QueryMetricsUtils.AppendHeaderToStringBuilder(stringBuilder, QueryMetricsConstants.SchedulingMetricsText, 1); QueryMetricsUtils.AppendHeaderToStringBuilder(stringBuilder, SchedulingMetricsTable.TopLine, 1); QueryMetricsUtils.AppendHeaderToStringBuilder(stringBuilder, SchedulingMetricsTable.Header, 1); QueryMetricsUtils.AppendHeaderToStringBuilder(stringBuilder, SchedulingMetricsTable.MiddleLine, 1); foreach (Tuple <string, SchedulingTimeSpan> partitionSchedulingTimeSpan in this.PartitionSchedulingTimeSpans.OrderBy(x => x.Item2.ResponseTime)) { string partitionId = partitionSchedulingTimeSpan.Item1; SchedulingTimeSpan schedulingTimeSpan = partitionSchedulingTimeSpan.Item2; QueryMetricsUtils.AppendHeaderToStringBuilder( stringBuilder, SchedulingMetricsTable.GetRow( partitionId, schedulingTimeSpan.ResponseTime.TotalMilliseconds.ToString("0.00"), schedulingTimeSpan.RunTime.TotalMilliseconds.ToString("0.00"), schedulingTimeSpan.WaitTime.TotalMilliseconds.ToString("0.00"), schedulingTimeSpan.TurnaroundTime.TotalMilliseconds.ToString("0.00"), schedulingTimeSpan.NumPreemptions), 1); } QueryMetricsUtils.AppendHeaderToStringBuilder(stringBuilder, SchedulingMetricsTable.BottomLine, 1); } return(stringBuilder.ToString()); }