Merge pull request #5820 from aws-lumberyard-dev/LYN-8025_PipeEditorServerLogsToEditor

Pipe Editor-Server Logs Back to the Editor
This commit is contained in:
Gene Walters
2021-12-01 07:36:02 -08:00
committed by GitHub
16 changed files with 129 additions and 46 deletions
@@ -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>
@@ -1482,7 +1482,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;
};
@@ -1,86 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "CommunicatorTracePrinter.h"
CommunicatorTracePrinter::CommunicatorTracePrinter(AzFramework::ProcessCommunicator* communicator, const char* window) :
m_communicator(communicator),
m_window(window)
{
m_stringBeingConcatenated.reserve(1024);
}
CommunicatorTracePrinter::~CommunicatorTracePrinter()
{
// flush stdout
WriteCurrentString(false);
// flush stderr
WriteCurrentString(true);
}
void CommunicatorTracePrinter::Pump()
{
if (m_communicator->IsValid())
{
// Don't call readOutput unless there is output or else it will block...
while (m_communicator->PeekOutput())
{
AZ::u32 readSize = m_communicator->ReadOutput(m_streamBuffer, AZ_ARRAY_SIZE(m_streamBuffer));
ParseDataBuffer(readSize, false);
}
while (m_communicator->PeekError())
{
AZ::u32 readSize = m_communicator->ReadError(m_streamBuffer, AZ_ARRAY_SIZE(m_streamBuffer));
ParseDataBuffer(readSize, true);
}
}
}
void CommunicatorTracePrinter::ParseDataBuffer(AZ::u32 readSize, bool isFromStdErr)
{
if (readSize > AZ_ARRAY_SIZE(m_streamBuffer))
{
AZ_ErrorOnce("ERROR", false, "Programmer bug: Read size is overflowing in traceprintf communicator.");
return;
}
// we cannot write the string to the same buffer, as stdError and stdOut are different streams and could
// have different cutting points as buffers empty.
AZStd::string& bufferToUse = isFromStdErr ? m_errorStringBeingConcatenated : m_stringBeingConcatenated;
for (size_t pos = 0; pos < readSize; ++pos)
{
if ((m_streamBuffer[pos] == '\n') || (m_streamBuffer[pos] == '\r'))
{
WriteCurrentString(isFromStdErr);
}
else
{
bufferToUse.push_back(m_streamBuffer[pos]);
}
}
}
void CommunicatorTracePrinter::WriteCurrentString(bool isFromStdErr)
{
AZStd::string& bufferToUse = isFromStdErr ? m_errorStringBeingConcatenated : m_stringBeingConcatenated;
if (!bufferToUse.empty())
{
if (isFromStdErr)
{
AZ_Error(m_window.c_str(), false, "%s", bufferToUse.c_str());
}
else
{
AZ_TracePrintf(m_window.c_str(), "%s", bufferToUse.c_str());
}
bufferToUse.clear();
}
}
@@ -1,35 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzFramework/Process/ProcessCommunicator.h>
//! CommunicatorTracePrinter 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
{
public:
CommunicatorTracePrinter(AzFramework::ProcessCommunicator* communicator, const char* window);
~CommunicatorTracePrinter();
// 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.
void ParseDataBuffer(AZ::u32 readSize, bool isFromStdErr);
void WriteCurrentString(bool isFromStdError);
private:
AZStd::string m_window;
AzFramework::ProcessCommunicator* m_communicator;
char m_streamBuffer[128];
AZStd::string m_stringBeingConcatenated;
AZStd::string m_errorStringBeingConcatenated;
};