Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tracy integration, allow parent projects to include RmlUi profiling markers #518

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions CMake/Modules/FindTracy.cmake

This file was deleted.

67 changes: 52 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,29 +254,64 @@ else()
endif()
endif()

option(ENABLE_TRACY_PROFILING "Enable profiling with Tracy. Source files can be placed in Dependencies/tracy." OFF)
if( ENABLE_TRACY_PROFILING )
find_package(Tracy REQUIRED)
function(EnableConfigurationType name enable)
if(enable)
list(APPEND CMAKE_CONFIGURATION_TYPES "${name}")
list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
else()
list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES "${name}")
endif()
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "List of configurations to enable" FORCE)
endfunction()

include_directories(${TRACY_INCLUDE_DIR})
option(RMLUI_TRACY_PROFILING "Enable profiling with Tracy. Source files can be placed in Dependencies/tracy." OFF)
if( RMLUI_TRACY_PROFILING )
option(RMLUI_TRACY_MEMORY_PROFILING "Overload global operator new/delete to track memory allocations in Tracy." ON)

if( CMAKE_CONFIGURATION_TYPES )
list(APPEND CMAKE_CONFIGURATION_TYPES Tracy)
list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
"Add the configurations that we need"
FORCE)
set(CMAKE_C_FLAGS_TRACY "${CMAKE_CXX_FLAGS_RELEASE} -DRMLUI_ENABLE_PROFILING")
set(CMAKE_CXX_FLAGS_TRACY "${CMAKE_CXX_FLAGS_RELEASE} -DRMLUI_ENABLE_PROFILING")
set(CMAKE_EXE_LINKER_FLAGS_TRACY "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
set(CMAKE_SHARED_LINKER_FLAGS_TRACY "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
option(RMLUI_TRACY_CONFIGURATION "Enable a separate Tracy configuration type for multi-config generators such as Visual Studio, otherwise enable Tracy in all configurations." ON)

if( RMLUI_TRACY_CONFIGURATION )
EnableConfigurationType(Tracy ON)
list(APPEND CMAKE_MAP_IMPORTED_CONFIG_TRACY Release)
set(CMAKE_C_FLAGS_TRACY "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_TRACY "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_EXE_LINKER_FLAGS_TRACY "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
set(CMAKE_SHARED_LINKER_FLAGS_TRACY "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
else()
EnableConfigurationType(Tracy OFF)
endif()
endif()

if(NOT TARGET Tracy::TracyClient)
find_package(Tracy QUIET)
endif()

if(NOT TARGET Tracy::TracyClient)
message("Trying to add Tracy from subdirectory 'Dependencies/tracy'.")
add_subdirectory("Dependencies/tracy")
endif()

if(NOT TARGET Tracy::TracyClient)
message(FATAL_ERROR "Tracy client not found. Either (a) make sure target Tracy::TracyClient is available from parent project,"
"(b) Tracy can be found as a config package, or (c) Tracy source files are located in 'Dependencies/Tracy'.")
endif()

if( CMAKE_CONFIGURATION_TYPES AND RMLUI_TRACY_CONFIGURATION )
message("-- Tracy profiling enabled in configuration 'Tracy'.")
set(RMLUI_TRACY_CONDITION "$<CONFIG:Tracy>")
else()
message("-- Tracy profiling enabled.")
list(APPEND CORE_PUBLIC_DEFS -DRMLUI_ENABLE_PROFILING)
set(RMLUI_TRACY_CONDITION "1")
endif()

list(APPEND CORE_PUBLIC_LINK_LIBS "$<${RMLUI_TRACY_CONDITION}:Tracy::TracyClient>")
list(APPEND CORE_PUBLIC_DEFS "$<${RMLUI_TRACY_CONDITION}:RMLUI_TRACY_PROFILING>")
if(RMLUI_TRACY_MEMORY_PROFILING)
list(APPEND CORE_PRIVATE_DEFS "$<${RMLUI_TRACY_CONDITION}:RMLUI_TRACY_MEMORY_PROFILING>")
endif()
elseif( CMAKE_CONFIGURATION_TYPES )
list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES Tracy)
EnableConfigurationType(Tracy OFF)
endif()

option(ENABLE_LOTTIE_PLUGIN "Enable plugin for Lottie animations. Requires the rlottie library." OFF)
Expand Down Expand Up @@ -600,12 +635,14 @@ if(NOT BUILD_FRAMEWORK)
target_include_directories(RmlCore PRIVATE ${CORE_INCLUDE_DIRS})
target_include_directories(RmlCore INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Include> $<INSTALL_INTERFACE:include>)
target_link_libraries(RmlCore PRIVATE ${CORE_LINK_LIBS})
target_link_libraries(RmlCore PUBLIC ${CORE_PUBLIC_LINK_LIBS})
target_link_libraries(RmlDebugger RmlCore)
target_compile_definitions(RmlCore PRIVATE ${CORE_PRIVATE_DEFS})
target_compile_definitions(RmlCore PUBLIC ${CORE_PUBLIC_DEFS})
else()
target_include_directories(RmlUi PRIVATE ${CORE_INCLUDE_DIRS})
target_link_libraries(RmlUi PRIVATE ${CORE_LINK_LIBS})
target_link_libraries(RmlUi PUBLIC ${CORE_PUBLIC_LINK_LIBS})
target_compile_definitions(RmlUi PRIVATE ${CORE_PRIVATE_DEFS})
target_compile_definitions(RmlUi PUBLIC ${CORE_PUBLIC_DEFS})
endif()
Expand Down
3 changes: 1 addition & 2 deletions Include/RmlUi/Core/Profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
#ifndef RMLUI_CORE_PROFILING_H
#define RMLUI_CORE_PROFILING_H

#ifdef RMLUI_ENABLE_PROFILING
#ifdef RMLUI_TRACY_PROFILING

#define TRACY_ENABLE
#include <tracy/Tracy.hpp>

#define RMLUI_ZoneNamed(varname, active) ZoneNamed(varname, active)
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Element::~Element()

void Element::Update(float dp_ratio, Vector2f vp_dimensions)
{
#ifdef RMLUI_ENABLE_PROFILING
#ifdef RMLUI_TRACY_PROFILING
auto name = GetAddress(false, false);
RMLUI_ZoneScoped;
RMLUI_ZoneText(name.c_str(), name.size());
Expand Down Expand Up @@ -213,7 +213,7 @@ void Element::UpdateProperties(const float dp_ratio, const Vector2f vp_dimension

void Element::Render()
{
#ifdef RMLUI_ENABLE_PROFILING
#ifdef RMLUI_TRACY_PROFILING
auto name = GetAddress(false, false);
RMLUI_ZoneScoped;
RMLUI_ZoneText(name.c_str(), name.size());
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Layout/BlockFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ UniquePtr<LayoutBox> BlockFormattingContext::Format(ContainerBox* parent_contain
{
RMLUI_ASSERT(parent_container && element);

#ifdef RMLUI_ENABLE_PROFILING
#ifdef RMLUI_TRACY_PROFILING
RMLUI_ZoneScopedC(0xB22222);
auto name = CreateString(80, "%s %x", element->GetAddress(false, false).c_str(), element);
RMLUI_ZoneName(name.c_str(), name.size());
Expand Down Expand Up @@ -212,7 +212,7 @@ bool BlockFormattingContext::FormatInlineBox(BlockContainer* parent_container, E

bool BlockFormattingContext::FormatBlockContainerChild(BlockContainer* parent_container, Element* element)
{
#ifdef RMLUI_ENABLE_PROFILING
#ifdef RMLUI_TRACY_PROFILING
RMLUI_ZoneScoped;
auto name = CreateString(80, ">%s %x", element->GetAddress(false, false).c_str(), element);
RMLUI_ZoneName(name.c_str(), name.size());
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/Profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

#include "../../Include/RmlUi/Core/Profiling.h"

#ifdef RMLUI_ENABLE_PROFILING
#include <TracyClient.cpp>
#ifdef RMLUI_TRACY_MEMORY_PROFILING
#include <memory>

void* operator new(std::size_t n)
Expand Down