Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ProcessInfo command to Diagnostics Server #38967

Merged
merged 19 commits into from
Jul 20, 2020
49 changes: 0 additions & 49 deletions src/coreclr/src/vm/diagnosticserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ DWORD WINAPI DiagnosticServer::DiagnosticsServerThread(LPVOID)

switch ((DiagnosticsIpc::DiagnosticServerCommandSet)message.GetHeader().CommandSet)
{
case DiagnosticsIpc::DiagnosticServerCommandSet::Server:
DiagnosticServerProtocolHelper::HandleIpcMessage(message, pStream);
break;

case DiagnosticsIpc::DiagnosticServerCommandSet::EventPipe:
EventPipeProtocolHelper::HandleIpcMessage(message, pStream);
break;
Expand Down Expand Up @@ -296,49 +292,4 @@ void DiagnosticServer::ResumeRuntimeStartup()
s_ResumeRuntimeStartupEvent->Set();
}

void DiagnosticServerProtocolHelper::HandleIpcMessage(DiagnosticsIpc::IpcMessage& message, IpcStream* pStream)
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
MODE_ANY;
PRECONDITION(pStream != nullptr);
}
CONTRACTL_END;

switch ((DiagnosticsIpc::DiagnosticServerCommandId)message.GetHeader().CommandId)
{
case DiagnosticsIpc::DiagnosticServerCommandId::ResumeRuntime:
DiagnosticServerProtocolHelper::ResumeRuntimeStartup(message, pStream);
break;

default:
STRESS_LOG1(LF_DIAGNOSTICS_PORT, LL_WARNING, "Received unknown request type (%d)\n", message.GetHeader().CommandSet);
DiagnosticsIpc::IpcMessage::SendErrorMessage(pStream, CORDIAGIPC_E_UNKNOWN_COMMAND);
delete pStream;
break;
}
}

void DiagnosticServerProtocolHelper::ResumeRuntimeStartup(DiagnosticsIpc::IpcMessage& message, IpcStream *pStream)
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
MODE_PREEMPTIVE;
PRECONDITION(pStream != nullptr);
}
CONTRACTL_END;

// no payload
DiagnosticServer::ResumeRuntimeStartup();
HRESULT res = S_OK;

DiagnosticsIpc::IpcMessage successResponse;
if (successResponse.Initialize(DiagnosticsIpc::GenericSuccessHeader, res))
successResponse.Send(pStream);
}

#endif // FEATURE_PERFTRACING
8 changes: 0 additions & 8 deletions src/coreclr/src/vm/diagnosticserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ class DiagnosticServer final
static CLREventStatic *s_ResumeRuntimeStartupEvent;
};

class DiagnosticServerProtocolHelper
{
public:
// IPC event handlers.
static void HandleIpcMessage(DiagnosticsIpc::IpcMessage& message, IpcStream *pStream);
static void ResumeRuntimeStartup(DiagnosticsIpc::IpcMessage& message, IpcStream *pStream);
};

#endif // FEATURE_PERFTRACING

#endif // __DIAGNOSTIC_SERVER_H__
13 changes: 1 addition & 12 deletions src/coreclr/src/vm/diagnosticsprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,10 @@ namespace DiagnosticsIpc
Server = 0xFF,
};

// Overlaps with DiagnosticServerResponseId
// DON'T create overlapping values
enum class DiagnosticServerCommandId : uint8_t
{
// 0x00 used in DiagnosticServerResponseId
ResumeRuntime = 0x01,
jander-msft marked this conversation as resolved.
Show resolved Hide resolved
// 0xFF used DiagnosticServerResponseId
};

// Overlaps with DiagnosticServerCommandId
// DON'T create overlapping values
enum class DiagnosticServerResponseId : uint8_t
{
OK = 0x00,
// 0x01 used in DiagnosticServerCommandId
// future
Error = 0xFF,
};

Expand Down
26 changes: 26 additions & 0 deletions src/coreclr/src/vm/processdiagnosticsprotocolhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "processdiagnosticsprotocolhelper.h"
#include "eventpipeeventsource.h"
#include "diagnosticsprotocol.h"
#include "diagnosticserver.h"

#ifdef FEATURE_PERFTRACING

Expand Down Expand Up @@ -160,6 +161,31 @@ void ProcessDiagnosticsProtocolHelper::GetProcessInfo(DiagnosticsIpc::IpcMessage
delete pStream;
}

void ProcessDiagnosticsProtocolHelper::ResumeRuntimeStartup(DiagnosticsIpc::IpcMessage& message, IpcStream *pStream)
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
MODE_PREEMPTIVE;
PRECONDITION(pStream != nullptr);
}
CONTRACTL_END;

// no payload
DiagnosticServer::ResumeRuntimeStartup();
HRESULT res = S_OK;

DiagnosticsIpc::IpcMessage successResponse;
const bool fSuccess = successResponse.Initialize(DiagnosticsIpc::GenericSuccessHeader, res) ?
successResponse.Send(pStream) :
DiagnosticsIpc::IpcMessage::SendErrorMessage(pStream, E_FAIL);
if (!fSuccess)
STRESS_LOG0(LF_DIAGNOSTICS_PORT, LL_WARNING, "Failed to send DiagnosticsIPC response");

