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
Merged
2 changes: 2 additions & 0 deletions src/coreclr/src/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ set(VM_SOURCES_WKS
objectlist.cpp
olevariant.cpp
pendingload.cpp
processdiagnosticsprotocolhelper.cpp
profdetach.cpp
profilermetadataemitvalidator.cpp
profilingenumerators.cpp
Expand Down Expand Up @@ -499,6 +500,7 @@ set(VM_HEADERS_WKS
objectlist.h
olevariant.h
pendingload.h
processdiagnosticsprotocolhelper.h
profdetach.h
profilermetadataemitvalidator.h
profilingenumerators.h
Expand Down
54 changes: 5 additions & 49 deletions src/coreclr/src/vm/diagnosticserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "eventpipeprotocolhelper.h"
#include "dumpdiagnosticprotocolhelper.h"
#include "profilerdiagnosticprotocolhelper.h"
#include "processdiagnosticsprotocolhelper.h"
#include "diagnosticsprotocol.h"

#ifdef TARGET_UNIX
Expand Down Expand Up @@ -75,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 All @@ -87,6 +84,10 @@ DWORD WINAPI DiagnosticServer::DiagnosticsServerThread(LPVOID)
DumpDiagnosticProtocolHelper::HandleIpcMessage(message, pStream);
break;

case DiagnosticsIpc::DiagnosticServerCommandSet::Process:
ProcessDiagnosticsProtocolHelper::HandleIpcMessage(message,pStream);
break;

#ifdef FEATURE_PROFAPI_ATTACH_DETACH
case DiagnosticsIpc::DiagnosticServerCommandSet::Profiler:
ProfilerDiagnosticProtocolHelper::HandleIpcMessage(message, pStream);
Expand Down Expand Up @@ -291,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__
25 changes: 9 additions & 16 deletions src/coreclr/src/vm/diagnosticsprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,15 @@ namespace DiagnosticsIpc
Dump = 0x01,
EventPipe = 0x02,
Profiler = 0x03,
Process = 0x04,
josalem marked this conversation as resolved.
Show resolved Hide resolved

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,
// future
Error = 0xFF,
};

Expand Down Expand Up @@ -206,12 +197,12 @@ namespace DiagnosticsIpc
//
// For more details on this pattern, look up "Substitution Failure Is Not An Error" or SFINAE

// template meta-programming to check for bool(Flatten)(void*) member function
// template meta-programming to check for bool(Flatten)(BYTE*&, uint16_t&) member function
template <typename T>
struct HasFlatten
{
template <typename U, U u> struct Has;
template <typename U> static std::true_type test(Has<bool (U::*)(void*), &U::Flatten>*);
template <typename U> static std::true_type test(Has<bool (U::*)(BYTE*&, uint16_t&), &U::Flatten>*);
template <typename U> static std::false_type test(...);
static constexpr bool value = decltype(test<T>(nullptr))::value;
};
Expand Down Expand Up @@ -464,7 +455,7 @@ namespace DiagnosticsIpc
// Handles the case where the payload structure exposes Flatten
// and GetSize methods
template <typename U,
typename std::enable_if<HasFlatten<U>::value&& HasGetSize<U>::value, int>::type = 0>
typename std::enable_if<HasFlatten<U>::value && HasGetSize<U>::value, int>::type = 0>
bool FlattenImpl(U& payload)
{
CONTRACTL
Expand All @@ -483,6 +474,7 @@ namespace DiagnosticsIpc
ASSERT(!temp_size.IsOverflow());

m_Size = temp_size.Value();
uint16_t remainingBytes = temp_size.Value();

BYTE* temp_buffer = new (nothrow) BYTE[m_Size];
if (temp_buffer == nullptr)
Expand All @@ -497,13 +489,14 @@ namespace DiagnosticsIpc

memcpy(temp_buffer_cursor, &m_Header, sizeof(struct IpcHeader));
temp_buffer_cursor += sizeof(struct IpcHeader);
remainingBytes -= sizeof(struct IpcHeader);

payload.Flatten(temp_buffer_cursor);
const bool fSuccess = payload.Flatten(temp_buffer_cursor, remainingBytes);

ASSERT(m_pData == nullptr);
m_pData = temp_buffer;

return true;
return fSuccess;
};

// handles the case where we were handed a struct with no Flatten or GetSize method
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/src/vm/eventpipeeventsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class EventPipeEventSource
const static WCHAR* s_pProcessInfoEventName;
EventPipeEvent *m_pProcessInfoEvent;

const static WCHAR* s_pOSInformation;
const static WCHAR* s_pArchInformation;

public:
EventPipeEventSource();
~EventPipeEventSource();

void Enable(EventPipeSession *pSession);
void SendProcessInfo(LPCWSTR pCommandLine);

const static WCHAR* s_pOSInformation;
const static WCHAR* s_pArchInformation;
};

#endif // FEATURE_PERFTRACING
Expand Down
Loading