Files
UnrealEngineUWP/Engine/Source/Developer/TraceServices/Private/Model/MemoryPrivate.h
brandon dawson 3ef2a1629c Fix memory corruption when a cached TagDesc's memory is moved.
#preflight 611d0a9d008be90001a8d8ff


#ROBOMERGE-SOURCE: CL 17214075
#ROBOMERGE-BOT: (v855-17104924)

[CL 17214138 by brandon dawson in ue5-main branch]
2021-08-18 09:45:46 -04:00

79 lines
2.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "TraceServices/AnalysisService.h"
#include "TraceServices/Model/Memory.h"
#include "Common/PagedArray.h"
namespace TraceServices
{
class FMemoryProvider : public IMemoryProvider
{
public:
explicit FMemoryProvider(IAnalysisSession& Session);
virtual ~FMemoryProvider() {}
void AddEventSpec(FMemoryTagId Tag, const TCHAR* Name, FMemoryTagId ParentTag);
void AddTrackerSpec(FMemoryTrackerId TrackerId, const TCHAR* Name);
void AddTagSnapshot(FMemoryTrackerId TrackerId, double Time, const int64* Tags, const FMemoryTagSample* Values, uint32 TagCount);
virtual uint32 GetTagSerial() const override;
virtual uint32 GetTagCount() const override;
virtual void EnumerateTags(TFunctionRef<void(const FMemoryTagInfo&)> Callback) const override;
virtual const FMemoryTagInfo* GetTag(FMemoryTagId Id) const override;
virtual uint32 GetTrackerCount() const override;
virtual void EnumerateTrackers(TFunctionRef<void(const FMemoryTrackerInfo&)> Callback) const override;
virtual uint64 GetTagSampleCount(FMemoryTrackerId Tracker, FMemoryTagId Tag) const override;
virtual void EnumerateTagSamples(
FMemoryTrackerId Tracker,
FMemoryTagId Tag,
double StartTime,
double EnddTime,
bool bIncludeRangeNeighbours,
TFunctionRef<void(double Time, double Duration, const FMemoryTagSample&)> Callback) const override;
public:
static FName ProviderName;
private:
enum {
DefaultPageSize = 65536,
};
struct FTagSampleData
{
// Sample values.
TPagedArray<FMemoryTagSample> Values;
// Cached pointer to the actual memory tag.
FMemoryTagInfo* TagPtr;
FTagSampleData(ILinearAllocator& Allocator) : Values(Allocator, DefaultPageSize), TagPtr(nullptr) {}
FTagSampleData(const FTagSampleData& Other) : Values(Other.Values), TagPtr(Other.TagPtr) {}
};
struct FTrackerData
{
// Timestamps for samples
TArray<double> SampleTimes;
// Samples for each tag
TMap<FMemoryTagId, FTagSampleData> Samples;
FTrackerData() {}
private:
FTrackerData(const FTrackerData&) = delete;
};
IAnalysisSession& Session;
TMap<FMemoryTagId, FMemoryTagInfo*> TagDescs;
TPagedArray<FMemoryTagInfo> TagDescsPool;
TMap<FMemoryTrackerId, FMemoryTrackerInfo> TrackerDescs;
TArray<FTrackerData> Trackers;
uint32 TagsSerial;
};
} // namespace TraceServices