flatten 20260225
This commit is contained in:
58
tjp/core/debug/Allocations.h
Executable file
58
tjp/core/debug/Allocations.h
Executable file
@@ -0,0 +1,58 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Debug.h"
|
||||
#include <typeinfo>
|
||||
#include "../containers/Map.h"
|
||||
#include "../string/String.h"
|
||||
#include "../threads/Lock.hpp"
|
||||
#include "../algorithm/ExecuteOnDestruct.hpp"
|
||||
#include "../rtti/RTTI.hpp"
|
||||
|
||||
namespace tjp::core::debug {
|
||||
|
||||
struct Allocations
|
||||
{
|
||||
struct Allocation {
|
||||
int count = 0;
|
||||
} ;
|
||||
|
||||
Mutex mutex;
|
||||
Map<String, Allocation> allocations;
|
||||
|
||||
void onAllocation (const type_index &t);
|
||||
void onDeallocation (const type_index &t);
|
||||
String log ();
|
||||
|
||||
static Allocations *shared();
|
||||
} ;
|
||||
|
||||
} // namespace
|
||||
|
||||
#if defined(_DEBUG)
|
||||
|
||||
#define ALLOC_RECORD(x) \
|
||||
tjp::core::debug::Allocations::shared()->onAllocation(type_id(*x))
|
||||
#define DEALLOC_RECORD(x) \
|
||||
tjp::core::debug::Allocations::shared()->onDeallocation(type_id(*x))
|
||||
|
||||
#define SCOPE_RECORD(x) \
|
||||
struct __ALLOC__##x __alloc__ {}; \
|
||||
ALLOC_RECORD(&__alloc_); \
|
||||
tjp::core::ExecuteOnDestruct __dealloc__([&]() { DEALLOC_RECORD(&__alloc__)); \
|
||||
|
||||
#define ALLOC_LOG() \
|
||||
sLogRelease("alloc", tjp::core::debug::Allocations::shared()->log())
|
||||
|
||||
#else
|
||||
|
||||
#define ALLOC_RECORD(x)
|
||||
#define DEALLOC_RECORD(x)
|
||||
#define SCOPE_RECORD(x)
|
||||
|
||||
#define ALLOC_LOG()
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user