Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
MemoryMisc.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Containers/UnrealString.h"
7#include "Containers/Map.h"
8
9/** Holds generic memory stats, internally implemented as a map. */
11{
12 void Add( const TCHAR* StatDescription, const SIZE_T StatValue )
13 {
14 Data.Add( FString(StatDescription), StatValue );
15 }
16
18};
19
20#ifndef ENABLE_MEMORY_SCOPE_STATS
21#define ENABLE_MEMORY_SCOPE_STATS 0
22#endif
23
24// This will grab the memory stats of VM and Physical before and at the end of scope
25// reporting +/- difference in memory.
26// WARNING This will also capture differences in Threads which have nothing to do with the scope
28class FScopedMemoryStats
29{
30public:
31 explicit FScopedMemoryStats(const TCHAR* Name);
32
33 ~FScopedMemoryStats();
34
35private:
36 const TCHAR* Text;
37 const FPlatformMemoryStats StartStats;
38};
39#else
41{
42public:
43 explicit FScopedMemoryStats(const TCHAR* Name) {}
44};
45#endif
46
47/**
48 * The FSharedMemoryTracker is used to track how much the shared and unique memory pools changed size in-between each call
49 * WARNING: Getting the shared & unique memory pool size is extremely costly (easily takes up to 60ms) so be careful
50 * not to use the tracker while hosting a game.
51 */
52#ifndef ENABLE_SHARED_MEMORY_TRACKER
53#define ENABLE_SHARED_MEMORY_TRACKER 0
54#endif
55
57
58class FSharedMemoryTracker
59{
60public:
61
62 /** Print the difference in memory pool sizes since the last call to this function exclusively */
63 static void PrintMemoryDiff(const TCHAR* Context);
64
65
66 /** Store the memory pool size at construction and log the difference in memory that occurred during the lifetime of the tracker */
67 explicit FSharedMemoryTracker(const FString& InContext);
68 ~FSharedMemoryTracker();
69
70private:
71 const FString PrintContext;
72 const FExtendedPlatformMemoryStats StartStats;
73};
74#else
76{
77public:
78
79 static void PrintMemoryDiff(const TCHAR* /*Context*/) {}
80
81 explicit FSharedMemoryTracker(const FString& /*InContext*/) {}
82};
83#endif // ENABLE_SHARED_MEMORY_TRACKER && PLATFORM_UNIX
#define ENABLE_MEMORY_SCOPE_STATS
Definition MemoryMisc.h:21
#define ENABLE_SHARED_MEMORY_TRACKER
Definition MemoryMisc.h:53
#define PLATFORM_UNIX
Definition Platform.h:59
FScopedMemoryStats(const TCHAR *Name)
Definition MemoryMisc.h:43
static void PrintMemoryDiff(const TCHAR *)
Definition MemoryMisc.h:79
FSharedMemoryTracker(const FString &)
Definition MemoryMisc.h:81
TMap< FString, SIZE_T > Data
Definition MemoryMisc.h:17
void Add(const TCHAR *StatDescription, const SIZE_T StatValue)
Definition MemoryMisc.h:12