Exemplo n.º 1
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());
        }