From 498673ada0fbb5e9adcbd1d0c41a06891ce406b1 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Thu, 2 Dec 2021 17:15:46 -0800 Subject: [PATCH] Removes Driller from AzCore Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../AzCore/Component/ComponentApplication.cpp | 2 - .../AzCore/Component/ComponentApplication.h | 1 - .../Component/ComponentApplicationBus.h | 5 - .../AzCore/AzCore/Debug/EventTrace.cpp | 29 - .../AzCore/AzCore/Debug/EventTrace.h | 43 - .../AzCore/AzCore/Debug/EventTraceDriller.cpp | 159 ---- .../AzCore/AzCore/Debug/EventTraceDriller.h | 87 -- .../AzCore/Debug/EventTraceDrillerBus.h | 81 -- .../AzCore/AzCore/Driller/DefaultStringPool.h | 125 --- .../AzCore/AzCore/Driller/Driller.cpp | 301 ------ .../Framework/AzCore/AzCore/Driller/Driller.h | 141 --- .../AzCore/AzCore/Driller/DrillerBus.cpp | 65 -- .../AzCore/AzCore/Driller/DrillerBus.h | 52 - .../AzCore/Driller/DrillerRootHandler.h | 170 ---- .../AzCore/AzCore/Driller/Stream.cpp | 893 ------------------ Code/Framework/AzCore/AzCore/Driller/Stream.h | 848 ----------------- .../AzCore/Memory/AllocationRecords.cpp | 5 +- .../AzCore/AzCore/Memory/OSAllocator.h | 2 +- .../AzCore/AzCore/UnitTest/TestTypes.h | 10 +- .../AzCore/AzCore/azcore_files.cmake | 13 - .../Framework/AzCore/Tests/AZStd/Parallel.cpp | 2 +- .../AzCore/Tests/AZStd/TypeTraits.cpp | 1 + Code/Framework/AzCore/Tests/EBus.cpp | 12 +- Code/Framework/AzCore/Tests/Memory.cpp | 5 - .../AzCore/Tests/Memory/LeakDetection.cpp | 3 - Code/Framework/AzCore/Tests/Rtti.cpp | 1 + .../Json/BasicContainerSerializerTests.cpp | 1 + 27 files changed, 15 insertions(+), 3042 deletions(-) delete mode 100644 Code/Framework/AzCore/AzCore/Debug/EventTrace.cpp delete mode 100644 Code/Framework/AzCore/AzCore/Debug/EventTrace.h delete mode 100644 Code/Framework/AzCore/AzCore/Debug/EventTraceDriller.cpp delete mode 100644 Code/Framework/AzCore/AzCore/Debug/EventTraceDriller.h delete mode 100644 Code/Framework/AzCore/AzCore/Debug/EventTraceDrillerBus.h delete mode 100644 Code/Framework/AzCore/AzCore/Driller/DefaultStringPool.h delete mode 100644 Code/Framework/AzCore/AzCore/Driller/Driller.cpp delete mode 100644 Code/Framework/AzCore/AzCore/Driller/Driller.h delete mode 100644 Code/Framework/AzCore/AzCore/Driller/DrillerBus.cpp delete mode 100644 Code/Framework/AzCore/AzCore/Driller/DrillerBus.h delete mode 100644 Code/Framework/AzCore/AzCore/Driller/DrillerRootHandler.h delete mode 100644 Code/Framework/AzCore/AzCore/Driller/Stream.cpp delete mode 100644 Code/Framework/AzCore/AzCore/Driller/Stream.h diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp index 99ff8e6e6b..c9841932f0 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp @@ -48,8 +48,6 @@ #include #include -#include -#include #include #include diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h index 56216a7a24..d53b8e1a4e 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h @@ -41,7 +41,6 @@ namespace AZ } namespace AZ::Debug { - class DrillerManager; class LocalFileEventLogger; } diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h b/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h index feefa95973..10f35d6e00 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h @@ -37,11 +37,6 @@ namespace AZ class ComponentFactoryInterface; } - namespace Debug - { - class DrillerManager; - } - struct ApplicationTypeQuery { bool IsEditor() const; diff --git a/Code/Framework/AzCore/AzCore/Debug/EventTrace.cpp b/Code/Framework/AzCore/AzCore/Debug/EventTrace.cpp deleted file mode 100644 index 58fa1f6cca..0000000000 --- a/Code/Framework/AzCore/AzCore/Debug/EventTrace.cpp +++ /dev/null @@ -1,29 +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 -#include -#include -#include - -namespace AZ::Debug -{ - EventTrace::ScopedSlice::ScopedSlice(const char* name, const char* category) - : m_Name(name) - , m_Category(category) - , m_Time(AZStd::GetTimeNowMicroSecond()) - { - } - - EventTrace::ScopedSlice::~ScopedSlice() - { - EventTraceDrillerBus::TryQueueBroadcast( - &EventTraceDrillerInterface::RecordSlice, m_Name, m_Category, AZStd::this_thread::get_id(), m_Time, - (uint32_t)(AZStd::GetTimeNowMicroSecond() - m_Time)); - } -} // namespace AZ::Debug diff --git a/Code/Framework/AzCore/AzCore/Debug/EventTrace.h b/Code/Framework/AzCore/AzCore/Debug/EventTrace.h deleted file mode 100644 index 1bc7ee20a6..0000000000 --- a/Code/Framework/AzCore/AzCore/Debug/EventTrace.h +++ /dev/null @@ -1,43 +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 -#include -#include - -namespace AZStd -{ - struct thread_id; -} - -namespace AZ -{ - namespace Debug - { - namespace EventTrace - { - class ScopedSlice - { - public: - ScopedSlice(const char* name, const char* category); - ~ScopedSlice(); - - private: - const char* m_Name; - const char* m_Category; - u64 m_Time; - }; - } - } -} - -#define AZ_TRACE_METHOD_NAME_CATEGORY(name, category) -#define AZ_TRACE_METHOD_NAME(name) AZ_TRACE_METHOD_NAME_CATEGORY(name, "") -#define AZ_TRACE_METHOD() AZ_TRACE_METHOD_NAME(AZ_FUNCTION_SIGNATURE) diff --git a/Code/Framework/AzCore/AzCore/Debug/EventTraceDriller.cpp b/Code/Framework/AzCore/AzCore/Debug/EventTraceDriller.cpp deleted file mode 100644 index cdaf7ec56f..0000000000 --- a/Code/Framework/AzCore/AzCore/Debug/EventTraceDriller.cpp +++ /dev/null @@ -1,159 +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 -#include -#include -#include - -namespace AZ::Debug -{ - namespace Crc - { - constexpr u32 EventTraceDriller = AZ_CRC_CE("EventTraceDriller"); - constexpr u32 Slice = AZ_CRC_CE("Slice"); - constexpr u32 ThreadInfo = AZ_CRC_CE("ThreadInfo"); - constexpr u32 Name = AZ_CRC_CE("Name"); - constexpr u32 Category = AZ_CRC_CE("Category"); - constexpr u32 ThreadId = AZ_CRC_CE("ThreadId"); - constexpr u32 Timestamp = AZ_CRC_CE("Timestamp"); - constexpr u32 Duration = AZ_CRC_CE("Duration"); - constexpr u32 Instant = AZ_CRC_CE("Instant"); - } - - EventTraceDriller::EventTraceDriller() - { - EventTraceDrillerSetupBus::Handler::BusConnect(); - AZStd::ThreadEventBus::Handler::BusConnect(); - } - - EventTraceDriller::~EventTraceDriller() - { - AZStd::ThreadEventBus::Handler::BusDisconnect(); - EventTraceDrillerSetupBus::Handler::BusDisconnect(); - } - - void EventTraceDriller::Start(const Param* params, int numParams) - { - (void)params; - (void)numParams; - - EventTraceDrillerBus::Handler::BusConnect(); - TickBus::Handler::BusConnect(); - - EventTraceDrillerBus::AllowFunctionQueuing(true); - } - - void EventTraceDriller::Stop() - { - EventTraceDrillerBus::AllowFunctionQueuing(false); - EventTraceDrillerBus::ClearQueuedEvents(); - - EventTraceDrillerBus::Handler::BusDisconnect(); - TickBus::Handler::BusDisconnect(); - } - - void EventTraceDriller::OnTick(float deltaTime, ScriptTimePoint time) - { - (void)deltaTime; - (void)time; - - AZ_TRACE_METHOD(); - RecordThreads(); - EventTraceDrillerBus::ExecuteQueuedEvents(); - } - - void EventTraceDriller::SetThreadName(const AZStd::thread_id& id, const char* name) - { - AZStd::lock_guard lock(m_ThreadMutex); - m_Threads[(size_t)id.m_id] = ThreadData{ name }; - } - - void EventTraceDriller::OnThreadEnter(const AZStd::thread::id& id, const AZStd::thread_desc* desc) - { - if (desc && desc->m_name) - { - SetThreadName(id, desc->m_name); - } - } - - void EventTraceDriller::OnThreadExit(const AZStd::thread::id& id) - { - AZStd::lock_guard lock(m_ThreadMutex); - m_Threads.erase((size_t)id.m_id); - } - - void EventTraceDriller::RecordThreads() - { - if (!m_output || m_Threads.empty()) - { - return; - } - // Main bus mutex guards m_output. - auto& context = EventTraceDrillerBus::GetOrCreateContext(); - - AZStd::scoped_lock lock(context.m_contextMutex, m_ThreadMutex); - for (const auto& keyValue : m_Threads) - { - m_output->BeginTag(Crc::EventTraceDriller); - m_output->BeginTag(Crc::ThreadInfo); - m_output->Write(Crc::ThreadId, keyValue.first); - m_output->Write(Crc::Name, keyValue.second.name); - m_output->EndTag(Crc::ThreadInfo); - m_output->EndTag(Crc::EventTraceDriller); - } - } - - void EventTraceDriller::RecordSlice( - const char* name, - const char* category, - const AZStd::thread_id threadId, - AZ::u64 timestamp, - AZ::u32 duration) - { - m_output->BeginTag(Crc::EventTraceDriller); - m_output->BeginTag(Crc::Slice); - m_output->Write(Crc::Name, name); - m_output->Write(Crc::Category, category); - m_output->Write(Crc::ThreadId, (size_t)threadId.m_id); - m_output->Write(Crc::Timestamp, timestamp); - m_output->Write(Crc::Duration, std::max(duration, 1u)); - m_output->EndTag(Crc::Slice); - m_output->EndTag(Crc::EventTraceDriller); - } - - void EventTraceDriller::RecordInstantGlobal( - const char* name, - const char* category, - AZ::u64 timestamp) - { - m_output->BeginTag(Crc::EventTraceDriller); - m_output->BeginTag(Crc::Instant); - m_output->Write(Crc::Name, name); - m_output->Write(Crc::Category, category); - m_output->Write(Crc::Timestamp, timestamp); - m_output->EndTag(Crc::Instant); - m_output->EndTag(Crc::EventTraceDriller); - } - - void EventTraceDriller::RecordInstantThread( - const char* name, - const char* category, - const AZStd::thread_id threadId, - AZ::u64 timestamp) - { - m_output->BeginTag(Crc::EventTraceDriller); - m_output->BeginTag(Crc::Instant); - m_output->Write(Crc::Name, name); - m_output->Write(Crc::Category, category); - m_output->Write(Crc::ThreadId, (size_t)threadId.m_id); - m_output->Write(Crc::Timestamp, timestamp); - m_output->EndTag(Crc::Instant); - m_output->EndTag(Crc::EventTraceDriller); - } -} // namespace AZ::Debug diff --git a/Code/Framework/AzCore/AzCore/Debug/EventTraceDriller.h b/Code/Framework/AzCore/AzCore/Debug/EventTraceDriller.h deleted file mode 100644 index b96a1a88f4..0000000000 --- a/Code/Framework/AzCore/AzCore/Debug/EventTraceDriller.h +++ /dev/null @@ -1,87 +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 -#include -#include -#include -#include - -namespace AZ -{ - namespace Debug - { - class EventTraceDriller - : public Driller - , public EventTraceDrillerBus::Handler - , public EventTraceDrillerSetupBus::Handler - , public AZStd::ThreadEventBus::Handler - , public AZ::TickBus::Handler - { - public: - AZ_CLASS_ALLOCATOR(EventTraceDriller, OSAllocator, 0) - - EventTraceDriller(); - virtual ~EventTraceDriller(); - - private: - // Driller - ////////////////////////////////////////////////////////////////////////// - const char* GroupName() const override { return "SystemDrillers"; } - const char* GetName() const override { return "EventTraceDriller"; } - const char* GetDescription() const override { return "Handles timed events for a Chrome Tracing."; } - void Start(const Param* params = NULL, int numParams = 0) override; - void Stop() override; - - // ThreadBus - ////////////////////////////////////////////////////////////////////////// - void OnThreadEnter(const AZStd::thread::id& id, const AZStd::thread_desc* desc) override; - void OnThreadExit(const AZStd::thread::id& id) override; - - // TickBus - ////////////////////////////////////////////////////////////////////////// - void OnTick(float deltaTime, ScriptTimePoint time) override; - - // EventTraceDrillerSetupBus - ////////////////////////////////////////////////////////////////////////// - void SetThreadName(const AZStd::thread_id& threadId, const char* name) override; - - // EventTraceDrillerBus - ////////////////////////////////////////////////////////////////////////// - void RecordSlice( - const char* name, - const char* category, - const AZStd::thread_id threadId, - AZ::u64 timestamp, - AZ::u32 duration) override; - - void RecordInstantGlobal( - const char* name, - const char* category, - AZ::u64 timestamp) override; - - void RecordInstantThread( - const char* name, - const char* category, - const AZStd::thread_id threadId, - AZ::u64 timestamp) override; - - void RecordThreads(); - - struct ThreadData - { - AZStd::string name; - }; - - AZStd::recursive_mutex m_ThreadMutex; - AZStd::unordered_map, AZStd::equal_to, OSStdAllocator> m_Threads; - }; - } -} // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/Debug/EventTraceDrillerBus.h b/Code/Framework/AzCore/AzCore/Debug/EventTraceDrillerBus.h deleted file mode 100644 index c588559088..0000000000 --- a/Code/Framework/AzCore/AzCore/Debug/EventTraceDrillerBus.h +++ /dev/null @@ -1,81 +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 -#include -#include - -namespace AZStd -{ - struct thread_id; -} - -namespace AZ -{ - namespace Debug - { - class EventTraceDrillerInterface - : public DrillerEBusTraits - { - public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const bool EnableEventQueue = true; - static const bool EventQueueingActiveByDefault = false; - ////////////////////////////////////////////////////////////////////////// - - virtual ~EventTraceDrillerInterface() {} - - virtual void RecordSlice( - const char* name, - const char* category, - const AZStd::thread_id threadId, - AZ::u64 timestamp, - AZ::u32 duration) = 0; - - virtual void RecordInstantThread( - const char* name, - const char* category, - const AZStd::thread_id threadId, - AZ::u64 timestamp) = 0; - - virtual void RecordInstantGlobal( - const char* name, - const char* category, - AZ::u64 timestamp) = 0; - }; - - typedef AZ::EBus EventTraceDrillerBus; - - class EventTraceDrillerSetupInterface - : public DrillerEBusTraits - { - public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - ////////////////////////////////////////////////////////////////////////// - - virtual ~EventTraceDrillerSetupInterface() {} - - virtual void SetThreadName(const AZStd::thread_id& threadId, const char* name) = 0; - }; - - typedef AZ::EBus EventTraceDrillerSetupBus; - } -} - -#define AZ_TRACE_INSTANT_GLOBAL_CATEGORY(name, category) \ - EBUS_QUEUE_EVENT(AZ::Debug::EventTraceDrillerBus, RecordInstantGlobal, name, category, AZStd::GetTimeNowMicroSecond()) -#define AZ_TRACE_INSTANT_GLOBAL(name) AZ_TRACE_INSTANT_GLOBAL_CATEGORY(name, "") - -#define AZ_TRACE_INSTANT_THREAD_CATEGORY(name, category) \ - EBUS_QUEUE_EVENT(AZ::Debug::EventTraceDrillerBus, RecordInstantThread, name, category, AZStd::this_thread::get_id(), AZStd::GetTimeNowMicroSecond()) -#define AZ_TRACE_INSTANT_THREAD(name) AZ_TRACE_INSTANT_THREAD_CATEGORY(name, "") diff --git a/Code/Framework/AzCore/AzCore/Driller/DefaultStringPool.h b/Code/Framework/AzCore/AzCore/Driller/DefaultStringPool.h deleted file mode 100644 index 630061f089..0000000000 --- a/Code/Framework/AzCore/AzCore/Driller/DefaultStringPool.h +++ /dev/null @@ -1,125 +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 - * - */ -#ifndef AZCORE_DRILLER_DEFAULT_STRING_POOL_H -#define AZCORE_DRILLER_DEFAULT_STRING_POOL_H - -#include - -#include -#include - -namespace AZ -{ - namespace Debug - { - template - struct unordered_map - { - typedef AZStd::unordered_map, AZStd::equal_to, OSStdAllocator> type; - }; - - template - struct unordered_set - { - typedef AZStd::unordered_set, AZStd::equal_to, OSStdAllocator> type; - }; - - /** - * Default implementation of a string pool. - */ - class DrillerDefaultStringPool - : public DrillerStringPool - { - public: - virtual ~DrillerDefaultStringPool() - { - Reset(); - } - - typedef unordered_map::type CrcToStringMapType; - typedef unordered_set::type OwnedStringsMapType; - - /** - * Add a copy of the string to the pool. If we return true the string was added otherwise it was already in the bool. - * In both cases the crc32 of the string and the pointer to the shared copy is returned (optional for poolStringAddress)! - */ - virtual bool InsertCopy(const char* string, unsigned int length, AZ::u32& crc32, const char** poolStringAddress = nullptr) - { - crc32 = AZ::Crc32(string, length); - CrcToStringMapType::pair_iter_bool insertIt = m_crcToStringMap.insert_key(crc32); - if (insertIt.second) - { - char* newString = reinterpret_cast(azmalloc(length + 1, 1, AZ::OSAllocator)); - memcpy(newString, string, length); - newString[length] = '\0'; // terminate - m_ownedStrings.insert(newString); - insertIt.first->second = newString; - } - if (poolStringAddress) - { - *poolStringAddress = insertIt.first->second; - } - return insertIt.second; - } - - /** - * Same as the InsertCopy above without actually coping the string into the pool. The pool assumes that - * none of the strings added to the pool will be deleted. - */ - virtual bool Insert(const char* string, unsigned int length, AZ::u32& crc32) - { - crc32 = AZ::Crc32(string, length); - return m_crcToStringMap.insert(AZStd::make_pair(crc32, string)).second; - } - - /// Finds a string in the pool by crc32. - virtual const char* Find(AZ::u32 crc32) - { - CrcToStringMapType::iterator it = m_crcToStringMap.find(crc32); - if (it != m_crcToStringMap.end()) - { - return it->second; - } - return NULL; - } - - virtual void Erase(AZ::u32 crc32) - { - CrcToStringMapType::iterator it = m_crcToStringMap.find(crc32); - if (it != m_crcToStringMap.end()) - { - OwnedStringsMapType::iterator ownerIt = m_ownedStrings.find(it->second); - if (ownerIt != m_ownedStrings.end()) - { - azfree(const_cast(it->second), AZ::OSAllocator); - m_ownedStrings.erase(ownerIt); - } - m_crcToStringMap.erase(it); - } - } - - virtual void Reset() - { - for (OwnedStringsMapType::iterator it = m_ownedStrings.begin(); it != m_ownedStrings.end(); ++it) - { - azfree(const_cast(*it), AZ::OSAllocator); - } - m_crcToStringMap.clear(); - m_ownedStrings.clear(); - } - protected: - CrcToStringMapType m_crcToStringMap; - OwnedStringsMapType m_ownedStrings; - }; - } // namespace Debug -} // namespace AZ - -#endif // AZCORE_DRILLER_DEFAULT_STRING_POOL_H -#pragma once - - diff --git a/Code/Framework/AzCore/AzCore/Driller/Driller.cpp b/Code/Framework/AzCore/AzCore/Driller/Driller.cpp deleted file mode 100644 index 7e986be81e..0000000000 --- a/Code/Framework/AzCore/AzCore/Driller/Driller.cpp +++ /dev/null @@ -1,301 +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 -#include - -#include -#include -#include - - -namespace AZ::Debug -{ - class DrillerManagerImpl - : public DrillerManager - { - public: - AZ_CLASS_ALLOCATOR(DrillerManagerImpl, OSAllocator, 0); - - using SessionListType = forward_list::type; - SessionListType m_sessions; - using DrillerArrayType = vector::type; - DrillerArrayType m_drillers; - - ~DrillerManagerImpl() override; - - void Register(Driller* factory) override; - void Unregister(Driller* factory) override; - - void FrameUpdate() override; - - DrillerSession* Start(DrillerOutputStream& output, const DrillerListType& drillerList, int numFrames = -1) override; - void Stop(DrillerSession* session) override; - - int GetNumDrillers() const override { return static_cast(m_drillers.size()); } - Driller* GetDriller(int index) override { return m_drillers[index]; } - }; - - ////////////////////////////////////////////////////////////////////////// - // Driller - - //========================================================================= - // Register - // [3/17/2011] - //========================================================================= - AZ::u32 Driller::GetId() const - { - return AZ::Crc32(GetName()); - } - - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - // Driller Manager - - //========================================================================= - // Register - // [3/17/2011] - //========================================================================= - DrillerManager* DrillerManager::Create(/*const Descriptor& desc*/) - { - const bool createAllocator = !AZ::AllocatorInstance::IsReady(); - if (createAllocator) - { - AZ::AllocatorInstance::Create(); - } - - DrillerManagerImpl* impl = aznew DrillerManagerImpl; - impl->m_ownsOSAllocator = createAllocator; - return impl; - } - - //========================================================================= - // Register - // [3/17/2011] - //========================================================================= - void DrillerManager::Destroy(DrillerManager* manager) - { - const bool allocatorCreated = manager->m_ownsOSAllocator; - delete manager; - if (allocatorCreated) - { - AZ::AllocatorInstance::Destroy(); - } - } - - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - // DrillerManagerImpl - - //========================================================================= - // ~DrillerManagerImpl - // [3/17/2011] - //========================================================================= - DrillerManagerImpl::~DrillerManagerImpl() - { - while (!m_sessions.empty()) - { - Stop(&m_sessions.front()); - } - - while (!m_drillers.empty()) - { - Driller* driller = m_drillers[0]; - Unregister(driller); - delete driller; - } - } - - //========================================================================= - // Register - // [3/17/2011] - //========================================================================= - void - DrillerManagerImpl::Register(Driller* driller) - { - AZ_Assert(driller, "You must provide a valid factory!"); - for (size_t i = 0; i < m_drillers.size(); ++i) - { - if (m_drillers[i]->GetId() == driller->GetId()) - { - AZ_Error("Debug", false, "Driller with id %08x has already been registered! You can't have two factory instances for the same driller type", driller->GetId()); - return; - } - } - m_drillers.push_back(driller); - } - - //========================================================================= - // Unregister - // [3/17/2011] - //========================================================================= - void - DrillerManagerImpl::Unregister(Driller* driller) - { - AZ_Assert(driller, "You must provide a valid factory!"); - for (DrillerArrayType::iterator iter = m_drillers.begin(); iter != m_drillers.end(); ++iter) - { - if ((*iter)->GetId() == driller->GetId()) - { - m_drillers.erase(iter); - return; - } - } - - AZ_Error("Debug", false, "Failed to find driller factory with id %08x", driller->GetId()); - } - - //========================================================================= - // FrameUpdate - // [3/17/2011] - //========================================================================= - void - DrillerManagerImpl::FrameUpdate() - { - if (m_sessions.empty()) - { - return; - } - - AZStd::lock_guard lock(DrillerEBusMutex::GetMutex()); ///< Make sure no driller is writing to the stream - for (SessionListType::iterator sessionIter = m_sessions.begin(); sessionIter != m_sessions.end(); ) - { - DrillerSession& s = *sessionIter; - - // tick the drillers directly if they care. - for (size_t i = 0; i < s.drillers.size(); ++i) - { - s.drillers[i]->Update(); - } - - s.output->EndTag(AZ_CRC("Frame", 0xb5f83ccd)); - - s.output->OnEndOfFrame(); - - s.curFrame++; - - if (s.numFrames != -1) - { - if (s.curFrame == s.numFrames) - { - Stop(&s); - continue; - } - } - - s.output->BeginTag(AZ_CRC("Frame", 0xb5f83ccd)); - s.output->Write(AZ_CRC("FrameNum", 0x85a1a919), s.curFrame); - - ++sessionIter; - } - } - - //========================================================================= - // Start - // [3/17/2011] - //========================================================================= - DrillerSession* - DrillerManagerImpl::Start(DrillerOutputStream& output, const DrillerListType& drillerList, int numFrames) - { - if (drillerList.empty()) - { - return nullptr; - } - - m_sessions.push_back(); - DrillerSession& s = m_sessions.back(); - s.curFrame = 0; - s.numFrames = numFrames; - s.output = &output; - - s.output->WriteHeader(); // first write the header in the stream - - s.output->BeginTag(AZ_CRC("StartData", 0xecf3f53f)); - s.output->Write(AZ_CRC("Platform", 0x3952d0cb), (unsigned int)g_currentPlatform); - for (DrillerListType::const_iterator iDriller = drillerList.begin(); iDriller != drillerList.end(); ++iDriller) - { - const DrillerInfo& di = *iDriller; - s.output->BeginTag(AZ_CRC("Driller", 0xa6e1fb73)); - s.output->Write(AZ_CRC("Name", 0x5e237e06), di.id); - for (int iParam = 0; iParam < (int)di.params.size(); ++iParam) - { - s.output->BeginTag(AZ_CRC("Param", 0xa4fa7c89)); - s.output->Write(AZ_CRC("Name", 0x5e237e06), di.params[iParam].name); - s.output->Write(AZ_CRC("Description", 0x6de44026), di.params[iParam].desc); - s.output->Write(AZ_CRC("Type", 0x8cde5729), di.params[iParam].type); - s.output->Write(AZ_CRC("Value", 0x1d775834), di.params[iParam].value); - s.output->EndTag(AZ_CRC("Param", 0xa4fa7c89)); - } - s.output->EndTag(AZ_CRC("Driller", 0xa6e1fb73)); - } - s.output->EndTag(AZ_CRC("StartData", 0xecf3f53f)); - - s.output->BeginTag(AZ_CRC("Frame", 0xb5f83ccd)); - s.output->Write(AZ_CRC("FrameNum", 0x85a1a919), s.curFrame); - - { - AZStd::lock_guard lock(DrillerEBusMutex::GetMutex()); ///< Make sure no driller is writing to the stream - for (DrillerListType::const_iterator iDriller = drillerList.begin(); iDriller != drillerList.end(); ++iDriller) - { - Driller* driller = nullptr; - const DrillerInfo& di = *iDriller; - for (size_t iDesc = 0; iDesc < m_drillers.size(); ++iDesc) - { - if (m_drillers[iDesc]->GetId() == di.id) - { - driller = m_drillers[iDesc]; - AZ_Assert(driller->m_output == nullptr, "Driller with id %08x is already have an output stream %p (currently we support only 1 at a time)", di.id, driller->m_output); - driller->m_output = &output; - driller->Start(di.params.data(), static_cast(di.params.size())); - s.drillers.push_back(driller); - break; - } - } - AZ_Warning("Driller", driller != nullptr, "We can't start a driller with id %d!", di.id); - } - } - return &s; - } - - - //========================================================================= - // Stop - // [3/17/2011] - //========================================================================= - void - DrillerManagerImpl::Stop(DrillerSession* session) - { - SessionListType::iterator iter; - for (iter = m_sessions.begin(); iter != m_sessions.end(); ++iter) - { - if (&*iter == session) - { - break; - } - } - - AZ_Assert(iter != m_sessions.end(), "We did not find session ID 0x%08x in the list!", session); - if (iter != m_sessions.end()) - { - DrillerSession& s = *session; - - { - AZStd::lock_guard lock(DrillerEBusMutex::GetMutex()); - for (size_t i = 0; i < s.drillers.size(); ++i) - { - s.drillers[i]->Stop(); - s.drillers[i]->m_output = nullptr; - } - } - s.output->EndTag(AZ_CRC("Frame", 0xb5f83ccd)); - m_sessions.erase(iter); - } - } -} // namespace AZ::Debug diff --git a/Code/Framework/AzCore/AzCore/Driller/Driller.h b/Code/Framework/AzCore/AzCore/Driller/Driller.h deleted file mode 100644 index bb2178e51f..0000000000 --- a/Code/Framework/AzCore/AzCore/Driller/Driller.h +++ /dev/null @@ -1,141 +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 - * - */ -#ifndef AZCORE_DRILLER_H -#define AZCORE_DRILLER_H - -#include -namespace AZStd -{ - class mutex; -} -namespace AZ -{ - namespace Debug - { - class DrillerOutputStream; - - /** - * Driller base class. Every driller should inherit from this class. - * When a driller is need to start outputting data - * the DrillerManager will call Driller::Start() so the driller - * can output the initial state for all reported entities. - * The same applies for the Stop. - * Depending on the type of your driller you might choose to collect state - * even before the driller has started. This of course should be a fast as - * possible, as we don't want to burden engine systems and it's highly recommended - * that you use configuration parameters to change that behavior as not all drillers - * are used on a daily basis. - * All drillers should use DebugAllocators (AZ_CLASS_ALLOCATOR(Driller,OSAllocator,0)) - * and they should use 'aznew' to create one, as by default if you don't unregister a - * a driller, the manager will use "delete" to delete them. - * - * IMPORTANT: Driller systems works OUTSIDE engine systems, you should NOT use SystemAllocator or any other engine systems - * as they might be drilled or not available at the moment. - */ - class Driller - { - friend class DrillerManagerImpl; - - public: - struct Param - { - enum Type - { - PT_BOOL, - PT_INT, - PT_FLOAT - }; - const char* desc; - u32 name; - int type; - int value; - }; - - Driller() - : m_output(NULL) {} - virtual ~Driller() {} - - /// Returns the driller ID Crc32 of the name (Crc32(GetName()) - AZ::u32 GetId() const; - /// Driller group name, used only for organizational purpose - virtual const char* GroupName() const = 0; - /// Unique name of the Driller, driller ID is the Crc of the name - virtual const char* GetName() const = 0; - virtual const char* GetDescription() const = 0; - // @{ Managing the list of supported driller parameters. - virtual int GetNumParams() const { return 0; } - virtual const Param* GetParam(int index) const { (void)index; return NULL; } - - protected: - Driller& operator=(const Driller&); - - /// Called by DrillerManager - virtual void Start(const Param* params = NULL, int numParams = 0) { (void)params; (void)numParams; } - /// Called by DrillerManager - virtual void Stop() {} - /// Called every frame by DrillerManger (while the driller is started) - virtual void Update() {} - - DrillerOutputStream* m_output; ///< Session output stream. - }; - - /** - * Stores the information while an active - * driller(s) session is running. - */ - struct DrillerSession - { - int numFrames; - int curFrame; - typedef vector::type DrillerArrayType; - DrillerArrayType drillers; - DrillerOutputStream* output; - }; - - /** - * Driller manager will manage all active driller sessions and driller factories. Generally you will never - * need more than one driller manger. - * IMPORTANT: Driller systems works OUTSIDE engine systems, you should NOT use SystemAllocator or any other engine systems - * as they might be drilled or not available at the moment. - */ - class DrillerManager - { - friend class DrillerRemoteServer; - public: - struct DrillerInfo - { - AZ::u32 id; - vector::type params; - }; - typedef forward_list::type DrillerListType; - - virtual ~DrillerManager() {} - - static DrillerManager* Create(/*const Descriptor& desc*/); - static void Destroy(DrillerManager* manager); - - virtual void Register(Driller* driller) = 0; - virtual void Unregister(Driller* driller) = 0; - - virtual void FrameUpdate() = 0; - - virtual DrillerSession* Start(DrillerOutputStream& output, const DrillerListType& drillerList, int numFrames = -1) = 0; - virtual void Stop(DrillerSession* session) = 0; - - virtual int GetNumDrillers() const = 0; - virtual Driller* GetDriller(int index) = 0; - - private: - // If the manager created the allocator, it should destroy it when it gets destroyed - bool m_ownsOSAllocator = false; - }; - } -} - -#endif // AZCORE_DRILLER_H -#pragma once diff --git a/Code/Framework/AzCore/AzCore/Driller/DrillerBus.cpp b/Code/Framework/AzCore/AzCore/Driller/DrillerBus.cpp deleted file mode 100644 index a46736aa87..0000000000 --- a/Code/Framework/AzCore/AzCore/Driller/DrillerBus.cpp +++ /dev/null @@ -1,65 +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 - -#include -#include -#include - -namespace AZ::Debug -{ - ////////////////////////////////////////////////////////////////////////// - // Globals - // We need to synchronize all driller evens, so we have proper order, and access to the data - // We use a global mutex which should be used for all driller operations. - // The mutex is held in an environment variable so it works across DLLs. - EnvironmentVariable s_drillerGlobalMutex; - ////////////////////////////////////////////////////////////////////////// - - - //========================================================================= - // lock - // [4/11/2011] - //========================================================================= - void DrillerEBusMutex::lock() - { - GetMutex().lock(); - } - - //========================================================================= - // try_lock - // [4/11/2011] - //========================================================================= - bool DrillerEBusMutex::try_lock() - { - return GetMutex().try_lock(); - } - - //========================================================================= - // unlock - // [4/11/2011] - //========================================================================= - void DrillerEBusMutex::unlock() - { - GetMutex().unlock(); - } - - //========================================================================= - // unlock - // [4/11/2011] - //========================================================================= - AZStd::recursive_mutex& DrillerEBusMutex::GetMutex() - { - if (!s_drillerGlobalMutex) - { - s_drillerGlobalMutex = Environment::CreateVariable(AZ_FUNCTION_SIGNATURE); - } - return *s_drillerGlobalMutex; - } -} // namespace AZ::Debug diff --git a/Code/Framework/AzCore/AzCore/Driller/DrillerBus.h b/Code/Framework/AzCore/AzCore/Driller/DrillerBus.h deleted file mode 100644 index 4c625f007d..0000000000 --- a/Code/Framework/AzCore/AzCore/Driller/DrillerBus.h +++ /dev/null @@ -1,52 +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 - * - */ -#ifndef AZCORE_DRILLER_BUS_H -#define AZCORE_DRILLER_BUS_H - -#include -#include -#include - -namespace AZStd -{ - class mutex; -} - -namespace AZ -{ - namespace Debug - { - class DrillerEBusMutex - { - public: - typedef AZStd::recursive_mutex MutexType; - - static MutexType& GetMutex(); - void lock(); - bool try_lock(); - void unlock(); - }; - - /** - * Specialization of the EBusTraits for a driller bus. We make sure - * all allocation are made using DebugAllocation (so no engine systems are involved). - * In addition we make sure all driller buses use the same Mutex to synchronize data across - * threads (so all events came in order all the time), they are still executed in the context of - * the thread. - */ - struct DrillerEBusTraits - : public AZ::EBusTraits - { - typedef DrillerEBusMutex MutexType; - typedef OSStdAllocator AllocatorType; - }; - } -} - -#endif // AZCORE_DRILLER_BUS_H -#pragma once diff --git a/Code/Framework/AzCore/AzCore/Driller/DrillerRootHandler.h b/Code/Framework/AzCore/AzCore/Driller/DrillerRootHandler.h deleted file mode 100644 index 6a12c0cb8b..0000000000 --- a/Code/Framework/AzCore/AzCore/Driller/DrillerRootHandler.h +++ /dev/null @@ -1,170 +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 - * - */ -#ifndef AZCORE_DRILLER_ROOT_HANDLER_H -#define AZCORE_DRILLER_ROOT_HANDLER_H - -#include -#include - -namespace AZ -{ - namespace Debug - { - // Please check DrillerRootHandler class... this is the one for direct use. - - /** - * Handler for the tag. - */ - class DrillerDrillerdataHandler - : public DrillerHandlerParser - { - public: - class ParamHandler - : public DrillerHandlerParser - { - public: - virtual void OnData(const DrillerSAXParser::Data& dataNode) - { - if (dataNode.m_name == AZ_CRC("Name", 0x5e237e06)) - { - dataNode.Read(m_param->name); - } - else if (dataNode.m_name == AZ_CRC("Description", 0x6de44026)) - { - m_param->desc = NULL; // ignored - } - else if (dataNode.m_name == AZ_CRC("Type", 0x8cde5729)) - { - dataNode.Read(m_param->type); - } - else if (dataNode.m_name == AZ_CRC("Value", 0x1d775834)) - { - dataNode.Read(m_param->value); - } - } - Driller::Param* m_param; - }; - - virtual DrillerHandlerParser* OnEnterTag(u32 tagName) - { - if (tagName == AZ_CRC("Param", 0xa4fa7c89)) - { - m_drillerInfo->params.push_back(); - m_paramHandler.m_param = &m_drillerInfo->params.back(); - return &m_paramHandler; - } - return NULL; - } - - virtual void OnData(const DrillerSAXParser::Data& dataNode) - { - if (dataNode.m_name == AZ_CRC("Name", 0x5e237e06)) - { - dataNode.Read(m_drillerInfo->id); - } - } - - DrillerManager::DrillerInfo* m_drillerInfo; - ParamHandler m_paramHandler; - }; - - - /** - * Handler for the tag - */ - class DrillerStartdataHandler - : public DrillerHandlerParser - { - public: - virtual DrillerHandlerParser* OnEnterTag(u32 tagName) - { - if (tagName == AZ_CRC("Driller", 0xa6e1fb73)) - { - m_drillers.push_back(); - m_drillerDataHandler.m_drillerInfo = &m_drillers.back(); - return &m_drillerDataHandler; - } - return NULL; - } - virtual void OnData(const DrillerSAXParser::Data& dataNode) - { - if (dataNode.m_name == AZ_CRC("Platform", 0x3952d0cb)) - { - dataNode.Read(m_platform); - } - } - - unsigned int m_platform; - DrillerManager::DrillerListType m_drillers; - DrillerDrillerdataHandler m_drillerDataHandler; - }; - - /** - * Handler for the tag - */ - template - class FrameHandler - : public DrillerHandlerParser - { - public: - FrameHandler() - : DrillerHandlerParser(DrillerContainer::s_isWarnOnMissingDrillers) - , m_currentFrame(-1) {} - - virtual DrillerHandlerParser* OnEnterTag(u32 tagName) { return m_drillersContainer.FindDrillerHandler(tagName); } - virtual void OnData(const DrillerSAXParser::Data& dataNode) - { - if (dataNode.m_name == AZ_CRC("FrameNum", 0x85a1a919)) - { - dataNode.Read(m_currentFrame); - } - } - DrillerContainer m_drillersContainer; - int m_currentFrame; - }; - - /** - * Use this class a input parameter to DrillerSAXParserHandler::DrillerSAXParserHandler(). It will handle all root level - * tags for a standard driller input stream stream. - * - * DrillerContainer should comply to the following requirements: - * - default constructible - * - has a static const bool s_isWarnOnMissingDrillers member to indicate if you want to - * trigger a warning when a driller is not found in the class. - * - implement a function DrillerHandlerParser* DrillerContainer::FindDrillerHandler(u32 drillerName) - * - */ - template - class DrillerRootHandler - : public DrillerHandlerParser - { - public: - DrillerContainer* GetDrillerContainer() { return m_frameHandler.m_drillersContainer; } - - virtual DrillerHandlerParser* OnEnterTag(u32 tagName) - { - if (tagName == AZ_CRC("StartData", 0xecf3f53f)) - { - return &m_drillerSessionInfo; - } - if (tagName == AZ_CRC("Frame", 0xb5f83ccd)) - { - return &m_frameHandler; - } - return NULL; - } - DrillerStartdataHandler m_drillerSessionInfo; - FrameHandler m_frameHandler; - }; - } // namespace Debug -} // namespace AZ - -#endif // AZCORE_DRILLER_ROOT_HANDLER_H -#pragma once - - diff --git a/Code/Framework/AzCore/AzCore/Driller/Stream.cpp b/Code/Framework/AzCore/AzCore/Driller/Stream.cpp deleted file mode 100644 index c86755149c..0000000000 --- a/Code/Framework/AzCore/AzCore/Driller/Stream.cpp +++ /dev/null @@ -1,893 +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 - -#include -#include -#include -#include -#include - -#include - -#if !defined(AZCORE_EXCLUDE_ZLIB) -# define AZ_FILE_STREAM_COMPRESSION -#endif // AZCORE_EXCLUDE_ZLIB - -#if defined(AZ_FILE_STREAM_COMPRESSION) -# include -#endif // AZ_FILE_STREAM_COMPRESSION - -namespace AZ::Debug -{ - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // Driller output stream - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - void DrillerOutputStream::Write(u32 name, const AZ::Vector3& v) - { - float data[4]; - unsigned int dataSize = 3 * sizeof(float); - v.StoreToFloat4(data); - StreamEntry de; - de.name = name; - de.sizeAndFlags = dataSize; - WriteBinary(de); - WriteBinary(data, dataSize); - } - void DrillerOutputStream::Write(u32 name, const AZ::Vector4& v) - { - float data[4]; - unsigned int dataSize = 4 * sizeof(float); - v.StoreToFloat4(data); - StreamEntry de; - de.name = name; - de.sizeAndFlags = dataSize; - WriteBinary(de); - WriteBinary(data, dataSize); - } - void DrillerOutputStream::Write(u32 name, const AZ::Aabb& aabb) - { - float data[7]; - unsigned int dataSize = 6 * sizeof(float); - aabb.GetMin().StoreToFloat4(data); - aabb.GetMax().StoreToFloat4(&data[3]); - StreamEntry de; - de.name = name; - de.sizeAndFlags = dataSize; - WriteBinary(de); - WriteBinary(data, dataSize); - } - void DrillerOutputStream::Write(u32 name, const AZ::Obb& obb) - { - float data[10]; - unsigned int dataSize = 10 * sizeof(float); // position (Vector3), rotation (Quaternion) and halfLengths (Vector3) - obb.GetPosition().StoreToFloat3(data); - obb.GetRotation().StoreToFloat4(&data[3]); - obb.GetHalfLengths().StoreToFloat3(&data[7]); - StreamEntry de; - de.name = name; - de.sizeAndFlags = dataSize; - WriteBinary(de); - WriteBinary(data, dataSize); - } - void DrillerOutputStream::Write(u32 name, const AZ::Transform& tm) - { - float data[12]; - unsigned int dataSize = 12 * sizeof(float); - const Matrix3x4 matrix3x4 = Matrix3x4::CreateFromTransform(tm); - matrix3x4.StoreToRowMajorFloat12(data); - StreamEntry de; - de.name = name; - de.sizeAndFlags = dataSize; - WriteBinary(de); - WriteBinary(data, dataSize); - } - void DrillerOutputStream::Write(u32 name, const AZ::Matrix3x3& tm) - { - float data[9]; - unsigned int dataSize = 9 * sizeof(float); - tm.StoreToRowMajorFloat9(data); - StreamEntry de; - de.name = name; - de.sizeAndFlags = dataSize; - WriteBinary(de); - WriteBinary(data, dataSize); - } - void DrillerOutputStream::Write(u32 name, const AZ::Matrix4x4& tm) - { - float data[16]; - unsigned int dataSize = 16 * sizeof(float); - tm.StoreToRowMajorFloat16(data); - StreamEntry de; - de.name = name; - de.sizeAndFlags = dataSize; - WriteBinary(de); - WriteBinary(data, dataSize); - } - void DrillerOutputStream::Write(u32 name, const AZ::Quaternion& tm) - { - float data[4]; - unsigned int dataSize = 4 * sizeof(float); - tm.StoreToFloat4(data); - StreamEntry de; - de.name = name; - de.sizeAndFlags = dataSize; - WriteBinary(de); - WriteBinary(data, dataSize); - } - void DrillerOutputStream::Write(u32 name, const AZ::Plane& plane) - { - Write(name, plane.GetPlaneEquationCoefficients()); - } - void DrillerOutputStream::WriteHeader() - { - StreamHeader sh; // StreamHeader should be endianess independent. - WriteBinary(&sh, sizeof(sh)); - } - - void DrillerOutputStream::WriteTimeUTC(u32 name) - { - AZStd::sys_time_t now = AZStd::GetTimeUTCMilliSecond(); - Write(name, now); - } - - void DrillerOutputStream::WriteTimeMicrosecond(u32 name) - { - AZStd::sys_time_t now = AZStd::GetTimeNowMicroSecond(); - Write(name, now); - } - - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // Driller Input Stream - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - bool DrillerInputStream::ReadHeader() - { - DrillerOutputStream::StreamHeader sh; // StreamHeader should be endianess independent. - unsigned int numRead = ReadBinary(&sh, sizeof(sh)); - (void)numRead; - AZ_Error("IO", numRead == sizeof(sh), "We should have atleast %d bytes in the stream to read the header!", sizeof(sh)); - if (numRead != sizeof(sh)) - { - return false; - } - m_isEndianSwap = AZ::IsBigEndian(static_cast(sh.platform)) != AZ::IsBigEndian(AZ::g_currentPlatform); - return true; - } - - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // Driller file stream - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - //========================================================================= - // DrillerOutputFileStream::DrillerOutputFileStream - // [3/23/2011] - //========================================================================= - DrillerOutputFileStream::DrillerOutputFileStream() - { -#if defined(AZ_FILE_STREAM_COMPRESSION) - m_zlib = azcreate(ZLib, (&AllocatorInstance::GetAllocator()), OSAllocator); - m_zlib->StartCompressor(2); -#endif - } - - //========================================================================= - // DrillerOutputFileStream::~DrillerOutputFileStream - // [3/23/2011] - //========================================================================= - DrillerOutputFileStream::~DrillerOutputFileStream() - { -#if defined(AZ_FILE_STREAM_COMPRESSION) - azdestroy(m_zlib, OSAllocator); -#endif - } - - //========================================================================= - // DrillerOutputFileStream::Open - // [3/23/2011] - //========================================================================= - bool DrillerOutputFileStream::Open(const char* fileName, int mode, int platformFlags) - { - if (IO::SystemFile::Open(fileName, mode, platformFlags)) - { - m_dataBuffer.reserve(100 * 1024); -#if defined(AZ_FILE_STREAM_COMPRESSION) - // // Enable optional: encode the file in the same format as the streamer so they are interchangeable - // IO::CompressorHeader ch; - // ch.SetAZCS(); - // ch.m_compressorId = IO::CompressorZLib::TypeId(); - // ch.m_uncompressedSize = 0; // will be updated later - // AZStd::endian_swap(ch.m_compressorId); - // AZStd::endian_swap(ch.m_uncompressedSize); - // IO::SystemFile::Write(&ch,sizeof(ch)); - // IO::CompressorZLibHeader zlibHdr; - // zlibHdr.m_numSeekPoints = 0; - // IO::SystemFile::Write(&zlibHdr,sizeof(zlibHdr)); -#endif - return true; - } - return false; - } - - //========================================================================= - // DrillerOutputFileStream::Close - // [3/23/2011] - //========================================================================= - void DrillerOutputFileStream::Close() - { - unsigned int dataSizeInBuffer = static_cast(m_dataBuffer.size()); - { -#if defined(AZ_FILE_STREAM_COMPRESSION) - unsigned int minCompressBufferSize = m_zlib->GetMinCompressedBufferSize(dataSizeInBuffer); - if (m_compressionBuffer.size() < minCompressBufferSize) // grow compression buffer if needed - { - m_compressionBuffer.clear(); - m_compressionBuffer.resize(minCompressBufferSize); - } - unsigned int compressedSize; - do - { - compressedSize = m_zlib->Compress(m_dataBuffer.data(), dataSizeInBuffer, m_compressionBuffer.data(), (unsigned)m_compressionBuffer.size(), ZLib::FT_FINISH); - if (compressedSize) - { - IO::SystemFile::Write(m_compressionBuffer.data(), compressedSize); - } - } while (compressedSize > 0); - m_zlib->ResetCompressor(); -#else - if (dataSizeInBuffer) - { - IO::SystemFile::Write(m_dataBuffer.data(), m_dataBuffer.size()); - } -#endif - m_dataBuffer.clear(); - } - IO::SystemFile::Close(); - } - //========================================================================= - // DrillerOutputFileStream::WriteBinary - // [3/23/2011] - //========================================================================= - void DrillerOutputFileStream::WriteBinary(const void* data, unsigned int dataSize) - { - size_t dataSizeInBuffer = m_dataBuffer.size(); - if (dataSizeInBuffer + dataSize > m_dataBuffer.capacity()) - { - if (dataSizeInBuffer > 0) - { -#if defined(AZ_FILE_STREAM_COMPRESSION) - // we need to flush the data - unsigned int dataToCompress = static_cast(dataSizeInBuffer); - unsigned int minCompressBufferSize = m_zlib->GetMinCompressedBufferSize(dataToCompress); - if (m_compressionBuffer.size() < minCompressBufferSize) // grow compression buffer if needed - { - m_compressionBuffer.clear(); - m_compressionBuffer.resize(minCompressBufferSize); - } - while (dataToCompress > 0) - { - unsigned int compressedSize = m_zlib->Compress(m_dataBuffer.data(), dataToCompress, m_compressionBuffer.data(), (unsigned)m_compressionBuffer.size()); - if (compressedSize) - { - IO::SystemFile::Write(m_compressionBuffer.data(), compressedSize); - } - } -#else - IO::SystemFile::Write(m_dataBuffer.data(), m_dataBuffer.size()); -#endif - m_dataBuffer.clear(); - } - } - m_dataBuffer.insert(m_dataBuffer.end(), reinterpret_cast(data), reinterpret_cast(data) + dataSize); - } - - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // Driller file input stream - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - - //========================================================================= - // DrillerInputFileStream::DrillerInputFileStream - // [3/23/2011] - //========================================================================= - DrillerInputFileStream::DrillerInputFileStream() - { -#if defined(AZ_FILE_STREAM_COMPRESSION) - m_zlib = azcreate(ZLib, (&AllocatorInstance::GetAllocator()), OSAllocator); - m_zlib->StartDecompressor(); -#endif - } - - //========================================================================= - // DrillerInputFileStream::DrillerInputFileStream - // [3/23/2011] - //========================================================================= - DrillerInputFileStream::~DrillerInputFileStream() - { -#if defined(AZ_FILE_STREAM_COMPRESSION) - azdestroy(m_zlib, OSAllocator); -#endif - } - - //========================================================================= - // DrillerInputFileStream::Open - // [3/23/2011] - //========================================================================= - bool DrillerInputFileStream::Open(const char* fileName, int mode, int platformFlags) - { - if (IO::SystemFile::Open(fileName, mode, platformFlags)) - { - DrillerOutputStream::StreamHeader sh; -#if defined(AZ_FILE_STREAM_COMPRESSION) - // TODO: optional encode the file in the same format as the streamer so they are interchangeable -#endif - // first read the header of the stream file. - return ReadHeader(); - } - return false; - } - //========================================================================= - // DrillerInputFileStream::ReadBinary - // [3/23/2011] - //========================================================================= - unsigned int DrillerInputFileStream::ReadBinary(void* data, unsigned int maxDataSize) - { - // make sure the compressed buffer if full enough... - size_t dataToLoad = maxDataSize * 2; - m_compressedData.reserve(dataToLoad); - while (m_compressedData.size() < dataToLoad) - { - unsigned char buffer[10 * 1024]; - IO::SystemFile::SizeType bytesRead = Read(AZ_ARRAY_SIZE(buffer), buffer); - if (bytesRead > 0) - { - m_compressedData.insert(m_compressedData.end(), (unsigned char*)buffer, buffer + bytesRead); - } - if (bytesRead < AZ_ARRAY_SIZE(buffer)) - { - break; - } - } -#if defined(AZ_FILE_STREAM_COMPRESSION) - unsigned int dataSize = maxDataSize; - unsigned int bytesProcessed = m_zlib->Decompress(m_compressedData.data(), (unsigned)m_compressedData.size(), data, dataSize); - unsigned int readSize = maxDataSize - dataSize; // Zlib::Decompress decrements the dataSize parameter by the amount uncompressed -#else - unsigned int bytesProcessed = AZStd::GetMin((unsigned int)m_compressedData.size(), maxDataSize); - unsigned int readSize = bytesProcessed; - memcpy(data, m_compressedData.data(), readSize); -#endif - m_compressedData.erase(m_compressedData.begin(), m_compressedData.begin() + bytesProcessed); - return readSize; - } - - //========================================================================= - // DrillerInputFileStream::Close - // [3/23/2011] - //========================================================================= - void DrillerInputFileStream::Close() - { -#if defined(AZ_FILE_STREAM_COMPRESSION) - if (m_zlib) - { - m_zlib->ResetDecompressor(); - } -#endif // AZ_FILE_STREAM_COMPRESSION - AZ::IO::SystemFile::Close(); - } - - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // DrillerSAXParser - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - //========================================================================= - // DrillerSAXParser - // [3/23/2011] - //========================================================================= - DrillerSAXParser::DrillerSAXParser(const TagCallbackType& tcb, const DataCallbackType& dcb) - : m_tagCallback(tcb) - , m_dataCallback(dcb) - { - } - - //========================================================================= - // ProcessStream - // [3/23/2011] - //========================================================================= - void - DrillerSAXParser::ProcessStream(DrillerInputStream& stream) - { - static const int processChunkSize = 15 * 1024; - char buffer[processChunkSize]; - unsigned int dataSize; - bool isEndianSwap = stream.IsEndianSwap(); - while ((dataSize = stream.ReadBinary(buffer, processChunkSize)) > 0) - { - char* dataStart = buffer; - char* dataEnd = dataStart + dataSize; - bool dataInBuffer = false; - if (!m_buffer.empty()) - { - m_buffer.insert(m_buffer.end(), dataStart, dataEnd); - dataStart = m_buffer.data(); - dataEnd = dataStart + m_buffer.size(); - dataInBuffer = true; - } - const int entrySize = sizeof(DrillerOutputStream::StreamEntry); - while (dataStart != dataEnd) - { - if ((dataEnd - dataStart) < entrySize) // we need at least one entry to proceed - { - // not enough data to process, buffer it. - if (!dataInBuffer) - { - m_buffer.insert(m_buffer.end(), dataStart, dataEnd); - } - break; - } - - DrillerOutputStream::StreamEntry* se = reinterpret_cast(dataStart); - if (isEndianSwap) - { - // endian swap - AZStd::endian_swap(se->name); - AZStd::endian_swap(se->sizeAndFlags); - } - - u32 dataType = (se->sizeAndFlags & DrillerOutputStream::StreamEntry::dataInternalMask) >> DrillerOutputStream::StreamEntry::dataInternalShift; - u32 value = se->sizeAndFlags & DrillerOutputStream::StreamEntry::dataSizeMask; - Data de; - de.m_name = se->name; - de.m_stringPool = stream.GetStringPool(); - de.m_isPooledString = false; - de.m_isPooledStringCrc32 = false; - switch (dataType) - { - case DrillerOutputStream::StreamEntry::INT_TAG: - { - bool isStart = (value != 0); - m_tagCallback(se->name, isStart); - dataStart += entrySize; - } break; - case DrillerOutputStream::StreamEntry::INT_DATA_U8: - { - u8 value8 = static_cast(value); - de.m_data = &value8; - de.m_dataSize = 1; - de.m_isEndianSwap = false; - m_dataCallback(de); - dataStart += entrySize; - } break; - case DrillerOutputStream::StreamEntry::INT_DATA_U16: - { - u16 value16 = static_cast(value); - de.m_data = &value16; - de.m_dataSize = 2; - de.m_isEndianSwap = false; - m_dataCallback(de); - dataStart += entrySize; - } break; - case DrillerOutputStream::StreamEntry::INT_DATA_U29: - { - de.m_data = &value; - de.m_dataSize = 4; - de.m_isEndianSwap = false; - m_dataCallback(de); - dataStart += entrySize; - } break; - case DrillerOutputStream::StreamEntry::INT_POOLED_STRING: - { - unsigned int userDataSize = value; - if ((userDataSize + entrySize) <= (unsigned)(dataEnd - dataStart)) - { - // Add string to the pool - AZ_Assert(de.m_stringPool != nullptr, "We require a string pool to parse this stream"); - AZ::u32 crc32; - const char* stringPtr; - dataStart += entrySize; - de.m_stringPool->InsertCopy(reinterpret_cast(dataStart), userDataSize, crc32, &stringPtr); - de.m_dataSize = userDataSize; - de.m_isEndianSwap = isEndianSwap; - de.m_isPooledString = true; - de.m_data = const_cast(static_cast(stringPtr)); - m_dataCallback(de); - dataStart += userDataSize; - } - else - { - // we can't process data right now add it to the buffer (if we have not done that already) - if (!dataInBuffer) - { - m_buffer.insert(m_buffer.end(), dataStart, dataEnd); - } - dataEnd = dataStart; // exit the loop - } - } break; - case DrillerOutputStream::StreamEntry::INT_POOLED_STRING_CRC32: - { - de.m_isPooledStringCrc32 = true; - AZ_Assert(value == 4, "The data size for a pooled string crc32 should be 4 bytes!"); - } // continue to INT_SIZE - case DrillerOutputStream::StreamEntry::INT_SIZE: - { - unsigned int userDataSize = value; - if ((userDataSize + entrySize) <= (unsigned)(dataEnd - dataStart)) // do we have all the date we need to process... - { - dataStart += entrySize; - de.m_data = dataStart; - de.m_dataSize = userDataSize; - de.m_isEndianSwap = isEndianSwap; - m_dataCallback(de); - dataStart += userDataSize; - } - else - { - // we can't process data right now add it to the buffer (if we have not done that already) - if (!dataInBuffer) - { - m_buffer.insert(m_buffer.end(), dataStart, dataEnd); - } - dataEnd = dataStart; // exit the loop - } - } break; - default: - { - AZ_Error("DrillerSAXParser",false,"Encounted unknown symbol (%i) while processing stream (%s). Aborting stream.\n",dataType, stream.GetIdentifier()); - - // If we can't process anything, we want to just escape the loop, to avoid spinning infinitely - dataEnd = dataStart; - } break; - } - } - if (dataInBuffer) // if the data was in the buffer remove the processed data! - { - m_buffer.erase(m_buffer.begin(), m_buffer.begin() + (dataStart - m_buffer.data())); - } - } - } - - void DrillerSAXParser::Data::Read(AZ::Vector3& v) const - { - AZ_Assert(m_dataSize == sizeof(float) * 3, "We are expecting 3 floats for Vector3 element 0x%08x with size %d bytes", m_name, m_dataSize); - float* data = reinterpret_cast(m_data); - if (m_isEndianSwap) - { - AZStd::endian_swap(data, data + 3); - m_isEndianSwap = false; - } - v = Vector3::CreateFromFloat3(data); - } - void DrillerSAXParser::Data::Read(AZ::Vector4& v) const - { - AZ_Assert(m_dataSize == sizeof(float) * 4, "We are expecting 4 floats for Vector4 element 0x%08x with size %d bytes", m_name, m_dataSize); - float* data = reinterpret_cast(m_data); - if (m_isEndianSwap) - { - AZStd::endian_swap(data, data + 4); - m_isEndianSwap = false; - } - v = Vector4::CreateFromFloat4(data); - } - void DrillerSAXParser::Data::Read(AZ::Aabb& aabb) const - { - AZ_Assert(m_dataSize == sizeof(float) * 6, "We are expecting 6 floats for Aabb element 0x%08x with size %d bytes", m_name, m_dataSize); - float* data = reinterpret_cast(m_data); - if (m_isEndianSwap) - { - AZStd::endian_swap(data, data + 6); - m_isEndianSwap = false; - } - Vector3 min = Vector3::CreateFromFloat3(data); - Vector3 max = Vector3::CreateFromFloat3(&data[3]); - aabb = Aabb::CreateFromMinMax(min, max); - } - void DrillerSAXParser::Data::Read(AZ::Obb& obb) const - { - AZ_Assert(m_dataSize == sizeof(float) * 10, "We are expecting 10 floats for Obb element 0x%08x with size %d bytes", m_name, m_dataSize); - float* data = reinterpret_cast(m_data); - if (m_isEndianSwap) - { - AZStd::endian_swap(data, data + 10); - m_isEndianSwap = false; - } - Vector3 position = Vector3::CreateFromFloat3(data); - Quaternion rotation = Quaternion::CreateFromFloat4(&data[3]); - Vector3 halfLengths = Vector3::CreateFromFloat3(&data[7]); - obb = Obb::CreateFromPositionRotationAndHalfLengths(position, rotation, halfLengths); - } - void DrillerSAXParser::Data::Read(AZ::Transform& tm) const - { - AZ_Assert(m_dataSize == sizeof(float) * 12, "We are expecting 12 floats for Transform element 0x%08x with size %d bytes", m_name, m_dataSize); - float* data = reinterpret_cast(m_data); - if (m_isEndianSwap) - { - AZStd::endian_swap(data, data + 12); - m_isEndianSwap = false; - } - const Matrix3x4 matrix3x4 = Matrix3x4::CreateFromRowMajorFloat12(data); - tm = Transform::CreateFromMatrix3x4(matrix3x4); - } - void DrillerSAXParser::Data::Read(AZ::Matrix3x3& tm) const - { - AZ_Assert(m_dataSize == sizeof(float) * 9, "We are expecting 9 floats for Matrix3x3 element 0x%08x with size %d bytes", m_name, m_dataSize); - float* data = reinterpret_cast(m_data); - if (m_isEndianSwap) - { - AZStd::endian_swap(data, data + 9); - m_isEndianSwap = false; - } - tm = Matrix3x3::CreateFromRowMajorFloat9(data); - } - void DrillerSAXParser::Data::Read(AZ::Matrix4x4& tm) const - { - AZ_Assert(m_dataSize == sizeof(float) * 16, "We are expecting 16 floats for Matrix4x4 element 0x%08x with size %d bytes", m_name, m_dataSize); - float* data = reinterpret_cast(m_data); - if (m_isEndianSwap) - { - AZStd::endian_swap(data, data + 16); - m_isEndianSwap = false; - } - tm = Matrix4x4::CreateFromRowMajorFloat16(data); - } - void DrillerSAXParser::Data::Read(AZ::Quaternion& tm) const - { - AZ_Assert(m_dataSize == sizeof(float) * 4, "We are expecting 4 floats for Quaternion element 0x%08x with size %d bytes", m_name, m_dataSize); - float* data = reinterpret_cast(m_data); - if (m_isEndianSwap) - { - AZStd::endian_swap(data, data + 4); - m_isEndianSwap = false; - } - tm = Quaternion::CreateFromFloat4(data); - } - void DrillerSAXParser::Data::Read(AZ::Plane& plane) const - { - AZ::Vector4 coeff; - Read(coeff); - plane = Plane::CreateFromCoefficients(coeff.GetX(), coeff.GetY(), coeff.GetZ(), coeff.GetW()); - } - - const char* DrillerSAXParser::Data::PrepareString(unsigned int& stringLength) const - { - const char* srcData = reinterpret_cast(m_data); - stringLength = m_dataSize; - if (m_stringPool) - { - AZ::u32 crc32; - const char* stringPtr; - if (m_isPooledStringCrc32) - { - crc32 = *reinterpret_cast(m_data); - if (m_isEndianSwap) - { - AZStd::endian_swap(crc32); - } - stringPtr = m_stringPool->Find(crc32); - AZ_Assert(stringPtr != nullptr, "Failed to find string with id 0x%08x in the string pool, proper stream read is impossible!", crc32); - stringLength = static_cast(strlen(stringPtr)); - } - else if (m_isPooledString) - { - stringPtr = srcData; // already stored in the pool just transfer the pointer - } - else - { - // Store copy of the string in the pool to save memory (keep only one reference of the string). - m_stringPool->InsertCopy(reinterpret_cast(srcData), stringLength, crc32, &stringPtr); - } - srcData = stringPtr; - } - else - { - AZ_Assert(m_isPooledString == false && m_isPooledStringCrc32 == false, "This stream requires using of a string pool as the string is send only once and afterwards only the Crc32 is used!"); - } - return srcData; - } - - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // DrillerDOMParser - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - - //========================================================================= - // Node::GetTag - // [1/23/2013] - //========================================================================= - const DrillerDOMParser::Node* DrillerDOMParser::Node::GetTag(u32 tagName) const - { - const Node* tagNode = nullptr; - for (Node::NodeListType::const_iterator i = m_tags.begin(); i != m_tags.end(); ++i) - { - if ((*i).m_name == tagName) - { - tagNode = &*i; - break; - } - } - return tagNode; - } - - //========================================================================= - // Node::GetData - // [3/23/2011] - //========================================================================= - const DrillerDOMParser::Data* DrillerDOMParser::Node::GetData(u32 dataName) const - { - const Data* dataNode = nullptr; - for (Node::DataListType::const_iterator i = m_data.begin(); i != m_data.end(); ++i) - { - if (i->m_name == dataName) - { - dataNode = &*i; - break; - } - } - return dataNode; - } - - //========================================================================= - // DrillerDOMParser - // [3/23/2011] - //========================================================================= - DrillerDOMParser::DrillerDOMParser(bool isPersistentInputData) - : DrillerSAXParser(TagCallbackType(this, &DrillerDOMParser::OnTag), DataCallbackType(this, &DrillerDOMParser::OnData)) - , m_isPersistentInputData(isPersistentInputData) - { - m_root.m_name = 0; - m_root.m_parent = nullptr; - m_topNode = &m_root; - } - static int g_numFree = 0; - //========================================================================= - // ~DrillerDOMParser - // [3/23/2011] - //========================================================================= - DrillerDOMParser::~DrillerDOMParser() - { - DeleteNode(m_root); - } - - //========================================================================= - // OnTag - // [3/23/2011] - //========================================================================= - void - DrillerDOMParser::OnTag(AZ::u32 name, bool isOpen) - { - if (isOpen) - { - m_topNode->m_tags.push_back(); - Node& node = m_topNode->m_tags.back(); - node.m_name = name; - node.m_parent = m_topNode; - - m_topNode = &node; - } - else - { - AZ_Assert(m_topNode->m_name == name, "We have opened tag with name 0x%08x and closing with name 0x%08x", m_topNode->m_name, name); - m_topNode = m_topNode->m_parent; - } - } - //========================================================================= - // OnData - // [3/23/2011] - //========================================================================= - void - DrillerDOMParser::OnData(const Data& data) - { - Data de = data; - if (!m_isPersistentInputData) - { - de.m_data = azmalloc(data.m_dataSize, 1, OSAllocator); - memcpy(const_cast(de.m_data), data.m_data, data.m_dataSize); - } - m_topNode->m_data.push_back(de); - } - //========================================================================= - // DeleteNode - // [3/23/2011] - //========================================================================= - void - DrillerDOMParser::DeleteNode(Node& node) - { - if (!m_isPersistentInputData) - { - for (Node::DataListType::iterator iter = node.m_data.begin(); iter != node.m_data.end(); ++iter) - { - azfree(iter->m_data, OSAllocator, iter->m_dataSize); - ++g_numFree; - } - node.m_data.clear(); - } - for (Node::NodeListType::iterator iter = node.m_tags.begin(); iter != node.m_tags.end(); ++iter) - { - DeleteNode(*iter); - } - node.m_tags.clear(); - } - - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // DrillerSAXParserHandler - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - - //========================================================================= - // DrillerSAXParserHandler - // [3/14/2013] - //========================================================================= - DrillerSAXParserHandler::DrillerSAXParserHandler(DrillerHandlerParser* rootHandler) - : DrillerSAXParser(TagCallbackType(this, &DrillerSAXParserHandler::OnTag), DataCallbackType(this, &DrillerSAXParserHandler::OnData)) - { - // Push the root element - m_stack.push_back(rootHandler); - } - - //========================================================================= - // OnTag - // [3/14/2013] - //========================================================================= - void DrillerSAXParserHandler::OnTag(u32 name, bool isOpen) - { - if (m_stack.empty()) - { - return; - } - - DrillerHandlerParser* childHandler = nullptr; - DrillerHandlerParser* currentHandler = m_stack.back(); - if (isOpen) - { - if (currentHandler != nullptr) - { - childHandler = currentHandler->OnEnterTag(name); - AZ_Warning("Driller", !currentHandler->IsWarnOnUnsupportedTags() || childHandler != nullptr, "Could not find handler for tag 0x%08x", name); - } - m_stack.push_back(childHandler); - } - else - { - m_stack.pop_back(); - if (!m_stack.empty()) - { - DrillerHandlerParser* parentHandler = m_stack.back(); - if (parentHandler) - { - parentHandler->OnExitTag(currentHandler, name); - } - } - } - } - - //========================================================================= - // OnData - // [3/14/2013] - //========================================================================= - void DrillerSAXParserHandler::OnData(const DrillerSAXParser::Data& data) - { - if (m_stack.empty()) - { - return; - } - - DrillerHandlerParser* currentHandler = m_stack.back(); - if (currentHandler) - { - currentHandler->OnData(data); - } - } -} // namespace AZ::Debug diff --git a/Code/Framework/AzCore/AzCore/Driller/Stream.h b/Code/Framework/AzCore/AzCore/Driller/Stream.h deleted file mode 100644 index 5efa416ef4..0000000000 --- a/Code/Framework/AzCore/AzCore/Driller/Stream.h +++ /dev/null @@ -1,848 +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 - * - */ -#ifndef AZCORE_DRILLER_STREAM_H -#define AZCORE_DRILLER_STREAM_H - -#include - -#include -#include -#include -#include -#include - -#include // for the Driller direct file stream -#include -#include - -namespace AZ -{ - class Vector3; - class Vector4; - class Aabb; - class Obb; - class Transform; - class Matrix3x3; - class Matrix4x4; - class Quaternion; - class Plane; - class ZLib; - - namespace IO - { - class Stream; - } - - namespace Debug - { - template - struct vector - { - typedef AZStd::vector type; - }; - - template - struct forward_list - { - typedef AZStd::forward_list type; - }; - - /** - * Interface for a string pool which can be used by input/output streams to avoid storing multiple copies of the same - * string in the stream. Of course this comes at the bookkeeping cost of the table. - */ - class DrillerStringPool - { - public: - virtual ~DrillerStringPool() {} - - /** - * Add a copy of the string to the pool. If we return true the string was added otherwise it was already in the bool. - * In both cases the crc32 of the string and the pointer to the shared copy is returned (optional for poolStringAddress)! - */ - virtual bool InsertCopy(const char* string, unsigned int length, AZ::u32& crc32, const char** poolStringAddress = NULL) = 0; - - /** - * Same as the InsertCopy above without actually coping the string into the pool. The pool assumes that - * none of the strings added to the pool will be deleted. - */ - virtual bool Insert(const char* string, unsigned int length, AZ::u32& crc32) = 0; - - /// Finds a string in the pool by crc32. - virtual const char* Find(AZ::u32 crc32) = 0; - - virtual void Erase(AZ::u32 crc32) = 0; - - /// Clears all the strings in the pool, make sure you don't reference any strings before you call that function. - virtual void Reset() = 0; - }; - - /** - * - */ - class DrillerOutputStream - { - protected: - friend class DrillerManagerImpl; - friend class DrillerSAXParser; - struct StreamEntry - { - enum InternalDataSize // max 8 values as we use 3 bit to store them - { - INT_SIZE = 0, ///< No internal data, we store the data size. IMPORTANT: INT_SIZE should be 0 the code makes assumptions based on that - INT_TAG, ///< True if this entry is tag - INT_DATA_U8, ///< Internal data u8 stored (1 byte) - INT_DATA_U16, ///< Internal data u16 stored (2 bytes) - INT_DATA_U29, ///< Internal data u32 stored (4 bytes) for which we use only the first 29 bits. - INT_POOLED_STRING_CRC32, ///< Data size should be 4 bytes crc32 that a string CRC and it require string pool. - INT_POOLED_STRING, ///< This data contains a string which should be inserted in the string pool. - }; - static const u32 dataSizeMask = 0x1fffffff; - static const u32 dataInternalMask = 0xE0000000; - static const u32 dataInternalShift = 29; - - u32 name; ///< data or tag name - u32 sizeAndFlags; ///< - }; - - template - struct IntergralType; - - template - struct IntergralType - { - static void Write(DrillerOutputStream& stream, u32 name, const T& data) - { - StreamEntry de; - de.name = name; - de.sizeAndFlags = (u32)(StreamEntry::INT_DATA_U8) << StreamEntry::dataInternalShift; - de.sizeAndFlags |= *reinterpret_cast(&data); - stream.WriteBinary(de); - } - }; - template - struct IntergralType - { - static void Write(DrillerOutputStream& stream, u32 name, const T& data) - { - StreamEntry de; - de.name = name; - de.sizeAndFlags = (u32)(StreamEntry::INT_DATA_U16) << StreamEntry::dataInternalShift; - de.sizeAndFlags |= *reinterpret_cast(&data); - stream.WriteBinary(de); - } - }; - template - struct IntergralType - { - static void Write(DrillerOutputStream& stream, u32 name, const T& data) - { - StreamEntry de; - de.name = name; - const u32* uintData = reinterpret_cast(&data); - if (((*uintData) & StreamEntry::dataSizeMask) == *uintData) // check if we can store it internally - { - de.sizeAndFlags = (u32)(StreamEntry::INT_DATA_U29) << StreamEntry::dataInternalShift; - de.sizeAndFlags |= *uintData; - stream.WriteBinary(de); - } - else - { - de.sizeAndFlags = 4; - stream.WriteBinary(de); - stream.WriteBinary(&data, de.sizeAndFlags); - } - } - }; - template - struct IntergralType - { - static void Write(DrillerOutputStream& stream, u32 name, const T& data) - { - StreamEntry de; - de.name = name; - const u64* uintData = reinterpret_cast(&data); - if (((*uintData) & static_cast(StreamEntry::dataSizeMask)) == *uintData) // check if we can store it internally - { - de.sizeAndFlags = (u32)(StreamEntry::INT_DATA_U29) << StreamEntry::dataInternalShift; - de.sizeAndFlags |= static_cast(*uintData); - stream.WriteBinary(de); - } - else - { - de.sizeAndFlags = 8; - stream.WriteBinary(de); - stream.WriteBinary(&data, de.sizeAndFlags); - } - } - }; - template - struct IntergralType - { - static void Write(DrillerOutputStream& stream, u32 name, const T* pointer) - { - size_t id = reinterpret_cast(pointer); - IntergralType::Write(stream, name, id); - } - }; - - public: - /** - * Each stream with start with this header, before anything else. - */ - struct StreamHeader - { - StreamHeader() - : platform((u8)g_currentPlatform) {} - u8 platform; - }; - - DrillerOutputStream(DrillerStringPool* stringPool = NULL) - : m_stringPool(stringPool) { } - virtual ~DrillerOutputStream() {} - - ////////////////////////////////////////////////////////////////////////// - // Write - inline void BeginTag(u32 name) - { - StreamEntry de; - de.name = name; - de.sizeAndFlags = (u32)(StreamEntry::INT_TAG) << StreamEntry::dataInternalShift; - de.sizeAndFlags |= 1; // true - open tag - WriteBinary(de); - } - inline void EndTag(u32 name) - { - StreamEntry de; - de.name = name; - de.sizeAndFlags = (u32)(StreamEntry::INT_TAG) << StreamEntry::dataInternalShift; - WriteBinary(de); - } - - ////////////////////////////////////////////////////////////////////////// - // Generic - template - inline void Write(u32 name, const T& data) - { - // User should handle non specialized non integral types. - IntergralType::value || AZStd::is_enum::value>::Write(*this, name, data); - } - - ////////////////////////////////////////////////////////////////////////// - // Binary and strings - inline void Write(u32 name, const void* data, unsigned int dataSize) - { - StreamEntry de; - de.name = name; - de.sizeAndFlags = dataSize; - WriteBinary(de); - WriteBinary(data, dataSize); - } - inline void Write(u32 name, const char* string, bool isCopyString = true) - { - StreamEntry de; - de.name = name; - de.sizeAndFlags = static_cast(strlen(string)); - AZ_Assert(de.sizeAndFlags <= StreamEntry::dataSizeMask, "Invalid string length! String is too long, length is limited to %u bytes!", StreamEntry::dataSizeMask); - ; - if (m_stringPool) - { - AZ::u32 crc; - bool isInserted = isCopyString ? m_stringPool->InsertCopy(string, de.sizeAndFlags, crc) : m_stringPool->Insert(string, de.sizeAndFlags, crc); - if (!isInserted) // if already inserted, it means it's in the stream, so store the crc only. - { - de.sizeAndFlags = (u32)(StreamEntry::INT_POOLED_STRING_CRC32) << StreamEntry::dataInternalShift; - de.sizeAndFlags |= sizeof(crc); - WriteBinary(de); - WriteBinary(&crc, sizeof(crc)); - } - else - { - AZ::u32 stringSize = de.sizeAndFlags; - de.sizeAndFlags |= (u32)(StreamEntry::INT_POOLED_STRING) << StreamEntry::dataInternalShift; - WriteBinary(de); - WriteBinary(string, stringSize); - } - } - else - { - WriteBinary(de); - WriteBinary(string, de.sizeAndFlags); - } - } - template - inline void Write(u32 name, const AZStd::basic_string& str, bool isCopyString = true) - { - StreamEntry de; - de.name = name; - de.sizeAndFlags = static_cast(str.size()); - AZ_Assert(de.sizeAndFlags <= StreamEntry::dataSizeMask, "Invalid string length! String is too long, length is limited to %u bytes!", StreamEntry::dataSizeMask); - if (m_stringPool) - { - AZ::u32 crc; - bool isInserted = isCopyString ? m_stringPool->InsertCopy(str.c_str(), de.sizeAndFlags, crc) : m_stringPool->Insert(str.c_str(), de.sizeAndFlags, crc); - if (!isInserted) // if already inserted, it means it's in the stream, so store the crc only. - { - de.sizeAndFlags = (u32)(StreamEntry::INT_POOLED_STRING_CRC32) << StreamEntry::dataInternalShift; - de.sizeAndFlags |= sizeof(crc); - WriteBinary(de); - WriteBinary(&crc, sizeof(crc)); - } - else - { - AZ::u32 stringSize = de.sizeAndFlags; - de.sizeAndFlags |= (u32)(StreamEntry::INT_POOLED_STRING) << StreamEntry::dataInternalShift; - WriteBinary(de); - WriteBinary(str.data(), stringSize); - } - } - else - { - WriteBinary(de); - WriteBinary(str.data(), de.sizeAndFlags); - } - } - - template - inline void Write(u32 name, const AZStd::basic_string& str) - { - StreamEntry de; - de.name = name; - de.sizeAndFlags = static_cast(str.size()); - AZ_Assert(de.sizeAndFlags <= StreamEntry::dataSizeMask, "Invalid string length! String is too long, length is limited to %u bytes!", StreamEntry::dataSizeMask); - WriteBinary(de); - WriteBinary(str.data(), de.sizeAndFlags * sizeof(AZStd::wstring::value_type)); - } - - ////////////////////////////////////////////////////////////////////////// - // math types - inline void Write(u32 name, float f) - { - Write(name, &f, static_cast(sizeof(float))); - } - inline void Write(u32 name, double d) - { - Write(name, &d, static_cast(sizeof(double))); - } - - void Write(u32 name, const AZ::Vector3& v); - void Write(u32 name, const AZ::Vector4& v); - void Write(u32 name, const AZ::Aabb& aabb); - void Write(u32 name, const AZ::Obb& obb); - void Write(u32 name, const AZ::Transform& tm); - void Write(u32 name, const AZ::Matrix3x3& tm); - void Write(u32 name, const AZ::Matrix4x4& tm); - void Write(u32 name, const AZ::Quaternion& tm); - void Write(u32 name, const AZ::Plane& plane); - - ////////////////////////////////////////////////////////////////////////// - // containers - template - inline void Write(u32 name, InputIterator first, InputIterator last) - { - // we can specialize for contiguous_iterator_tag so have only 1 write for all elements - size_t numElements = AZStd::distance(first, last); - size_t elementSize = sizeof(typename AZStd::iterator_traits::value_type); - unsigned int dataSize = static_cast(numElements * elementSize); - StreamEntry de; - de.name = name; - de.sizeAndFlags = dataSize; - AZ_Assert(dataSize < StreamEntry::dataSizeMask, "Invalid data size, size is limited to %d bytes!", StreamEntry::dataSizeMask - 1); - WriteBinary(de); - //WriteBinary(data,dataSize); for contiguous_iterator_tag - for (; first != last; ++first) - { - WriteBinary(&*first, static_cast(elementSize)); - } - } - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - // Raw data to the output - template - inline void WriteBinary(const T& data) - { - WriteBinary(&data, sizeof(T)); - } - - virtual void WriteBinary(const void* data, unsigned int dataSize) = 0; - ////////////////////////////////////////////////////////////////////////// - - /** - * Write a time stamp (AZStd::sys_time_t) in millisecond since 1970/01/01 00:00:00 UTC. - * On older windows this function can have ~15 ms resolution, in such cases use \ref GetTimeNowMicroSecond - */ - void WriteTimeUTC(u32 name); - - /** - * Write a time stamp (AZStd::sys_time_t) in micriseconds. This function is inaccurate for long periods but it has ms resolution. - * For long periods use \ref WriteTimeUTC. - */ - void WriteTimeMicrosecond(u32 name); - - /// Called when the driller is moving on the next frame, so you can flush you current buffer to network/disk. - virtual void OnEndOfFrame() {} - - /// Sets the string pool used for this stream. To disable the pool just set it to NULL. - void SetStringPool(DrillerStringPool* stringPool) { m_stringPool = stringPool; } - - protected: - /// Write the Stream header structure (should be endianess independent). - void WriteHeader(); - - DrillerStringPool* m_stringPool; ///< Optional pointer to a string pool. - }; - - /** - * For efficiency all data read functions are placed with the parsers. - */ - class DrillerInputStream - { - public: - DrillerInputStream(DrillerStringPool* stringPool = NULL) - : m_isEndianSwap(false) - , m_stringPool(stringPool) {} - virtual ~DrillerInputStream() {} - - bool IsEndianSwap() const { return m_isEndianSwap; } - /// Reads binary data from a stream to to maxDataSize. Returns 0 if no more data. - virtual unsigned int ReadBinary(void* data, unsigned int maxDataSize) = 0; - - /// Sets the string pool used for this stream. To disable the pool just set it to NULL. - void SetStringPool(DrillerStringPool* stringPool) { m_stringPool = stringPool; } - DrillerStringPool* GetStringPool() const { return m_stringPool; } - - void SetIdentifier(const char* identifier) { m_streamIdentifier = identifier; } - const char* GetIdentifier() const { return m_streamIdentifier.c_str(); } - - protected: - /// Read the Stream header structure - bool ReadHeader(); - - bool m_isEndianSwap; - DrillerStringPool* m_stringPool; ///< Optional pointer to a string pool. - AZStd::string m_streamIdentifier; - }; - - /** - * Outputs all stream data into a memory buffer. It will grow automatically. - */ - class DrillerOutputMemoryStream - : public DrillerOutputStream - { - protected: - vector::type m_data; - public: - AZ_CLASS_ALLOCATOR(DrillerOutputMemoryStream, OSAllocator, 0) - DrillerOutputMemoryStream(size_t memorySize = 2048) { m_data.reserve(memorySize); } - const unsigned char* GetData() const { return m_data.data(); } - unsigned int GetDataSize() const { return static_cast(m_data.size()); } - inline void Reset() { m_data.clear(); } - void WriteBinary(const void* data, unsigned int dataSize) override - { - m_data.insert(m_data.end(), reinterpret_cast(data), reinterpret_cast(data) + dataSize); - } - }; - /** - * Reads data from a memory stream. Data is NOT copied and must be persistent while we are using it. - */ - class DrillerInputMemoryStream - : public DrillerInputStream - { - const unsigned char* m_data; - const unsigned char* m_dataEnd; - - public: - AZ_CLASS_ALLOCATOR(DrillerInputMemoryStream, OSAllocator, 0) - DrillerInputMemoryStream(const char* streamIdentifier = "", const void* data = nullptr, unsigned int dataSize = 0) - : DrillerInputStream() - , m_data(nullptr) - , m_dataEnd(nullptr) - { - if (data != nullptr) - { - SetData(streamIdentifier, data, dataSize); - } - } - - void SetData(const char* streamIdentifier, const void* data, unsigned int dataSize) - { - SetIdentifier(streamIdentifier); - - AZ_Assert(data != nullptr && dataSize > 0, "We must have a valid pointer %p and data size %d !", data, dataSize); - if (m_data == nullptr) // this is the first data chuck, read the platform - { - m_data = reinterpret_cast(data); - m_dataEnd = m_data + dataSize; - ReadHeader(); - } - else - { - m_data = reinterpret_cast(data); - m_dataEnd = m_data + dataSize; - } - } - - unsigned int GetDataLeft() const { return static_cast(m_dataEnd - m_data); } - unsigned int ReadBinary(void* data, unsigned int maxDataSize) override - { - AZ_Assert(m_data != nullptr, "You must call SetData function, before you can read data!"); - AZ_Assert(data != nullptr && maxDataSize > 0, "We must have a valid pointer and max data size!"); - unsigned int dataToCopy = AZStd::GetMin(static_cast(m_dataEnd - m_data), maxDataSize); - if (dataToCopy) - { - memcpy(data, m_data, dataToCopy); - } - m_data += dataToCopy; - return dataToCopy; - } - }; - - /** - * Outputs driller data to a file (buffered) - * IMPORTANT: We provide direct IO classes (instead trough Streamer), because the driller - * framework should NOT use engine systems (for example imagine we are drilling the Streamer, using it to - * write the drilled data will invalidate all the results as the streamer is unaware which data is driller data and which not) - */ - class DrillerOutputFileStream - : public IO::SystemFile - , public DrillerOutputStream - { - ZLib* m_zlib; - vector::type m_compressionBuffer; - vector::type m_dataBuffer; - public: - AZ_CLASS_ALLOCATOR(DrillerOutputFileStream, OSAllocator, 0) - DrillerOutputFileStream(); - ~DrillerOutputFileStream(); - bool Open(const char* fileName, int mode, int platformFlags = 0); - void Close(); - - void WriteBinary(const void* data, unsigned int dataSize) override; - }; - - /** - * Reads driller data from a file. - */ - class DrillerInputFileStream - : public AZ::IO::SystemFile - , public DrillerInputStream - { - ZLib* m_zlib; - vector::type m_compressedData; - public: - AZ_CLASS_ALLOCATOR(DrillerInputFileStream, OSAllocator, 0) - DrillerInputFileStream(); - ~DrillerInputFileStream(); - bool Open(const char* fileName, int mode, int platformFlags = 0); - unsigned int ReadBinary(void* data, unsigned int maxDataSize) override; - void Close(); - }; - - /** - * SAX like stream parser for driller data. We can stream the data - * and we will trigger events as tags and data (attributes) arrive. We use less memory this way. - * \note SAX is used as reference name, we are NOT trying to compatible with - * any specs. (not that SAX has specs) - * IMPORTANT: All data callbacks (tag and data) are called in the order they were at store. You can - * use this order as event index. - */ - class DrillerSAXParser - { - public: - struct Data - { - u32 m_name; ///< Crc name of the data entry. - void* m_data; ///< Pointer to copy if the loaded data. - unsigned int m_dataSize; ///< Data size in bytes. - mutable bool m_isEndianSwap; ///< True if the user will need to swap the endian when he access the data. We swap the data is the storage so we can read it multiple times without swap. - DrillerStringPool* m_stringPool; ///< Pointer to optional data string pool. - bool m_isPooledString; ///< True if we have a pooled string (stored in the stringPool already). - bool m_isPooledStringCrc32; ///< True is we have stored a crc32 (4 bytes) which refers to a string from the String Pool. - - ////////////////////////////////////////////////////////////////////////// - // Generic - template - inline void Read(T& t) const - { - static_assert(AZStd::is_pod::value, "T must be plain-old-data"); - - AZ_Assert(sizeof(t) >= m_dataSize, "You are about to lose some data, this is wrong."); - if (m_dataSize == sizeof(t)) - { - // do a memcpy as alignment might be required for some data types! This is not performance critical as we usually load drill files on x86/x64 - // which doesn't care about alignment. - memcpy(&t, m_data, m_dataSize); - } - else - { - AZ_Assert(AZStd::is_pointer::value || AZStd::is_integral::value, "We support extending only for integral types, float and pointers up to 8 bytes!"); - - if (AZStd::is_signed::value) - { - switch (m_dataSize) - { - case 1: - t = static_cast(*reinterpret_cast(m_data)); - break; - case 2: - t = static_cast(*reinterpret_cast(m_data)); - break; - case 4: - t = static_cast(*reinterpret_cast(m_data)); - break; - default: - AZ_Assert(false, "Source data size unsupported... we can extend only 1,2,4 bytes into 2,4,8 bytes integrals"); - } - } - else - { - switch (m_dataSize) - { - case 1: - t = static_cast(*reinterpret_cast(m_data)); - break; - case 2: - t = static_cast(*reinterpret_cast(m_data)); - break; - case 4: - t = static_cast(*reinterpret_cast(m_data)); - break; - default: - AZ_Assert(false, "Source data size unsupported... we can extend only 1,2,4 bytes into 2,4,8 bytes integrals"); - } - } - } - if (m_isEndianSwap) - { - AZStd::endian_swap(t); - } - } - - inline void Read(bool& b) const - { - u8* data = reinterpret_cast(m_data); - b = false; - for (unsigned int i = 0; i < m_dataSize; ++i) - { - if (data[i] != 0) - { - b = true; - return; - } - } - } - ////////////////////////////////////////////////////////////////////////// - // Binary and strings - inline unsigned int Read(void* buffer, unsigned int bufferSize) const - { - unsigned int dataToCopy = AZStd::GetMin(m_dataSize, bufferSize); - memcpy(buffer, m_data, dataToCopy); - // no data swap - return dataToCopy; - } - // a call avilable only when we use a string pool, it will return the pointer of string in the pool, so you don't need to copy it or do any fancy procedures. - inline const char* ReadPooledString() const - { - AZ_Assert(m_stringPool != nullptr, "This read type is supported only when we use string pool!"); - unsigned int srcDataSize; - return PrepareString(srcDataSize); - } - inline unsigned int Read(char* string, unsigned int maxNumChars) const - { - unsigned int srcDataSize; - const char* srcData = PrepareString(srcDataSize); - unsigned int dataToCopy = AZStd::GetMin(maxNumChars - 1, srcDataSize); - memcpy(string, srcData, dataToCopy); - string[dataToCopy] = '\0'; - return dataToCopy; - } - template - inline unsigned int Read(AZStd::basic_string& str) const - { - unsigned int srcDataSize; - const char* srcData = PrepareString(srcDataSize); - str = AZStd::basic_string(static_cast(srcData), srcDataSize); - return m_dataSize; - } - template - inline unsigned int Read(AZStd::basic_string& str) const - { - // wstring pooling not supported yet - str = AZStd::basic_string(static_cast(m_data), m_dataSize / 2); - if (m_isEndianSwap) - { - AZStd::endian_swap(str.begin(), str.end()); - } - return m_dataSize; - } - - ////////////////////////////////////////////////////////////////////////// - // math types - void Read(AZ::Vector3& v) const; - void Read(AZ::Vector4& v) const; - void Read(AZ::Aabb& aabb) const; - void Read(AZ::Obb& obb) const; - void Read(AZ::Transform& tm) const; - void Read(AZ::Matrix3x3& tm) const; - void Read(AZ::Matrix4x4& tm) const; - void Read(AZ::Quaternion& tm) const; - void Read(AZ::Plane& plane) const; - - ////////////////////////////////////////////////////////////////////////// - // containers - template - inline void Read(AZStd::insert_iterator& iter) const - { - typedef typename AZStd::insert_iterator InsertIterator; - // we can specialize for contiguous_iterator_tag so have only 1 write for all elements - const size_t elementSize = sizeof(InsertIterator::container_type::value_type); - size_t numElements = m_dataSize / elementSize; - AZ_Assert(m_dataSize % elementSize == 0, "Stored elements size doesn't match the read parameters!"); - Data elementEntry = *this; - elementEntry.m_dataSize = elementSize; - char* dataPtr = reinterpret_cast(m_data); - for (size_t i = 0; i < numElements; ++i, ++iter) - { - typename InsertIterator::container_type::value_type value; - elementEntry.m_data = dataPtr; - Read(elementEntry, value); - iter = value; - dataPtr += elementSize; - } - } - ////////////////////////////////////////////////////////////////////////// - private: - const char* PrepareString(unsigned int& stringLength) const; - }; - - typedef AZStd::delegate TagCallbackType; - typedef AZStd::delegate DataCallbackType; - - AZ_CLASS_ALLOCATOR(DrillerSAXParser, OSAllocator, 0) - DrillerSAXParser(const TagCallbackType& tcb, const DataCallbackType& dcb); - /// Processes an input stream until all data is consumed (read returns 0 bytes). - void ProcessStream(DrillerInputStream& stream); - protected: - - typedef vector::type BufferType; - BufferType m_buffer; - TagCallbackType m_tagCallback; - DataCallbackType m_dataCallback; - }; - - /** - * DOM like parser, we will load the entire stream in memory (ProcessStream function). - * Depending on the data size this can be very memory consuming. - * \note DOM is used as reference we are NOT compliant with the DOM specs in any way. - * IMPORTANT: All data is stored (for parsing) in the same order the events occurred - * or the remote machine. Each next tad or data was recorded in the way. You can use - * this as an event index. - */ - class DrillerDOMParser - : public DrillerSAXParser - { - public: - struct Node - { - typedef forward_list::type DataListType; - typedef forward_list::type NodeListType; - - u32 m_name; - Node* m_parent; - DataListType m_data; - NodeListType m_tags; - - /// Return a pointer to the first tag with specific name. - const Node* GetTag(u32 tagName) const; - /// Returns pointer to the first data entry with specific name. NULL if not data has been found. - const Data* GetData(u32 dataName) const; - /// Returns pointer to the first data entry with specific name. If it can't be found it will assert - const Data* GetDataRequired(u32 dataName) const - { - const Data* dataNode = GetData(dataName); - AZ_Assert(dataNode != NULL, "Data node in tag 0x%08x with name 0x%08x is required but missing!", m_name, dataName); - return dataNode; - } - }; - - AZ_CLASS_ALLOCATOR(DrillerDOMParser, OSAllocator, 0) - - DrillerDOMParser(bool isPersistentInputData = false); - ~DrillerDOMParser(); - /// return true if we are at top level of the tree and we can parse the data safely (there may be still more data, but it's top level only). - bool CanParse() const { return m_topNode == &m_root; } - - const Node* GetRootNode() const { return &m_root; } - protected: - Node m_root; - Node* m_topNode; - bool m_isPersistentInputData; ///< true if data that we process is persistent so we don't need to copy it internally, false otherwise. - - void OnTag(u32 name, bool isOpen); - void OnData(const Data& data); - void DeleteNode(Node& node); - }; - - /** - * Base class for handling a Tag with a specific name. Handlers are kept in a hierarchy - * with one required by DrillerSAXParserHandler to be able to handle tags at a root - * level for the driller data stream. - */ - class DrillerHandlerParser - { - public: - DrillerHandlerParser(bool isWarnOnUnsupportedTags = true) - : m_isWarnOnUnsupportedTags(isWarnOnUnsupportedTags) {} - - virtual ~DrillerHandlerParser() {} - /// Enumerate all the child tags that we support for the tag we are handling. If the tag is not know you should return NULL - virtual DrillerHandlerParser* OnEnterTag(u32 tagName) { (void)tagName; return NULL; } - /// Exit tag you are not required to implement this, we always exist tags in order FILO. - virtual void OnExitTag(DrillerHandlerParser* handler, u32 tagName) { (void)handler; (void)tagName; } - /// Handle that data for the tag we are handling. - virtual void OnData(const DrillerSAXParser::Data& dataNode) { (void)dataNode; } - /// Return the warning state on unsupported tags (sometime you might want to warn usually) and sometimes not (if you load newer drills, etc.) - inline bool IsWarnOnUnsupportedTags() const { return m_isWarnOnUnsupportedTags; } - - protected: - bool m_isWarnOnUnsupportedTags; - }; - - /** - * Processes a driller driller and dispatches the data based on the - * the DrillerHandlerParser (handlers) and their ability to handle specific tags. - * If a tag is NOT found as a child of the current one it will display a warning with the tag name - * (useless it's allowed by DrillerHandlerParser::IsWarnOnUnsupportedTags) and process the stream - * is a safe manner by skipping all the data and tags we can't handle. - */ - class DrillerSAXParserHandler - : public DrillerSAXParser - { - public: - AZ_CLASS_ALLOCATOR(DrillerSAXParserHandler, OSAllocator, 0) - - DrillerSAXParserHandler(DrillerHandlerParser* rootHandler); - - protected: - - /// Called from DrillerSAXParser when we have an open tag. - void OnTag(u32 name, bool isOpen); - /// Called from DrillerSAXParser when we have data, which will be forwarded to the handler. - void OnData(const DrillerSAXParser::Data& data); - - typedef vector::type DrillerHandlerStackType; - DrillerHandlerStackType m_stack; - }; - } // namespace Debug -} // namespace AZ - -#endif // AZCORE_DRILLER_STREAM_H -#pragma once - - diff --git a/Code/Framework/AzCore/AzCore/Memory/AllocationRecords.cpp b/Code/Framework/AzCore/AzCore/Memory/AllocationRecords.cpp index bd541dc539..680d93501a 100644 --- a/Code/Framework/AzCore/AzCore/Memory/AllocationRecords.cpp +++ b/Code/Framework/AzCore/AzCore/Memory/AllocationRecords.cpp @@ -242,9 +242,8 @@ void AllocationRecords::UnregisterAllocation(void* address, size_t byteSize, siz { AZStd::scoped_lock lock(m_recordsMutex); Debug::AllocationRecordsType::iterator iter = m_records.find(address); - // We cannot assert if an allocation does not exist because our allocators start up way before the driller is started and the - // Allocator Records would be created. It is currently impossible to actually track all allocations that happen before a certain - // point + // We cannot assert if an allocation does not exist because allocations may have been made before tracking was enabled. + // It is currently impossible to actually track all allocations that happen before a certain point // AZ_Assert(iter!=m_records.end(), "Could not find address 0x%p in the allocator!", address); if (iter == m_records.end()) { diff --git a/Code/Framework/AzCore/AzCore/Memory/OSAllocator.h b/Code/Framework/AzCore/AzCore/Memory/OSAllocator.h index b327cf6349..3a8080483b 100644 --- a/Code/Framework/AzCore/AzCore/Memory/OSAllocator.h +++ b/Code/Framework/AzCore/AzCore/Memory/OSAllocator.h @@ -20,7 +20,7 @@ namespace AZ * OS allocator should be used for direct OS allocations (C heap) * It's memory usage is NOT tracked. If you don't create this allocator, it will be implicitly * created by the SystemAllocator when it is needed. In addition this allocator is used for - * debug data (like drillers, memory trackng, etc.) + * debug data (like memory tracking, etc.) */ class OSAllocator : public AllocatorBase diff --git a/Code/Framework/AzCore/AzCore/UnitTest/TestTypes.h b/Code/Framework/AzCore/AzCore/UnitTest/TestTypes.h index c1ada33446..afa6898944 100644 --- a/Code/Framework/AzCore/AzCore/UnitTest/TestTypes.h +++ b/Code/Framework/AzCore/AzCore/UnitTest/TestTypes.h @@ -13,7 +13,6 @@ #include #include -#include #include #if defined(HAVE_BENCHMARK) @@ -38,7 +37,6 @@ namespace UnitTest */ class AllocatorsBase { - AZ::Debug::DrillerManager* m_drillerManager; bool m_ownsAllocator{}; public: @@ -46,7 +44,6 @@ namespace UnitTest void SetupAllocator(const AZ::SystemAllocator::Descriptor& allocatorDesc = {}) { - m_drillerManager = AZ::Debug::DrillerManager::Create(); AZ::AllocatorManager::Instance().EnterProfilingMode(); AZ::AllocatorManager::Instance().SetDefaultTrackingMode(AZ::Debug::AllocationRecords::RECORD_FULL); @@ -67,7 +64,6 @@ namespace UnitTest AZ::AllocatorInstance::Destroy(); } m_ownsAllocator = false; - AZ::Debug::DrillerManager::Destroy(m_drillerManager); AZ::AllocatorManager::Instance().SetDefaultTrackingMode(AZ::Debug::AllocationRecords::RECORD_NO_RECORDS); AZ::AllocatorManager::Instance().ExitProfilingMode(); @@ -93,8 +89,7 @@ namespace UnitTest * Helper class to handle the boiler plate of setting up a test fixture that uses the system allocators * If you wish to do additional setup and tear down be sure to call the base class SetUp first and TearDown * last. - * By default memory tracking through driller is enabled. - * Defaults to a heap size of 15 MB + * By default memory tracking is enabled. */ class AllocatorsTestFixture @@ -123,8 +118,7 @@ namespace UnitTest * Helper class to handle the boiler plate of setting up a benchmark fixture that uses the system allocators * If you wish to do additional setup and tear down be sure to call the base class SetUp first and TearDown * last. - * By default memory tracking through driller is disabled. - * Defaults to a heap size of 15 MB + * By default memory tracking is enabled. */ class AllocatorsBenchmarkFixture : public ::benchmark::Fixture diff --git a/Code/Framework/AzCore/AzCore/azcore_files.cmake b/Code/Framework/AzCore/AzCore/azcore_files.cmake index 6659e814f3..08fc4c28af 100644 --- a/Code/Framework/AzCore/AzCore/azcore_files.cmake +++ b/Code/Framework/AzCore/AzCore/azcore_files.cmake @@ -107,11 +107,6 @@ set(FILES Debug/ProfilerReflection.cpp Debug/ProfilerReflection.h Debug/StackTracer.h - Debug/EventTrace.h - Debug/EventTrace.cpp - Debug/EventTraceDriller.h - Debug/EventTraceDriller.cpp - Debug/EventTraceDrillerBus.h Debug/Timer.h Debug/Trace.cpp Debug/Trace.h @@ -120,14 +115,6 @@ set(FILES Debug/TraceReflection.h DOM/DomVisitor.cpp DOM/DomVisitor.h - Driller/DefaultStringPool.h - Driller/Driller.cpp - Driller/Driller.h - Driller/DrillerBus.cpp - Driller/DrillerBus.h - Driller/DrillerRootHandler.h - Driller/Stream.cpp - Driller/Stream.h EBus/BusImpl.h EBus/EBus.h EBus/EBusEnvironment.cpp diff --git a/Code/Framework/AzCore/Tests/AZStd/Parallel.cpp b/Code/Framework/AzCore/Tests/AZStd/Parallel.cpp index 9c59cd450e..362560c7be 100644 --- a/Code/Framework/AzCore/Tests/AZStd/Parallel.cpp +++ b/Code/Framework/AzCore/Tests/AZStd/Parallel.cpp @@ -1392,7 +1392,7 @@ namespace UnitTest EXPECT_TRUE(done); } - // Fixture for thread-driller-bus related calls + // Fixture for thread-event-bus related calls // exists only to categorize the tests. class ThreadEventsBus : public AllocatorsFixture diff --git a/Code/Framework/AzCore/Tests/AZStd/TypeTraits.cpp b/Code/Framework/AzCore/Tests/AZStd/TypeTraits.cpp index da3aae1387..aeba048d69 100644 --- a/Code/Framework/AzCore/Tests/AZStd/TypeTraits.cpp +++ b/Code/Framework/AzCore/Tests/AZStd/TypeTraits.cpp @@ -8,6 +8,7 @@ #include "UserTypes.h" #include +#include #include #include #include diff --git a/Code/Framework/AzCore/Tests/EBus.cpp b/Code/Framework/AzCore/Tests/EBus.cpp index 9acf0f8a05..470a95435b 100644 --- a/Code/Framework/AzCore/Tests/EBus.cpp +++ b/Code/Framework/AzCore/Tests/EBus.cpp @@ -2500,7 +2500,7 @@ namespace UnitTest namespace RoutingTest { - class DrillerInterceptor : public EBusVersion1::Router + class EBusInterceptor : public EBusVersion1::Router { public: void OnEvent(int a) override @@ -2555,20 +2555,20 @@ namespace UnitTest TEST_F(EBus, Routing) { using namespace RoutingTest; - DrillerInterceptor driller; + EBusInterceptor interceptor; EBusVersion1Handler v1Handler; v1Handler.BusConnect(); - driller.BusRouterConnect(); + interceptor.BusRouterConnect(); EBusVersion1::Broadcast(&EBusVersion1::Events::OnEvent, 1020); - EXPECT_EQ(1, driller.m_numOnEvent); + EXPECT_EQ(1, interceptor.m_numOnEvent); EXPECT_EQ(1, v1Handler.m_numOnEvent); - driller.BusRouterDisconnect(); + interceptor.BusRouterDisconnect(); EBusVersion1::Broadcast(&EBusVersion1::Events::OnEvent, 1020); - EXPECT_EQ(1, driller.m_numOnEvent); + EXPECT_EQ(1, interceptor.m_numOnEvent); EXPECT_EQ(2, v1Handler.m_numOnEvent); // routing events diff --git a/Code/Framework/AzCore/Tests/Memory.cpp b/Code/Framework/AzCore/Tests/Memory.cpp index e442d62c7d..5287167c8b 100644 --- a/Code/Framework/AzCore/Tests/Memory.cpp +++ b/Code/Framework/AzCore/Tests/Memory.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -43,17 +42,13 @@ namespace UnitTest void SetUp() override { AZ::AllocatorManager::Instance().SetDefaultTrackingMode(AZ::Debug::AllocationRecords::RECORD_FULL); - m_drillerManager = Debug::DrillerManager::Create(); AZ::AllocatorManager::Instance().EnterProfilingMode(); } void TearDown() override { - Debug::DrillerManager::Destroy(m_drillerManager); AZ::AllocatorManager::Instance().ExitProfilingMode(); AZ::AllocatorManager::Instance().SetDefaultTrackingMode(AZ::Debug::AllocationRecords::RECORD_NO_RECORDS); } - protected: - Debug::DrillerManager* m_drillerManager = nullptr; }; class SystemAllocatorTest diff --git a/Code/Framework/AzCore/Tests/Memory/LeakDetection.cpp b/Code/Framework/AzCore/Tests/Memory/LeakDetection.cpp index 0748d5a1aa..dcfc931141 100644 --- a/Code/Framework/AzCore/Tests/Memory/LeakDetection.cpp +++ b/Code/Framework/AzCore/Tests/Memory/LeakDetection.cpp @@ -270,7 +270,6 @@ namespace UnitTest void SetUp() override { - m_drillerManager = AZ::Debug::DrillerManager::Create(); AZ::AllocatorManager::Instance().EnterProfilingMode(); AZ::AllocatorManager::Instance().SetDefaultTrackingMode(AZ::Debug::AllocationRecords::RECORD_FULL); @@ -292,7 +291,6 @@ namespace UnitTest // Other allocators need the SystemAllocator in order to work AZ::AllocatorInstance::Destroy(); } - AZ::Debug::DrillerManager::Destroy(m_drillerManager); AZ::AllocatorManager::Instance().ExitProfilingMode(); m_busRedirector.BusDisconnect(); @@ -353,7 +351,6 @@ namespace UnitTest }; BusRedirector m_busRedirector; - AZ::Debug::DrillerManager* m_drillerManager = nullptr; bool m_leakDetected = false; bool m_leakExpected = false; }; diff --git a/Code/Framework/AzCore/Tests/Rtti.cpp b/Code/Framework/AzCore/Tests/Rtti.cpp index 935df848c2..85089b0602 100644 --- a/Code/Framework/AzCore/Tests/Rtti.cpp +++ b/Code/Framework/AzCore/Tests/Rtti.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/Code/Framework/AzCore/Tests/Serialization/Json/BasicContainerSerializerTests.cpp b/Code/Framework/AzCore/Tests/Serialization/Json/BasicContainerSerializerTests.cpp index 4a6a8e9e8a..17a4cfbc7f 100644 --- a/Code/Framework/AzCore/Tests/Serialization/Json/BasicContainerSerializerTests.cpp +++ b/Code/Framework/AzCore/Tests/Serialization/Json/BasicContainerSerializerTests.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include