diff --git a/python/bindings/Memory.hpp b/python/bindings/Memory.hpp index bd1982be..91430ca9 100644 --- a/python/bindings/Memory.hpp +++ b/python/bindings/Memory.hpp @@ -9,12 +9,12 @@ namespace py = pybind11; using OptionalString = std::optional; using OptionalInt = std::optional; +#ifdef TRACY_ENABLE 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); @@ -38,27 +38,11 @@ OptionalNumber MemoryAllocate(const Type &type, std::size_t size, 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)); @@ -75,11 +59,27 @@ bool MemoryFree(const Type &type, const OptionalNumber &id = std::nullopt, else TracyFreeNS(reinterpret_cast(type), *depth, ptr); return true; +} #else - static_cast(type); // unused - static_cast(id); // unused - static_cast(depth); // unused + +template +OptionalNumber MemoryAllocate(const Type &, std::size_t, const OptionalString &, + const OptionalNumber &, OptionalInt) { + return 0ul; +} + +template +bool MemoryFree(const Type &, const OptionalNumber &, OptionalInt) { + return true; +} #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 <> diff --git a/python/bindings/Module.cpp b/python/bindings/Module.cpp index 7522de6c..0a13b836 100644 --- a/python/bindings/Module.cpp +++ b/python/bindings/Module.cpp @@ -703,7 +703,7 @@ PYBIND11_MODULE(TracyClientBindings, m) { m.def( "program_name", [](const std::string &name) { - if (!tracy::IsEnabled()) return false; + if (!tracy::IsEnabled()) return true; auto entry = NameBuffer::Add(name); if (!entry.first) return false; TracySetProgramName(entry.second); @@ -722,7 +722,7 @@ PYBIND11_MODULE(TracyClientBindings, m) { m.def( "app_info", [](const std::string &text) { - if (!tracy::IsEnabled()) return false; + if (!tracy::IsEnabled()) return true; if (text.size() >= std::numeric_limits::max()) return false; TracyAppInfo(text.c_str(), text.size()); return true; @@ -732,7 +732,7 @@ PYBIND11_MODULE(TracyClientBindings, m) { m.def( "message", [](const std::string &message) { - if (!tracy::IsEnabled()) return false; + if (!tracy::IsEnabled()) return true; if (message.size() >= std::numeric_limits::max()) return false; TracyMessage(message.c_str(), message.size()); @@ -743,7 +743,7 @@ PYBIND11_MODULE(TracyClientBindings, m) { m.def( "message", [](const std::string &message, uint32_t pColor) { - if (!tracy::IsEnabled()) return false; + if (!tracy::IsEnabled()) return true; if (message.size() >= std::numeric_limits::max()) return false; TracyMessageC(message.c_str(), message.size(), pColor); @@ -756,8 +756,7 @@ PYBIND11_MODULE(TracyClientBindings, m) { m.def( "frame_mark_start", [](const std::string &name) { - if (!tracy::IsEnabled()) - return static_cast(std::nullopt); + if (!tracy::IsEnabled()) return static_cast(0ul); auto entry = NameBuffer::Add(name); if (!entry.first) return static_cast(std::nullopt); FrameMarkStart(entry.second); @@ -768,7 +767,7 @@ PYBIND11_MODULE(TracyClientBindings, m) { m.def( "frame_mark_end", [](std::size_t id) { - if (!tracy::IsEnabled()) return false; + if (!tracy::IsEnabled()) return true; auto ptr = NameBuffer::Get(id); if (!ptr) return false; FrameMarkEnd(ptr); @@ -780,7 +779,7 @@ PYBIND11_MODULE(TracyClientBindings, m) { "frame_image", [](const py::bytes &image, uint16_t width, uint16_t height, uint8_t offset = 0, bool flip = false) { - if (!tracy::IsEnabled()) return false; + if (!tracy::IsEnabled()) return true; if (width % 4 != 0 || height % 4 != 0) return false; TracyCFrameImage(std::string(image).data(), width, height, offset, flip); @@ -823,8 +822,7 @@ PYBIND11_MODULE(TracyClientBindings, m) { "_plot_config", [](const std::string &name, int type, bool step, bool fill, uint32_t color = 0) { - if (!tracy::IsEnabled()) - return static_cast(std::nullopt); + if (!tracy::IsEnabled()) return static_cast(0ul); auto entry = NameBuffer::Add(name); if (!entry.first) return static_cast(std::nullopt); TracyCPlotConfig(entry.second, type, step, fill, color); @@ -842,7 +840,7 @@ PYBIND11_MODULE(TracyClientBindings, m) { m.def( "plot", [](std::size_t id, double value) { - if (!tracy::IsEnabled()) return false; + if (!tracy::IsEnabled()) return true; auto ptr = NameBuffer::Get(id); if (!ptr) return false; TracyCPlot(ptr, value); @@ -852,7 +850,7 @@ PYBIND11_MODULE(TracyClientBindings, m) { m.def( "plot", [](std::size_t id, float value) { - if (!tracy::IsEnabled()) return false; + if (!tracy::IsEnabled()) return true; auto ptr = NameBuffer::Get(id); if (!ptr) return false; TracyCPlotF(ptr, value); @@ -862,7 +860,7 @@ PYBIND11_MODULE(TracyClientBindings, m) { m.def( "plot", [](std::size_t id, int64_t value) { - if (!tracy::IsEnabled()) return false; + if (!tracy::IsEnabled()) return true; auto ptr = NameBuffer::Get(id); if (!ptr) return false; TracyCPlotI(ptr, value); diff --git a/python/bindings/ScopedZone.hpp b/python/bindings/ScopedZone.hpp index e5c6143b..98e8fafb 100644 --- a/python/bindings/ScopedZone.hpp +++ b/python/bindings/ScopedZone.hpp @@ -23,7 +23,6 @@ bool SetText(const std::string& text, tracy::ScopedZone* zone) { zone->Text(text.c_str(), text.size()); return true; } -#endif class PyScopedZone { public: @@ -45,47 +44,30 @@ class PyScopedZone { virtual ~PyScopedZone() { Exit(); }; bool IsActive() const { -#ifdef TRACY_ENABLE if (!m_zone) return m_active; return m_zone->IsActive(); -#else - return false; -#endif } template bool Text(const Type& text) { -#ifdef TRACY_ENABLE return SetText(text, m_zone); -#else - static_cast(text); // unused -#endif } bool Name(const std::string& name) { -#ifdef TRACY_ENABLE if (name.size() >= std::numeric_limits::max()) return false; m_name = name; if (!m_zone) return true; m_zone->Name(m_name->c_str(), m_name->size()); return true; -#else - static_cast(name); // unused -#endif } void Color(uint32_t color) { -#ifdef TRACY_ENABLE m_color = color; if (!m_zone) return; m_zone->Color(m_color); -#else - static_cast(color); // unused -#endif } void Enter() { -#ifdef TRACY_ENABLE if (m_depth) m_zone = new tracy::ScopedZone( m_line, m_source.c_str(), m_source.size(), m_function.c_str(), @@ -96,14 +78,11 @@ class PyScopedZone { m_line, m_source.c_str(), m_source.size(), m_function.c_str(), m_function.size(), m_name ? m_name->c_str() : nullptr, m_name ? m_name->size() : 0ul, m_color, m_active); -#endif } void Exit() { -#ifdef TRACY_ENABLE if (m_zone) delete m_zone; m_zone = nullptr; -#endif } private: @@ -116,7 +95,26 @@ class PyScopedZone { std::string m_source; uint32_t m_line; -#ifdef TRACY_ENABLE tracy::ScopedZone* m_zone; -#endif }; +#else + +class PyScopedZone { + public: + PyScopedZone(const std::optional&, uint32_t, std::optional, + bool, const std::string&, const std::string&, uint32_t line) {} + virtual ~PyScopedZone(){}; + + bool IsActive() const { return false; } + + template + bool Text(const Type&) { + return true; + } + + bool Name(const std::string&) { return true; } + void Color(uint32_t) {} + void Enter() {} + void Exit() {} +}; +#endif