#pragma once #include namespace py = pybind11; #include "NameBuffer.hpp" #include "tracy/Tracy.hpp" using OptionalString = std::optional; using OptionalInt = std::optional; template OptionalNumber MemoryAllocate(const Type &type, std::size_t size, const OptionalString &name = std::nullopt, const OptionalNumber &id = std::nullopt, OptionalInt depth = std::nullopt) { #ifdef TRACY_ENABLE if (!name && !id) { if (!depth) TracyAlloc(reinterpret_cast(type), size); else TracyAllocS(reinterpret_cast(type), size, *depth); return std::nullopt; } BufferEntry entry; if (id) { entry.second = NameBuffer::Get(*id); if (!entry.second) return std::nullopt; } else { entry = NameBuffer::Add(*name); if (!entry.first) return std::nullopt; } if (!depth) TracyAllocN(reinterpret_cast(type), size, entry.second); else TracyAllocNS(reinterpret_cast(type), size, *depth, entry.second); return entry.first; #else static_cast(type); // unused static_cast(size); // unused static_cast(name); // unused static_cast(id); // unused static_cast(depth); // unused #endif } template <> OptionalNumber MemoryAllocate(const py::object &object, std::size_t size, const OptionalString &name, const OptionalNumber &id, OptionalInt depth) { return MemoryAllocate(reinterpret_cast(object.ptr()), size, name, id, depth); } template bool MemoryFree(const Type &type, const OptionalNumber &id = std::nullopt, OptionalInt depth = std::nullopt) { #ifdef TRACY_ENABLE if (!id) { if (!depth) TracyFree(reinterpret_cast(type)); else TracyFreeS(reinterpret_cast(type), *depth); return true; } auto ptr = NameBuffer::Get(*id); if (!ptr) return false; if (!depth) TracyFreeN(reinterpret_cast(type), ptr); else TracyFreeNS(reinterpret_cast(type), *depth, ptr); return true; #else static_cast(type); // unused static_cast(id); // unused static_cast(depth); // unused #endif } template <> bool MemoryFree(const py::object &object, const OptionalNumber &id, OptionalInt depth) { return MemoryFree(reinterpret_cast(object.ptr()), id, depth); }