Skip to content

Commit

Permalink
remove implementation when VKB_PROFILING is off
Browse files Browse the repository at this point in the history
  • Loading branch information
tomadamatkinson committed Jun 24, 2024
1 parent 10123f2 commit 7afbca4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
7 changes: 6 additions & 1 deletion components/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ vkb__register_component(
src/profiling.cpp
LINK_LIBS
spdlog::spdlog
TracyClient
)

if (VKB_PROFILING)
target_link_libraries(vkb__core PUBLIC TracyClient)
target_compile_definitions(vkb__core PUBLIC TRACY_ENABLE)
endif()


vkb__register_tests(
COMPONENT core
NAME utils
Expand Down
18 changes: 14 additions & 4 deletions components/core/include/core/util/profiling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@

#include "core/util/error.hpp"

VKBP_DISABLE_WARNINGS()
#ifdef TRACY_ENABLE
#include <tracy/Tracy.hpp>
VKBP_ENABLE_WARNINGS()
#endif




#ifdef TRACY_ENABLE
// malloc and free are used by Tracy to provide memory profiling
void *operator new(size_t count);
void operator delete(void *ptr) noexcept;
Expand All @@ -37,6 +41,10 @@ void operator delete(void *ptr) noexcept;

// Trace a function
#define PROFILE_FUNCTION() ZoneScoped
#else
#define PROFILE_SCOPE(name)
#define PROFILE_FUNCTION()
#endif

// The type of plot to use
enum class PlotType
Expand Down Expand Up @@ -108,8 +116,10 @@ class Plot
private:
static void update_tracy_plot(const char *name, T value)
{
TracyPlot(name, value);
TracyPlotConfig(name, TO_TRACY_PLOT_FORMAT(PT), true, true, 0);
#ifdef TRACY_ENABLE
TracyPlot(name, value);
TracyPlotConfig(name, TO_TRACY_PLOT_FORMAT(PT), true, true, 0);
#endif
}

static Plot *get_instance()
Expand Down
2 changes: 2 additions & 0 deletions components/core/src/profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <cstdlib>

#ifdef TRACY_ENABLE
void *operator new(size_t count)
{
auto ptr = malloc(count);
Expand All @@ -31,3 +32,4 @@ void operator delete(void *ptr) noexcept
TracyFree(ptr);
free(ptr);
}
#endif
12 changes: 7 additions & 5 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,10 @@ set_property(TARGET Catch2 PROPERTY FOLDER "ThirdParty")
set_property(TARGET Catch2WithMain PROPERTY FOLDER "ThirdParty")

# Tracy
set(TRACY_ENABLE ${VKB_ENABLE_TRACY})
set(TRACY_TIMER_FALLBACK ON)
add_subdirectory(tracy)
add_compile_definitions(TRACY_NO_INVARIANT_CHECK=1)
set_property(TARGET TracyClient PROPERTY FOLDER "ThirdParty")
if (VKB_PROFILING)
set(TRACY_ENABLE ${VKB_PROFILING})
set(TRACY_TIMER_FALLBACK ON)
add_subdirectory(tracy)
add_compile_definitions(TRACY_NO_INVARIANT_CHECK=1)
set_property(TARGET TracyClient PROPERTY FOLDER "ThirdParty")
endif()

0 comments on commit 7afbca4

Please sign in to comment.