Moving CommunicatorTracePrinter to a place that AP and Multiplayer gem can use it. MultiplayerEditorSystemComponent now watching the server process and pumping the trace printer. Wip; for some reason not all the server logs are reaching the editor

Signed-off-by: Gene Walters <genewalt@amazon.com>
monroegm-disable-blank-issue-2
Gene Walters 4 years ago
parent 384d631485
commit 5d5087e0d3

@ -6,16 +6,16 @@
*
*/
#include "CommunicatorTracePrinter.h"
#include "ProcessCommunicatorTracePrinter.h"
CommunicatorTracePrinter::CommunicatorTracePrinter(AzFramework::ProcessCommunicator* communicator, const char* window) :
ProcessCommunicatorTracePrinter::ProcessCommunicatorTracePrinter(AzFramework::ProcessCommunicator* communicator, const char* window) :
m_communicator(communicator),
m_window(window)
{
m_stringBeingConcatenated.reserve(1024);
}
CommunicatorTracePrinter::~CommunicatorTracePrinter()
ProcessCommunicatorTracePrinter::~ProcessCommunicatorTracePrinter()
{
// flush stdout
WriteCurrentString(false);
@ -24,7 +24,7 @@ CommunicatorTracePrinter::~CommunicatorTracePrinter()
WriteCurrentString(true);
}
void CommunicatorTracePrinter::Pump()
void ProcessCommunicatorTracePrinter::Pump()
{
if (m_communicator->IsValid())
{
@ -42,7 +42,7 @@ void CommunicatorTracePrinter::Pump()
}
}
void CommunicatorTracePrinter::ParseDataBuffer(AZ::u32 readSize, bool isFromStdErr)
void ProcessCommunicatorTracePrinter::ParseDataBuffer(AZ::u32 readSize, bool isFromStdErr)
{
if (readSize > AZ_ARRAY_SIZE(m_streamBuffer))
{
@ -67,7 +67,7 @@ void CommunicatorTracePrinter::ParseDataBuffer(AZ::u32 readSize, bool isFromStdE
}
}
void CommunicatorTracePrinter::WriteCurrentString(bool isFromStdErr)
void ProcessCommunicatorTracePrinter::WriteCurrentString(bool isFromStdErr)
{
AZStd::string& bufferToUse = isFromStdErr ? m_errorStringBeingConcatenated : m_stringBeingConcatenated;

@ -10,20 +10,21 @@
#include <AzFramework/Process/ProcessCommunicator.h>
//! CommunicatorTracePrinter listens to stderr and stdout of a running process and writes its output to the AZ_Trace system
//! ProcessCommunicatorTracePrinter listens to stderr and stdout of a running process and writes its output to the AZ_Trace system
//! Importantly, it does not do any blocking operations.
class CommunicatorTracePrinter
class ProcessCommunicatorTracePrinter
{
public:
CommunicatorTracePrinter(AzFramework::ProcessCommunicator* communicator, const char* window);
~CommunicatorTracePrinter();
ProcessCommunicatorTracePrinter(AzFramework::ProcessCommunicator* communicator, const char* window);
~ProcessCommunicatorTracePrinter();
// call this periodically to drain the buffers and write them.
// Call this periodically to drain the buffers and write them.
void Pump();
// drains the buffer into the string thats being built, then traces the string when it hits a newline.
// Drains the buffer into the string that's being built, then traces the string when it hits a newline.
void ParseDataBuffer(AZ::u32 readSize, bool isFromStdErr);
// Prints the current buffer to AZ_Error or AZ_TracePrintf so that it can be picked up by AZ::Debug::Trace
void WriteCurrentString(bool isFromStdError);
private:

@ -274,6 +274,8 @@ set(FILES
Process/ProcessWatcher.cpp
Process/ProcessWatcher.h
Process/ProcessCommon_fwd.h
Process/ProcessCommunicatorTracePrinter.cpp
Process/ProcessCommunicatorTracePrinter.h
ProjectManager/ProjectManager.h
ProjectManager/ProjectManager.cpp
Render/GameIntersectorComponent.h

@ -89,8 +89,6 @@ set(FILES
native/utilities/BuilderManager.inl
native/utilities/ByteArrayStream.cpp
native/utilities/ByteArrayStream.h
native/utilities/CommunicatorTracePrinter.cpp
native/utilities/CommunicatorTracePrinter.h
native/utilities/IniConfiguration.cpp
native/utilities/IniConfiguration.h
native/utilities/JobDiagnosticTracker.cpp

@ -20,7 +20,6 @@
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzFramework/Application/Application.h>
#include <AzFramework/Process/ProcessCommunicator.h>
#include <AzFramework/Process/ProcessWatcher.h>
#include <AzToolsFramework/Application/ToolsApplication.h>
@ -31,7 +30,6 @@
#include "native/utilities/assetUtils.h"
#include "native/utilities/AssetBuilderInfo.h"
#include "native/utilities/CommunicatorTracePrinter.h"
#include <AssetProcessor_Traits_Platform.h>

@ -1479,7 +1479,7 @@ bool ApplicationManagerBase::WaitForBuilderExit(AzFramework::ProcessWatcher* pro
AZ::u32 exitCode = 0;
bool finishedOK = false;
QElapsedTimer ticker;
CommunicatorTracePrinter tracer(processWatcher->GetCommunicator(), "AssetBuilder");
ProcessCommunicatorTracePrinter tracer(processWatcher->GetCommunicator(), "AssetBuilder");
ticker.start();

@ -164,7 +164,7 @@ namespace AssetProcessor
return false;
}
m_tracePrinter = AZStd::make_unique<CommunicatorTracePrinter>(m_processWatcher->GetCommunicator(), "AssetBuilder");
m_tracePrinter = AZStd::make_unique<ProcessCommunicatorTracePrinter>(m_processWatcher->GetCommunicator(), "AssetBuilder");
return WaitForConnection();
}

@ -10,11 +10,11 @@
#include <AzCore/std/string/string.h>
#include <AzCore/std/parallel/binary_semaphore.h>
#include <AzFramework/Process/ProcessWatcher.h>
#include <AzFramework/Process/ProcessCommunicatorTracePrinter.h>
#include <AssetBuilderSDK/AssetBuilderSDK.h>
#include <AzCore/std/smart_ptr/shared_ptr.h>
#include <QString>
#include <QByteArray>
#include <native/utilities/CommunicatorTracePrinter.h>
#include <native/utilities/assetUtils.h>
#include <QDir> // used in the inl file.
@ -127,7 +127,7 @@ namespace AssetProcessor
AZStd::unique_ptr<AzFramework::ProcessWatcher> m_processWatcher = nullptr;
//! Optional communicator, only available if we have a process watcher
AZStd::unique_ptr<CommunicatorTracePrinter> m_tracePrinter = nullptr;
AZStd::unique_ptr<ProcessCommunicatorTracePrinter> m_tracePrinter = nullptr;
const AssetUtilities::QuitListener& m_quitListener;
};

@ -6,6 +6,8 @@
*
*/
#include "AzFramework/Process/ProcessCommunicator.h"
#include <Multiplayer/IMultiplayer.h>
#include <Multiplayer/IMultiplayerTools.h>
#include <Multiplayer/INetworkSpawnableLibrary.h>
@ -133,6 +135,7 @@ namespace Multiplayer
AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
AzFramework::GameEntityContextEventBus::Handler::BusDisconnect();
MultiplayerEditorServerRequestBus::Handler::BusDisconnect();
AZ::TickBus::Handler::BusDisconnect();
}
void MultiplayerEditorSystemComponent::NotifyRegisterViews()
@ -157,12 +160,21 @@ namespace Multiplayer
[[fallthrough]];
case eNotify_OnEndGameMode:
// Kill the configured server if it's active
if (m_serverProcess)
if (m_serverProcessWatcher)
{
m_serverProcess->TerminateProcess(0);
m_serverProcess = nullptr;
m_serverProcessWatcher->TerminateProcess(0);
if (m_serverProcessTracePrinter)
{
m_serverProcessTracePrinter->Pump();
m_serverProcessTracePrinter->WriteCurrentString(true);
m_serverProcessTracePrinter->WriteCurrentString(false);
}
m_serverProcessWatcher = nullptr;
m_serverProcessTracePrinter = nullptr;
}
AZ::TickBus::Handler::BusDisconnect();
if (INetworkInterface* editorNetworkInterface = AZ::Interface<INetworking>::Get()->RetrieveNetworkInterface(AZ::Name(MpEditorInterfaceName)))
{
editorNetworkInterface->Disconnect(m_editorConnId, AzNetworking::DisconnectReason::TerminatedByClient);
@ -220,7 +232,7 @@ namespace Multiplayer
// Launch the Server
AzFramework::ProcessWatcher* outProcess = AzFramework::ProcessWatcher::LaunchProcess(
processLaunchInfo, AzFramework::ProcessCommunicationType::COMMUNICATOR_TYPE_NONE);
processLaunchInfo, AzFramework::ProcessCommunicationType::COMMUNICATOR_TYPE_STDINOUT);
AZ_Error(
"MultiplayerEditor", processLaunchInfo.m_launchResult != AzFramework::ProcessLauncher::ProcessLaunchResult::PLR_MissingFile,
@ -389,4 +401,10 @@ namespace Multiplayer
{
return PyIsInGameMode();
}
void MultiplayerEditorSystemComponent::OnTick(float, AZ::ScriptTimePoint)
{
m_serverProcessTracePrinter->Pump();
}
}

@ -13,14 +13,12 @@
#include <Multiplayer/Editor/MultiplayerPythonEditorEventsBus.h>
#include <IEditor.h>
#include <Editor/MultiplayerEditorConnection.h>
#include <AzCore/Component/Component.h>
#include <AzCore/Component/TickBus.h>
#include <AzCore/Console/IConsole.h>
#include <AzCore/Console/ILogger.h>
#include <AzFramework/Entity/GameEntityContextBus.h>
#include <AzFramework/Process/ProcessWatcher.h>
#include <AzFramework/Process/ProcessCommunicatorTracePrinter.h>
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
namespace AzNetworking
@ -52,6 +50,7 @@ namespace Multiplayer
, private AzToolsFramework::EditorEvents::Bus::Handler
, private IEditorNotifyListener
, private MultiplayerEditorServerRequestBus::Handler
, private AZ::TickBus::Handler
{
public:
AZ_COMPONENT(MultiplayerEditorSystemComponent, "{9F335CC0-5574-4AD3-A2D8-2FAEF356946C}");
@ -101,8 +100,14 @@ namespace Multiplayer
void SendEditorServerLevelDataPacket(AzNetworking::IConnection* connection) override;
//! @}
//! AZ::TickBus::Handler
//! @{
void OnTick(float, AZ::ScriptTimePoint) override;
//! @}
IEditor* m_editor = nullptr;
AzFramework::ProcessWatcher* m_serverProcess = nullptr;
AzFramework::ProcessWatcher* m_serverProcessWatcher = nullptr;
AZStd::unique_ptr<ProcessCommunicatorTracePrinter> m_serverProcessTracePrinter = nullptr;
AzNetworking::ConnectionId m_editorConnId;
ServerAcceptanceReceivedEvent::Handler m_serverAcceptanceReceivedHandler;

@ -1134,6 +1134,7 @@ namespace Multiplayer
AZStd::to_lower(sv_defaultPlayerSpawnAssetLowerCase.begin(), sv_defaultPlayerSpawnAssetLowerCase.end());
PrefabEntityId playerPrefabEntityId(AZ::Name(static_cast<AZ::CVarFixedString>(sv_defaultPlayerSpawnAssetLowerCase).c_str()));
INetworkEntityManager::EntityList entityList = m_networkEntityManager.CreateEntitiesImmediate(playerPrefabEntityId, NetEntityRole::Authority, AZ::Transform::CreateIdentity(), Multiplayer::AutoActivate::DoNotActivate);
AZ_TracePrintf("MultiplayerSystemComponent", "Server spawned the default player: %s", sv_defaultPlayerSpawnAssetLowerCase.c_str())
for (NetworkEntityHandle subEntity : entityList)
{

Loading…
Cancel
Save