| 221 | #define TRACY_ENABLE_MEMORY (TRACY_ENABLE) |
| 222 | |
| 223 | void PlatformBase::OnMemoryAlloc(void* ptr, uint64 size) |
| 224 | { |
| 225 | if (!ptr) |
| 226 | return; |
| 227 | |
| 228 | #if TEST_MALLOC |
| 229 | if (GetMallocTester().OnMalloc(ptr, size)) |
| 230 | LOG(Fatal, "Invalid malloc detected for pointer 0x{0:x} ({1} bytes)!\n{2}", (uintptr)ptr, size, Platform::GetStackTrace(3)); |
| 231 | #endif |
| 232 | |
| 233 | #if TRACY_ENABLE_MEMORY |
| 234 | // Track memory allocation in Tracy |
| 235 | //tracy::Profiler::MemAlloc(ptr, (size_t)size, false); |
| 236 | tracy::Profiler::MemAllocCallstack(ptr, (size_t)size, 12, false); |
| 237 | #endif |
| 238 | |
| 239 | // Register in memory profiler |
| 240 | if (ProfilerMemory::Enabled) |
| 241 | ProfilerMemory::OnMemoryAlloc(ptr, size); |
| 242 | |
| 243 | // Register allocation during the current CPU event |
| 244 | auto thread = ProfilerCPU::GetCurrentThread(); |
| 245 | if (thread != nullptr && thread->Buffer.GetCount() != 0) |
| 246 | { |
| 247 | auto& activeEvent = thread->Buffer.Last().Event(); |
| 248 | if (activeEvent.End < ZeroTolerance) |
| 249 | { |
| 250 | activeEvent.NativeMemoryAllocation += (int32)size; |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | void PlatformBase::OnMemoryFree(void* ptr) |
| 256 | { |