[development] Android trace support (#7021)

- Abstracted the platform specific low level profiler API
- Added support for ATrace markers on Android
- Stubbed iOS, Linux, and macOS with unimplemented versions of the low level platform profiler API

Signed-off-by: AMZN-ScottR 24445312+AMZN-ScottR@users.noreply.github.com
This commit is contained in:
Scott Romero
2022-01-25 07:59:53 -08:00
committed by GitHub
parent 95c0186d1b
commit f3e6e57cc4
15 changed files with 175 additions and 32 deletions
@@ -10,11 +10,6 @@
#include <AzCore/Debug/Budget.h>
#include <AzCore/Statistics/StatisticalProfilerProxy.h>
#ifdef USE_PIX
#include <AzCore/PlatformIncl.h>
#include <WinPixEventRuntime/pix3.h>
#endif
#if defined(AZ_PROFILER_MACRO_DISABLE) // by default we never disable the profiler registers as their overhead should be minimal, you can
// still do that for your code though.
#define AZ_PROFILE_SCOPE(...)
+31 -25
View File
@@ -10,44 +10,48 @@
namespace AZ::Debug
{
namespace Platform
{
template<typename... T>
void BeginProfileRegion(Budget* budget, const char* eventName, T const&... args);
void BeginProfileRegion(Budget* budget, const char* eventName);
void EndProfileRegion(Budget* budget);
} // namespace Platform
template<typename... T>
void ProfileScope::BeginRegion(
[[maybe_unused]] Budget* budget, [[maybe_unused]] const char* eventName, [[maybe_unused]] T const&... args)
{
if (!budget)
#if !defined(_RELEASE)
if (budget)
{
return;
}
#if !defined(_RELEASE)
// TODO: Verification that the supplied system name corresponds to a known budget
#if defined(USE_PIX)
PIXBeginEvent(PIX_COLOR_INDEX(budget->Crc() & 0xff), eventName, args...);
#endif
budget->BeginProfileRegion();
Platform::BeginProfileRegion(budget, eventName, args...);
if (auto profiler = AZ::Interface<Profiler>::Get(); profiler)
{
profiler->BeginRegion(budget, eventName);
budget->BeginProfileRegion();
if (auto profiler = AZ::Interface<Profiler>::Get(); profiler)
{
profiler->BeginRegion(budget, eventName);
}
}
#endif
#endif // #if !defined(_RELEASE)
}
inline void ProfileScope::EndRegion([[maybe_unused]] Budget* budget)
{
if (!budget)
#if !defined(_RELEASE)
if (budget)
{
return;
budget->EndProfileRegion();
if (auto profiler = AZ::Interface<Profiler>::Get(); profiler)
{
profiler->EndRegion(budget);
}
Platform::EndProfileRegion(budget);
}
#if !defined(_RELEASE)
budget->EndProfileRegion();
#if defined(USE_PIX)
PIXEndEvent();
#endif
if (auto profiler = AZ::Interface<Profiler>::Get(); profiler)
{
profiler->EndRegion(budget);
}
#endif
#endif // !defined(_RELEASE)
}
template<typename... T>
@@ -63,3 +67,5 @@ namespace AZ::Debug
}
} // namespace AZ::Debug
#include <AzCore/Debug/Profiler_Platform.inl>
@@ -0,0 +1,37 @@
/*
* 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 <AzCore/std/string/fixed_string.h>
#include <android/trace.h>
namespace AZ::Debug::Platform
{
template<typename... T>
void BeginProfileRegion([[maybe_unused]] Budget* budget, const char* eventName, T const&... args)
{
// ideally this would be smaller but AZ_PROFILE_FUNCTION produces some long event names
using EventNameString = AZStd::fixed_string<512>;
AZ_PUSH_DISABLE_WARNING(, "-Wformat-security")
EventNameString fullEventName = EventNameString::format(eventName, args...);
AZ_POP_DISABLE_WARNING
ATrace_beginSection(fullEventName.c_str());
}
inline void BeginProfileRegion([[maybe_unused]] Budget* budget, const char* eventName)
{
ATrace_beginSection(eventName);
}
inline void EndProfileRegion([[maybe_unused]] Budget* budget)
{
ATrace_endSection();
}
} // namespace AZ::Debug::Platform
@@ -5,6 +5,5 @@
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <../Common/Default/AzCore/IO/Streamer/StreamerContext_Default.h>
#include <AzCore/Debug/Profiler_Android.inl>
@@ -81,6 +81,8 @@ set(FILES
../../AzCore/Android/JNI/Internal/JStringUtils_impl.h
../../AzCore/Android/JNI/Internal/Object_impl.h
../../AzCore/Android/JNI/Internal/Signature_impl.h
AzCore/Debug/Profiler_Platform.inl
AzCore/Debug/Profiler_Android.inl
)
if (LY_TEST_PROJECT)
ly_add_source_properties(
@@ -0,0 +1,23 @@
/*
* 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
*
*/
namespace AZ::Debug::Platform
{
template<typename... T>
void BeginProfileRegion([[maybe_unused]] Budget* budget, [[maybe_unused]] const char* eventName, [[maybe_unused]] T const&... args)
{
}
inline void BeginProfileRegion([[maybe_unused]] Budget* budget, [[maybe_unused]] const char* eventName)
{
}
inline void EndProfileRegion([[maybe_unused]] Budget* budget)
{
}
} // namespace AZ::Debug::Platform
@@ -0,0 +1,37 @@
/*
* 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
*
*/
#ifdef USE_PIX
#include <AzCore/PlatformIncl.h>
#include <WinPixEventRuntime/pix3.h>
#endif
namespace AZ::Debug::Platform
{
template<typename... T>
void BeginProfileRegion([[maybe_unused]] Budget* budget, [[maybe_unused]] const char* eventName, [[maybe_unused]] T const&... args)
{
#ifdef USE_PIX
PIXBeginEvent(PIX_COLOR_INDEX(budget->Crc() & 0xff), eventName, args...);
#endif
}
inline void BeginProfileRegion([[maybe_unused]] Budget* budget, [[maybe_unused]] const char* eventName)
{
#ifdef USE_PIX
PIXBeginEvent(PIX_COLOR_INDEX(budget->Crc() & 0xff), eventName);
#endif
}
inline void EndProfileRegion([[maybe_unused]] Budget* budget)
{
#ifdef USE_PIX
PIXEndEvent();
#endif
}
} // namespace AZ::Debug::Platform
@@ -0,0 +1,9 @@
/*
* 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 <../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl>
@@ -66,4 +66,6 @@ set(FILES
../Common/UnixLike/AzCore/std/time_UnixLike.cpp
AzCore/Utils/Utils_Linux.cpp
../Common/UnixLike/AzCore/Utils/Utils_UnixLike.cpp
AzCore/Debug/Profiler_Platform.inl
../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl
)
@@ -0,0 +1,9 @@
/*
* 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 <../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl>
@@ -69,4 +69,6 @@ set(FILES
AzCore/Utils/Utils_Mac.cpp
../Common/Apple/AzCore/Utils/Utils_Apple.cpp
../Common/UnixLike/AzCore/Utils/Utils_UnixLike.cpp
AzCore/Debug/Profiler_Platform.inl
../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl
)
@@ -0,0 +1,9 @@
/*
* 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 <../Common/WinAPI/AzCore/Debug/Profiler_WinAPI.inl>
@@ -72,4 +72,6 @@ set(FILES
AzCore/std/time_Windows.cpp
../Common/WinAPI/AzCore/Utils/Utils_WinAPI.cpp
AzCore/Utils/Utils_Windows.cpp
AzCore/Debug/Profiler_Platform.inl
../Common/WinAPI/AzCore/Debug/Profiler_WinAPI.inl
)
@@ -0,0 +1,9 @@
/*
* 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 <../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl>
@@ -67,4 +67,6 @@ set(FILES
AzCore/Utils/Utils_iOS.mm
../Common/Apple/AzCore/Utils/Utils_Apple.cpp
../Common/UnixLike/AzCore/Utils/Utils_UnixLike.cpp
AzCore/Debug/Profiler_Platform.inl
../Common/Unimplemented/AzCore/Debug/Profiler_Unimplemented.inl
)