Files
o3de/Code/Tools/Standalone/Source/Driller/DrillerDataContainer.cpp
T
Esteban Papp 1f9b284de2 Merge branch 'development' into cmake/SPEC-7179
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>

# Conflicts:
#	Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h
#	Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h
#	Code/Editor/Plugins/EditorCommon/stdafx.cpp
#	Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h
#	Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h
#	Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h
#	Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h
#	Code/Tools/AssetProcessor/native/precompiled.h
#	Code/Tools/Standalone/StandaloneTools_precompiled.h
#	Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h
#	Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h
#	Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h
#	Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h
#	Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h
#	Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h
#	Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake
#	Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h
#	Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h
#	Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp
#	Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake
#	Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h
#	Gems/Blast/Code/Source/StdAfx.cpp
#	Gems/Camera/Code/Source/Camera_precompiled.h
#	Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h
#	Gems/FastNoise/Code/Source/FastNoise_precompiled.h
#	Gems/Gestures/Code/Source/Gestures_precompiled.h
#	Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h
#	Gems/GraphCanvas/Code/precompiled.h
#	Gems/ImGui/Code/Source/ImGui_precompiled.h
#	Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h
#	Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h
#	Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp
#	Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h
#	Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h
#	Gems/LyShine/Code/Source/LyShine_precompiled.h
#	Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h
#	Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h
#	Gems/Maestro/Code/Source/Maestro_precompiled.h
#	Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h
#	Gems/Metastream/Code/Source/Metastream_precompiled.h
#	Gems/Microphone/Code/Source/Microphone_precompiled.h
#	Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h
#	Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h
#	Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h
#	Gems/PhysX/Code/Source/PhysX_precompiled.h
#	Gems/PhysX/Code/physx_unsupported_files.cmake
#	Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h
#	Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h
#	Gems/ScriptCanvas/Code/Editor/precompiled.h
#	Gems/ScriptCanvas/Code/Source/precompiled.h
#	Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h
#	Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h
#	Gems/ScriptEvents/Code/Source/precompiled.h
#	Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp
#	Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h
#	Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h
#	Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h
#	Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h
#	Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h
#	Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h
#	Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h
#	Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h
#	Gems/Twitch/Code/Source/Twitch_precompiled.h
#	Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h
#	Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h
#	Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
2021-07-16 15:42:37 -07:00

284 lines
11 KiB
C++

