Files
o3de/Gems/ScriptCanvas/Code/Include/ScriptCanvas/PerformanceTracker.h
T
Steve Pham 38261d0800 Shorten copyright headers by splitting into 2 lines (#2213)
* Updated all copyright headers to split the longer original copyright line into 2 shorter lines

Signed-off-by: Steve Pham <spham@amazon.com>
2021-07-16 15:25:48 -07:00

94 lines
3.2 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <ScriptCanvas/Execution/ExecutionBus.h>
#include <ScriptCanvas/Execution/ExecutionPerformanceTimer.h>
namespace ScriptCanvas
{
namespace Execution
{
class PerformanceTimer;
class PerformanceTracker
{
friend class PerformanceScopeExecution;
friend class PerformanceScopeInitialization;
friend class PerformanceScopeLatent;
public:
AZ_TYPE_INFO(PerformanceTracker, "{D40DFC8B-D4EA-4D6A-A0CA-3FDD00604553}");
AZ_CLASS_ALLOCATOR(PerformanceTracker, AZ::SystemAllocator, 0);
PerformanceTracker();
~PerformanceTracker();
void CalculateReports();
void ClearGlobalReport();
void ClearSnapshotReport();
void FinalizeReport(PerformanceKey key, const AZ::Data::AssetId& assetId);
PerformanceTrackingReport GetGlobalReport() const;
PerformanceTrackingReport GetGlobalReportByAsset(const AZ::Data::AssetId& assetId) const;
// Not thread safe
const PerformanceReport& GetGlobalReportFull() const;
PerformanceTrackingReport GetSnapshotReport() const;
PerformanceTrackingReport GetSnapshotReportByAsset(const AZ::Data::AssetId& assetId) const;
// Not thread safe
const PerformanceReport& GetSnapshotReportFull() const;
private:
static PerformanceTrackingReport* ModOrCreateReport(PerformanceReportByAsset& reports, AZ::Data::AssetId key);
static PerformanceTrackingReport GetReportByAsset(const PerformanceReportByAsset& report, AZ::Data::AssetId key);
PerformanceReport m_lastCapturedSnapshot;
PerformanceReport m_lastCapturedGlobal;
PerformanceReport m_snapshotReport;
PerformanceReport m_globalReport;
AZStd::recursive_mutex m_activeTimerMutex;
AZStd::unordered_map<PerformanceKey, PerformanceTimer*> m_activeTimers;
struct AssetTimer
{
AZ_TYPE_INFO(AssetTimer, "{80860A85-C6B7-4544-8C30-62C76C657427}");
AZ_CLASS_ALLOCATOR(AssetTimer, AZ::SystemAllocator, 0);
PerformanceTimer timer;
AZ::u32 assetActivationCount = 0;
};
AZStd::unordered_map<AZ::Data::AssetId, AssetTimer*> m_timersByAsset;
PerformanceTimer* CreateTimer(PerformanceKey key);
AssetTimer* GetOrCreateTimer(const AZ::Data::AssetId& key);
PerformanceTimer* GetOrCreateTimer(PerformanceKey key);
void ReportExecutionTime(PerformanceKey key, const AZ::Data::AssetId& assetId, AZStd::sys_time_t);
void ReportLatentTime(PerformanceKey key, const AZ::Data::AssetId& assetId, AZStd::sys_time_t);
void ReportInitializationTime(PerformanceKey key, const AZ::Data::AssetId& assetId, AZStd::sys_time_t);
};
}
}