Profiler notifications (#640)

* Initial changes for adding lost event notifications

* Handling polling errors by notifying listeners

* Restructuring lost events & testing

* Minor fixes to tests

* Add back in filtering

* Changing how lost events are found

* Cleaning up tests
This commit is contained in:
Madeline MacDonald
2018-06-18 17:43:22 -07:00
committed by GitHub
parent f244d307e2
commit 838a7e4fab
9 changed files with 271 additions and 17 deletions

View File

@@ -24,6 +24,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
private TimeSpan pollingDelay = DefaultPollingDelay;
private ProfilerEvent lastSeenEvent = null;
private bool eventsLost = false;
int lastSeenId = -1;
public bool pollImmediatly = false;
/// <summary>
@@ -87,6 +90,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
}
}
/// <summary>
/// Could events have been lost in the last poll
/// </summary>
public bool EventsLost
{
get
{
return this.eventsLost;
}
}
/// <summary>
/// Determine if an event was caused by the XEvent polling queries
/// </summary>
@@ -129,13 +143,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
/// </summary>
public void FilterOldEvents(List<ProfilerEvent> events)
{
if (lastSeenEvent != null)
this.eventsLost = false;
if (lastSeenId != -1)
{
// find the last event we've previously seen
bool foundLastEvent = false;
int idx = events.Count;
int earliestSeenEventId = int.Parse(events.LastOrDefault().Values["event_sequence"]);
while (--idx >= 0)
{
// update the furthest back event we've found so far
earliestSeenEventId = Math.Min(earliestSeenEventId, int.Parse(events[idx].Values["event_sequence"]));
if (events[idx].Equals(lastSeenEvent))
{
foundLastEvent = true;
@@ -148,11 +168,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
events.RemoveRange(0, idx + 1);
}
else if(earliestSeenEventId > (lastSeenId + 1))
{
// if there's a gap between the expected next event sequence
// and the furthest back event seen, we know we've lost events
this.eventsLost = true;
}
// save the last event so we know where to clean-up the list from next time
if (events.Count > 0)
{
lastSeenEvent = events.LastOrDefault();
lastSeenId = int.Parse(lastSeenEvent.Values["event_sequence"]);
}
}
else // first poll at start of session, all data is old
@@ -161,6 +188,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
if (events.Count > 0)
{
lastSeenEvent = events.LastOrDefault();
lastSeenId = int.Parse(lastSeenEvent.Values["event_sequence"]);
}
// ignore all events before the session began