delete pStream;
}

void ProcessDiagnosticsProtocolHelper::HandleIpcMessage(DiagnosticsIpc::IpcMessage& message, IpcStream* pStream)
{
CONTRACTL
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/vm/processdiagnosticsprotocolhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class IpcStream;
enum class ProcessCommandId : uint8_t
{
GetProcessInfo = 0x00,
ResumeRuntime = 0x01,
// future
};

Expand Down Expand Up @@ -50,6 +51,7 @@ class ProcessDiagnosticsProtocolHelper
// IPC event handlers.
static void HandleIpcMessage(DiagnosticsIpc::IpcMessage& message, IpcStream *pStream);
static void GetProcessInfo(DiagnosticsIpc::IpcMessage& message, IpcStream *pStream);
static void ProcessDiagnosticsProtocolHelper::ResumeRuntimeStartup(DiagnosticsIpc::IpcMessage& message, IpcStream *pStream);
};

#endif // FEATURE_PERFTRACING
Expand Down
20 changes: 10 additions & 10 deletions src/tests/tracing/eventpipe/pauseonstart/pauseonstart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public static async Task<bool> TEST_RuntimeResumesExecutionWithCommand()
Stream stream = await server.AcceptAsync();
IpcAdvertise advertise = IpcAdvertise.Parse(stream);
Logger.logger.Log(advertise.ToString());
// send ResumeRuntime command (0xFF=ServerCommandSet, 0x01=ResumeRuntime commandid)
var message = new IpcMessage(0xFF,0x01);
// send ResumeRuntime command (0x04=ProcessCommandSet, 0x01=ResumeRuntime commandid)
var message = new IpcMessage(0x04,0x01);
Logger.logger.Log($"Sent: {message.ToString()}");
IpcMessage response = IpcClient.SendMessage(stream, message);
Logger.logger.Log($"received: {response.ToString()}");
Expand Down Expand Up @@ -75,8 +75,8 @@ public static async Task<bool> TEST_TracesHaveRelevantEvents()
Task readerTask = eventStream.CopyToAsync(memoryStream);

Logger.logger.Log($"Send ResumeRuntime Diagnostics IPC Command");
// send ResumeRuntime command (0xFF=ServerCommandSet, 0x01=ResumeRuntime commandid)
var message = new IpcMessage(0xFF,0x01);
// send ResumeRuntime command (0x04=ProcessCommandSet, 0x01=ResumeRuntime commandid)
var message = new IpcMessage(0x04,0x01);
Logger.logger.Log($"Sent: {message.ToString()}");
IpcMessage response = IpcClient.SendMessage(stream, message);
Logger.logger.Log($"received: {response.ToString()}");
Expand Down Expand Up @@ -145,8 +145,8 @@ public static async Task<bool> TEST_MultipleSessionsCanBeStartedWhilepaused()


Logger.logger.Log($"Send ResumeRuntime Diagnostics IPC Command");
// send ResumeRuntime command (0xFF=ServerCommandSet, 0x01=ResumeRuntime commandid)
var message = new IpcMessage(0xFF,0x01);
// send ResumeRuntime command (0x04=ProcessCommandSet, 0x01=ResumeRuntime commandid)
var message = new IpcMessage(0x04,0x01);
Logger.logger.Log($"Sent: {message.ToString()}");
IpcMessage response = IpcClient.SendMessage(stream, message);
Logger.logger.Log($"received: {response.ToString()}");
Expand Down Expand Up @@ -247,8 +247,8 @@ public static async Task<bool> TEST_CanStartAndStopSessionWhilepaused()
Logger.logger.Log("Stopped EventPipeSession over standard connection");

Logger.logger.Log($"Send ResumeRuntime Diagnostics IPC Command");
// send ResumeRuntime command (0xFF=ServerCommandSet, 0x01=ResumeRuntime commandid)
var message = new IpcMessage(0xFF,0x01);
// send ResumeRuntime command (0x04=ProcessCommandSet, 0x01=ResumeRuntime commandid)
var message = new IpcMessage(0x04,0x01);
Logger.logger.Log($"Sent: {message.ToString()}");
IpcMessage response = IpcClient.SendMessage(stream, message);
Logger.logger.Log($"received: {response.ToString()}");
Expand Down Expand Up @@ -292,8 +292,8 @@ public static async Task<bool> TEST_DisabledCommandsError()
Logger.logger.Log(advertise.ToString());

Logger.logger.Log($"Send ResumeRuntime Diagnostics IPC Command");
// send ResumeRuntime command (0xFF=ServerCommandSet, 0x01=ResumeRuntime commandid)
message = new IpcMessage(0xFF,0x01);
// send ResumeRuntime command (0x04=ProcessCommandSet, 0x01=ResumeRuntime commandid)
message = new IpcMessage(0x04,0x01);
Logger.logger.Log($"Sent: {message.ToString()}");
response = IpcClient.SendMessage(stream, message);
Logger.logger.Log($"received: {response.ToString()}");
Expand Down