/*
* 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 "DrillerDataContainer.h"
#include <AzCore/Driller/Stream.h>
#include <AzCore/Driller/DrillerRootHandler.h>
#include <AzCore/Driller/DefaultStringPool.h>
#include <AzCore/IO/SystemFile.h> // temp for DebugHackProcessFile
#include <AzCore/XML/rapidxml_print.h> // metadata is stored this way
#include "Unsupported/UnsupportedDataAggregator.hxx"
#include "Memory/MemoryDataAggregator.hxx"
#include "Trace/TraceMessageDataAggregator.hxx"
#include "Profiler/ProfilerDataAggregator.hxx"
#include "Carrier/CarrierDataAggregator.hxx"
#include "Replica/ReplicaDataAggregator.hxx"
#include "Rendering/VRAM/VRAMDataAggregator.hxx"
#include "EventTrace/EventTraceDataAggregator.h"
// IMPORTANT: include new aggregators above
namespace Driller
{
class DrillerDataHandler : public AZ::Debug::DrillerHandlerParser
{
public:
AZ_CLASS_ALLOCATOR(DrillerDataHandler,AZ::SystemAllocator,0)
DrillerDataHandler(int identity, DrillerDataContainer* container)
: AZ::Debug::DrillerHandlerParser(/*true*/false)
, m_identity(identity)
, m_currentFrame(-1)
, m_dataContainer(container)
, m_dataParser(nullptr)
{
m_drillerSessionInfo.m_platform = static_cast<int>(AZ::g_currentPlatform); /// Init with current platform so no endian swapping till we read all the initial settings.
m_inputStream.SetStringPool(&m_stringPool);
m_dataParser = aznew AZ::Debug::DrillerSAXParserHandler(this);
}
~DrillerDataHandler()
{
delete m_dataParser;
}
virtual AZ::Debug::DrillerHandlerParser* OnEnterTag(AZ::u32 tagName)
{
if( tagName == AZ_CRC("StartData", 0xecf3f53f) )
return &m_drillerSessionInfo;
if( tagName == AZ_CRC("Frame", 0xb5f83ccd) )
return this;
for(DrillerNetworkMessages::AggregatorList::iterator it = m_dataContainer->m_aggregators.begin(); it != m_dataContainer->m_aggregators.end(); ++it)
{
if( (*it)->GetDrillerId() == tagName )
return (*it)->GetDrillerDataParser();
}
AZ_TracePrintf("Driller", "We should never get here as we should have added 'Unsupported driller(s)' in OnExitTag('StartData')");
return nullptr;
}
virtual void OnExitTag(DrillerHandlerParser* handler, AZ::u32 tagName)
{
(void)handler;
if( tagName == AZ_CRC("StartData", 0xecf3f53f) )
{
// create all drillers that were in the session data
for(AZ::Debug::DrillerManager::DrillerListType::iterator itDriller = m_drillerSessionInfo.m_drillers.begin(); itDriller != m_drillerSessionInfo.m_drillers.end(); ++itDriller )
{
AZ::u32 drillerId = itDriller->id;
bool isCreated = false;
for(DrillerNetworkMessages::AggregatorList::iterator it = m_dataContainer->m_aggregators.begin(); it != m_dataContainer->m_aggregators.end(); ++it)
{
if( (*it)->GetDrillerId() == drillerId )
{
isCreated = true;
break;
}
}
if( !isCreated )
{
// Create the aggregator, if the driller is missing add UnsupportedAggregator
Aggregator* aggr = m_dataContainer->CreateAggregator(drillerId, true);
if( aggr )
m_dataContainer->m_aggregators.push_back(aggr);
// two ways to add aggregators:
// 1) "NewAggregatorList" send an entire list which replaces the current setup, which is most efficient
// 2) "AddAggregator" send a single aggregator which gets appended
EBUS_EVENT_ID(m_identity, DrillerNetworkMessages::Bus,AddAggregator, *m_dataContainer->m_aggregators.back());
}
}
}
}
virtual void OnData(const AZ::Debug::DrillerSAXParser::Data& dataNode)
{
if( dataNode.m_name == AZ_CRC("FrameNum", 0x85a1a919) )
{
// Send event that previous frame has finished
if( m_currentFrame != -1 )
{
EBUS_EVENT_ID(m_identity, DrillerNetworkMessages::Bus,EndFrame, m_currentFrame);
}
dataNode.Read(m_currentFrame);
for(DrillerNetworkMessages::AggregatorList::iterator it = m_dataContainer->m_aggregators.begin(); it != m_dataContainer->m_aggregators.end(); ++it)
{
(*it)->AddNewFrame();
}
}
}
void ProcessStream(const char* streamIdentifier, const void* data, unsigned int dataSize)
{
m_inputStream.SetData(streamIdentifier, data, dataSize);
m_dataParser->ProcessStream(m_inputStream);
}
AZ::Debug::DrillerStartdataHandler m_drillerSessionInfo;
int m_currentFrame;
DrillerDataContainer* m_dataContainer;
AZ::Debug::DrillerSAXParserHandler* m_dataParser;
AZ::Debug::DrillerInputMemoryStream m_inputStream;
AZ::Debug::DrillerDefaultStringPool m_stringPool;
int m_identity;
};
DrillerDataContainer::DrillerDataContainer(int identity, const char* tmpCaptureFilename)
: m_dataHandler(nullptr)
, m_identity(identity)
, m_tmpCaptureFilename(tmpCaptureFilename)
{
AzFramework::DrillerNetworkConsoleEventBus::Handler::BusConnect();
EBUS_EVENT(AzFramework::DrillerNetworkConsoleCommandBus, EnumerateAvailableDrillers);
}
DrillerDataContainer::~DrillerDataContainer()
{
AzFramework::DrillerNetworkConsoleEventBus::Handler::BusDisconnect();
DestroyAggregators();
delete m_dataHandler;
}
void DrillerDataContainer::OnReceivedDrillerEnumeration(const AzFramework::DrillerInfoListType& availableDrillers)
{
// TODO: Decide how the available driller list should influence the behavior of the driller
// display. For now we will display whatever is available.
m_availableDrillers = availableDrillers;
EBUS_EVENT_ID(m_identity, DrillerNetworkMessages::Bus, NewAggregatorsAvailable);
}
void DrillerDataContainer::CreateAggregators()
{
DestroyAggregators();
if (m_availableDrillers.size())
{
for (size_t i = 0; i < m_availableDrillers.size(); ++i)
{
Aggregator* aggr = CreateAggregator(m_availableDrillers[i].m_id, true);
if( aggr )
m_aggregators.push_back(aggr);
}
}
EBUS_EVENT_ID(m_identity, DrillerNetworkMessages::Bus, NewAggregatorList,m_aggregators);
}
void DrillerDataContainer::DestroyAggregators()
{
EBUS_EVENT_ID(m_identity, DrillerNetworkMessages::Bus, DiscardAggregators);
for(DrillerNetworkMessages::AggregatorList::iterator it = m_aggregators.begin(); it != m_aggregators.end(); ++it )
delete *it;
m_aggregators.clear();
}
Aggregator* DrillerDataContainer::CreateAggregator(AZ::u32 id, bool createUnsupported)
{
if( id == MemoryDataAggregator::DrillerId() )
{
return aznew MemoryDataAggregator(m_identity);
}
else if( id == TraceMessageDataAggregator::DrillerId() )
{
return aznew TraceMessageDataAggregator(m_identity);
}
else if (id == ProfilerDataAggregator::DrillerId() )
{
return aznew ProfilerDataAggregator(m_identity);
}
else if(id == CarrierDataAggregator::DrillerId())
{
return aznew CarrierDataAggregator(m_identity);
}
else if(id == ReplicaDataAggregator::DrillerId())
{
return aznew ReplicaDataAggregator(m_identity);
}
else if(id == VRAM::VRAMDataAggregator::DrillerId())
{
return aznew VRAM::VRAMDataAggregator(m_identity);
}
else if (id == EventTraceDataAggregator::DrillerId())
{
return aznew EventTraceDataAggregator(m_identity);
}
// IMPORTANT: Add new aggregators here
return createUnsupported ? aznew UnsupportedDataAggregator(id) : nullptr;
}
void DrillerDataContainer::ProcessIncomingDrillerData(const char* streamIdentifier, const void* data, size_t dataSize)
{
AZ_Assert(m_dataHandler,"You must have a valid data handler parser to parse the data!");
m_dataHandler->ProcessStream(streamIdentifier, data, static_cast<unsigned int>(dataSize));
}
void DrillerDataContainer::OnDrillerConnectionLost()
{
StopDrilling();
}
void DrillerDataContainer::StartDrilling()
{
DrillerEvent::ResetGlobalEventId();
AzFramework::DrillerListType drillersToStart;
for(DrillerNetworkMessages::AggregatorList::iterator it = m_aggregators.begin(); it != m_aggregators.end(); ++it)
{
(*it)->Reset();
if ((*it)->IsCaptureEnabled())
{
drillersToStart.push_back((*it)->GetDrillerId());
}
}
if (drillersToStart.size())
{
delete m_dataHandler;
m_dataHandler = aznew DrillerDataHandler(m_identity, this);
AzFramework::DrillerRemoteSession::StartDrilling(drillersToStart, m_tmpCaptureFilename.c_str());
}
}
void DrillerDataContainer::LoadCaptureData(const char* fileName)
{
DrillerEvent::ResetGlobalEventId();
// Reset data
DestroyAggregators();
AZStd::string baseFilename( fileName );
delete m_dataHandler;
m_dataHandler = aznew DrillerDataHandler(m_identity, this);
AzFramework::DrillerRemoteSession::LoadCaptureData(fileName);
}
void DrillerDataContainer::CloseCaptureData()
{
StopDrilling();
DestroyAggregators();
}
void DrillerDataContainer::Reflect(AZ::ReflectContext* context)
{
MemoryDataAggregator::Reflect(context);
TraceMessageDataAggregator::Reflect(context);
ProfilerDataAggregator::Reflect(context);
ReplicaDataAggregator::Reflect(context);
}
}//namespace Driller