Returning start/end and elapsed time with batch summaries (#92)

Returning start/end and elapsed timestamps for batches with the batch summary.
This commit is contained in:
Benjamin Russell
2016-10-13 12:14:22 -07:00
committed by GitHub
parent 2f876714ed
commit 2eeed98a63
3 changed files with 54 additions and 0 deletions

View File

@@ -30,6 +30,16 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
/// </summary>
private bool disposed;
/// <summary>
/// Local time when the execution and retrieval of files is finished
/// </summary>
private DateTime executionEndTime;
/// <summary>
/// Local time when the execution starts, specifically when the object is created
/// </summary>
private readonly DateTime executionStartTime;
/// <summary>
/// Factory for creating readers/writers for the output of the batch
/// </summary>
@@ -55,6 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
// Initialize the internal state
BatchText = batchText;
executionStartTime = DateTime.Now;
Selection = new SelectionData(startLine, startColumn, endLine, endColumn);
HasExecuted = false;
resultSets = new List<ResultSet>();
@@ -69,6 +80,30 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
/// </summary>
public string BatchText { get; set; }
/// <summary>
/// Localized timestamp for when the execution completed.
/// Stored in UTC ISO 8601 format; should be localized before displaying to any user
/// </summary>
public string ExecutionEndTimeStamp { get { return executionEndTime.ToString("o"); } }
/// <summary>
/// Localized timestamp for how long it took for the execution to complete
/// </summary>
public string ExecutionElapsedTime
{
get
{
TimeSpan elapsedTime = executionEndTime - executionStartTime;
return elapsedTime.ToString();
}
}
/// <summary>
/// Localized timestamp for when the execution began.
/// Stored in UTC ISO 8601 format; should be localized before displaying to any user
/// </summary>
public string ExecutionStartTimeStamp { get { return executionStartTime.ToString("o"); } }
/// <summary>
/// Whether or not this batch has an error
/// </summary>
@@ -218,6 +253,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
// Mark that we have executed
HasExecuted = true;
executionEndTime = DateTime.Now;
}
}

View File

@@ -10,6 +10,21 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
/// </summary>
public class BatchSummary
{
/// <summary>
/// Localized timestamp for how long it took for the execution to complete
/// </summary>
public string ExecutionElapsed { get; set; }
/// <summary>
/// Localized timestamp for when the execution completed.
/// </summary>
public string ExecutionEnd { get; set; }
/// <summary>
/// Localized timestamp for when the execution started.
/// </summary>
public string ExecutionStart { get; set; }
/// <summary>
/// Whether or not the batch was successful. True indicates errors, false indicates success
/// </summary>

View File

@@ -132,6 +132,9 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
return Batches.Select((batch, index) => new BatchSummary
{
Id = index,
ExecutionStart = batch.ExecutionStartTimeStamp,
ExecutionEnd = batch.ExecutionEndTimeStamp,
ExecutionElapsed = batch.ExecutionElapsedTime,
HasError = batch.HasError,
Messages = batch.ResultMessages.ToArray(),
ResultSetSummaries = batch.ResultSummaries,