Add memory usage query for various asset types
This commit is contained in:
@@ -86,6 +86,11 @@ public:
|
||||
{
|
||||
return Position.GetKeyframes().Count() + Rotation.GetKeyframes().Count() + Scale.GetKeyframes().Count();
|
||||
}
|
||||
|
||||
uint64 GetMemoryUsage() const
|
||||
{
|
||||
return NodeName.Length() * sizeof(Char) + Position.GetMemoryUsage() + Rotation.GetMemoryUsage() + Scale.GetMemoryUsage();
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -131,6 +136,14 @@ public:
|
||||
return static_cast<float>(Duration / FramesPerSecond);
|
||||
}
|
||||
|
||||
uint64 GetMemoryUsage() const
|
||||
{
|
||||
uint64 result = RootNodeName.Length() * sizeof(Char) + Channels.Capacity() * sizeof(NodeAnimationData);
|
||||
for (const auto& e : Channels)
|
||||
result += e.GetMemoryUsage();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total amount of keyframes in the all animation channels.
|
||||
/// </summary>
|
||||
|
||||
@@ -733,6 +733,11 @@ public:
|
||||
_keyframes[i].Time = _keyframes[i].Time * timeScale + timeOffset;;
|
||||
}
|
||||
|
||||
uint64 GetMemoryUsage() const
|
||||
{
|
||||
return _keyframes.Capacity() * sizeof(KeyFrame);
|
||||
}
|
||||
|
||||
public:
|
||||
FORCE_INLINE KeyFrame& operator[](int32 index)
|
||||
{
|
||||
|
||||
@@ -569,6 +569,23 @@ void Animation::OnSkinnedModelUnloaded(Asset* obj)
|
||||
MappingCache.Remove(i);
|
||||
}
|
||||
|
||||
uint64 Animation::GetMemoryUsage() const
|
||||
{
|
||||
Locker.Lock();
|
||||
uint64 result = BinaryAsset::GetMemoryUsage();
|
||||
result += sizeof(Animation) - sizeof(BinaryAsset);
|
||||
result += Data.GetMemoryUsage();
|
||||
result += Events.Capacity() * sizeof(Pair<String, StepCurve<AnimEventData>>);
|
||||
for (const auto& e : Events)
|
||||
result += e.First.Length() * sizeof(Char) + e.Second.GetMemoryUsage();
|
||||
result += NestedAnims.Capacity() * sizeof(Pair<String, NestedAnimData>);
|
||||
result += MappingCache.Capacity() * sizeof(Pair<String, StepCurve<AnimEventData>>);
|
||||
for (const auto& e : MappingCache)
|
||||
result += e.Value.Capacity() * sizeof(int32);
|
||||
Locker.Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
void Animation::OnScriptingDispose()
|
||||
{
|
||||
// Dispose any events to prevent crashes (scripting is released before content)
|
||||
|
||||
@@ -152,7 +152,6 @@ public:
|
||||
const NodeToChannel* GetMapping(SkinnedModel* obj);
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
/// <summary>
|
||||
/// Gets the animation as serialized timeline data. Used to show it in Editor.
|
||||
/// </summary>
|
||||
@@ -173,7 +172,6 @@ public:
|
||||
/// <remarks>The cannot be used by virtual assets.</remarks>
|
||||
/// <returns><c>true</c> failed to save data; otherwise, <c>false</c>.</returns>
|
||||
bool Save(const StringView& path = StringView::Empty);
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
@@ -181,6 +179,7 @@ private:
|
||||
|
||||
public:
|
||||
// [BinaryAsset]
|
||||
uint64 GetMemoryUsage() const override;
|
||||
void OnScriptingDispose() override;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -64,6 +64,16 @@ bool RawDataAsset::Save(const StringView& path)
|
||||
|
||||
#endif
|
||||
|
||||
uint64 RawDataAsset::GetMemoryUsage() const
|
||||
{
|
||||
Locker.Lock();
|
||||
uint64 result = BinaryAsset::GetMemoryUsage();
|
||||
result += sizeof(RawDataAsset) - sizeof(BinaryAsset);
|
||||
result += Data.Count();
|
||||
Locker.Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
Asset::LoadResult RawDataAsset::load()
|
||||
{
|
||||
auto chunk0 = GetChunk(0);
|
||||
|
||||
@@ -28,6 +28,10 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
public:
|
||||
// [BinaryAsset]
|
||||
uint64 GetMemoryUsage() const override;
|
||||
|
||||
protected:
|
||||
// [BinaryAsset]
|
||||
LoadResult load() override;
|
||||
|
||||
@@ -452,6 +452,22 @@ const String& BinaryAsset::GetPath() const
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64 BinaryAsset::GetMemoryUsage() const
|
||||
{
|
||||
Locker.Lock();
|
||||
uint64 result = Asset::GetMemoryUsage();
|
||||
result += sizeof(BinaryAsset) - sizeof(Asset);
|
||||
result += _dependantAssets.Capacity() * sizeof(BinaryAsset*);
|
||||
for (int32 i = 0; i < ASSET_FILE_DATA_CHUNKS; i++)
|
||||
{
|
||||
auto chunk = _header.Chunks[i];
|
||||
if (chunk != nullptr && chunk->IsLoaded())
|
||||
result += chunk->Size();
|
||||
}
|
||||
Locker.Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper task used to initialize binary asset and upgrade it if need to in background.
|
||||
/// </summary>
|
||||
|
||||
@@ -41,7 +41,6 @@ public:
|
||||
FlaxStorage* Storage;
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
/// <summary>
|
||||
/// The asset metadata information. Stored in a Json format.
|
||||
/// </summary>
|
||||
@@ -51,14 +50,12 @@ public:
|
||||
/// Asset dependencies list used by the asset for tracking (eg. material functions used by material asset). The pair of asset ID and cached file edit time (for tracking modification).
|
||||
/// </summary>
|
||||
Array<Pair<Guid, DateTime>> Dependencies;
|
||||
|
||||
#endif
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Gets the asset serialized version.
|
||||
/// </summary>
|
||||
/// <returns>Version number.</returns>
|
||||
virtual uint32 GetSerializedVersion() const = 0;
|
||||
|
||||
/// <summary>
|
||||
@@ -84,14 +81,11 @@ public:
|
||||
|
||||
public:
|
||||
#if USE_EDITOR
|
||||
|
||||
#if COMPILE_WITH_ASSETS_IMPORTER
|
||||
|
||||
/// <summary>
|
||||
/// Reimports asset from the source file.
|
||||
/// </summary>
|
||||
API_FUNCTION() void Reimport() const;
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
@@ -130,7 +124,6 @@ protected:
|
||||
virtual void OnDependencyModified(BinaryAsset* asset)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
protected:
|
||||
@@ -255,7 +248,6 @@ public:
|
||||
bool LoadChunks(AssetChunksFlag chunks);
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
/// <summary>
|
||||
/// Saves this asset to the storage container.
|
||||
/// </summary>
|
||||
@@ -281,7 +273,6 @@ public:
|
||||
/// <param name="silentMode">In silent mode don't reload opened storage container that is using target file.</param>
|
||||
/// <returns>True if failed, otherwise false.</returns>
|
||||
static bool SaveToAsset(const StringView& path, AssetInitData& data, bool silentMode = false);
|
||||
|
||||
#endif
|
||||
|
||||
protected:
|
||||
@@ -302,6 +293,7 @@ public:
|
||||
void OnDeleteObject() override;
|
||||
#endif
|
||||
const String& GetPath() const final override;
|
||||
uint64 GetMemoryUsage() const override;
|
||||
|
||||
protected:
|
||||
// [Asset]
|
||||
|
||||
@@ -93,6 +93,17 @@ const String& JsonAssetBase::GetPath() const
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64 JsonAssetBase::GetMemoryUsage() const
|
||||
{
|
||||
Locker.Lock();
|
||||
uint64 result = Asset::GetMemoryUsage();
|
||||
result += sizeof(JsonAssetBase) - sizeof(Asset);
|
||||
if (Data)
|
||||
result += Document.GetAllocator().Capacity();
|
||||
Locker.Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
void FindIds(ISerializable::DeserializeStream& node, Array<Guid>& output)
|
||||
@@ -248,6 +259,17 @@ JsonAsset::JsonAsset(const SpawnParams& params, const AssetInfo* info)
|
||||
{
|
||||
}
|
||||
|
||||
uint64 JsonAsset::GetMemoryUsage() const
|
||||
{
|
||||
Locker.Lock();
|
||||
uint64 result = JsonAssetBase::GetMemoryUsage();
|
||||
result += sizeof(JsonAsset) - sizeof(JsonAssetBase);
|
||||
if (Instance && InstanceType)
|
||||
result += InstanceType.GetType().Size;
|
||||
Locker.Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
Asset::LoadResult JsonAsset::loadAsset()
|
||||
{
|
||||
const auto result = JsonAssetBase::loadAsset();
|
||||
|
||||
@@ -77,6 +77,7 @@ public:
|
||||
public:
|
||||
// [Asset]
|
||||
const String& GetPath() const override;
|
||||
uint64 GetMemoryUsage() const override;
|
||||
#if USE_EDITOR
|
||||
void GetReferences(Array<Guid, HeapAllocation>& output) const override;
|
||||
#endif
|
||||
@@ -122,6 +123,10 @@ public:
|
||||
return Instance && InstanceType.IsAssignableFrom(T::TypeInitializer) ? (T*)Instance : nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
// [JsonAssetBase]
|
||||
uint64 GetMemoryUsage() const override;
|
||||
|
||||
protected:
|
||||
// [JsonAssetBase]
|
||||
LoadResult loadAsset() override;
|
||||
|
||||
@@ -636,6 +636,21 @@ bool TextureBase::Init(void* ptr)
|
||||
return Init(initData);
|
||||
}
|
||||
|
||||
uint64 TextureBase::GetMemoryUsage() const
|
||||
{
|
||||
Locker.Lock();
|
||||
uint64 result = BinaryAsset::GetMemoryUsage();
|
||||
result += sizeof(TextureBase) - sizeof(BinaryAsset);
|
||||
if (_customData)
|
||||
{
|
||||
result += sizeof(InitData);
|
||||
for (auto& mip : _customData->Mips)
|
||||
result += mip.Data.Length();
|
||||
}
|
||||
Locker.Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
void TextureBase::CancelStreaming()
|
||||
{
|
||||
_texture.CancelStreamingTasks();
|
||||
|
||||
@@ -221,6 +221,7 @@ private:
|
||||
|
||||
public:
|
||||
// [BinaryAsset]
|
||||
uint64 GetMemoryUsage() const override;
|
||||
void CancelStreaming() override;
|
||||
|
||||
// [ITextureOwner]
|
||||
|
||||
6
Source/ThirdParty/rapidjson/document.h
vendored
6
Source/ThirdParty/rapidjson/document.h
vendored
@@ -2304,6 +2304,12 @@ public:
|
||||
return *allocator_;
|
||||
}
|
||||
|
||||
//! Get the allocator of this document.
|
||||
const Allocator& GetAllocator() const {
|
||||
RAPIDJSON_ASSERT(allocator_);
|
||||
return *allocator_;
|
||||
}
|
||||
|
||||
//! Get the capacity of stack in bytes.
|
||||
size_t GetStackCapacity() const { return stack_.GetCapacity(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user