Stopping sessions when handling stop requests (#627)

* Dropping profiler session on stop request

* Changes to IXEventSession to simplify dropping sessions

* Stop sessions instead of dropping, disable flaky tests
This commit is contained in:
Madeline MacDonald
2018-06-05 13:48:55 -07:00
committed by GitHub
parent b41c19bd25
commit 35b19320d4
9 changed files with 235 additions and 161 deletions

View File

@@ -27,6 +27,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
/// <summary>
/// Stops monitoring a profiler session
/// </summary>
bool StopMonitoringSession(string sessionId);
bool StopMonitoringSession(string sessionId, out ProfilerSession session);
}
}

View File

@@ -14,5 +14,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
/// Reads XEvent XML from the default session target
/// </summary>
string GetTargetXml();
/// <summary>
/// Stops XEvent session
/// </summary>
void Stop();
}
}

View File

@@ -154,7 +154,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
try
{
monitor.StopMonitoringSession(parameters.OwnerUri);
ProfilerSession session;
monitor.StopMonitoringSession(parameters.OwnerUri, out session);
session.XEventSession.Stop();
await requestContext.SendResult(new StopProfilingResult
{
Succeeded = true
@@ -163,7 +166,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
catch (Exception e)
{
await requestContext.SendError(e);
}
}
}
/// <summary>
@@ -224,9 +227,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
private static Session CreateSession(SqlStoreConnection connection, string sessionName)
{
string createSessionSql =
string createSessionSql =
@"
CREATE EVENT SESSION [Profiler] ON SERVER
CREATE EVENT SESSION [Profiler] ON SERVER
ADD EVENT sqlserver.attention(
ACTION(package0.event_sequence,sqlserver.client_app_name,sqlserver.client_pid,sqlserver.database_id,sqlserver.nt_username,sqlserver.query_hash,sqlserver.server_principal_name,sqlserver.session_id)
WHERE ([package0].[equal_boolean]([sqlserver].[is_system],(0)))),
@@ -251,7 +254,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
connection.ServerConnection.ExecuteNonQuery(createSessionSql);
XEStore store = new XEStore(connection);
return store.Sessions[sessionName];
return store.Sessions[sessionName];
}
/// <summary>
@@ -275,7 +278,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
public void Dispose()
{
if (!disposed)
{
{
disposed = true;
}
}

View File

@@ -72,17 +72,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
/// <summary>
/// Stop monitoring the session specified by the sessionId
/// </summary>
public bool StopMonitoringSession(string sessionId)
public bool StopMonitoringSession(string sessionId, out ProfilerSession session)
{
lock (this.sessionsLock)
{
if (this.monitoredSessions.ContainsKey(sessionId))
{
ProfilerSession session;
return this.monitoredSessions.Remove(sessionId, out session);
}
else
{
session = null;
return false;
}
}

View File

@@ -14,6 +14,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
public Session Session { get; set; }
public void Stop()
{
this.Session.Stop();
}
public string GetTargetXml()
{
if (this.Session == null)