Skip to content
Open
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
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ set_option(TRACY_TIMER_FALLBACK "Use lower resolution timers" OFF)
set_option(TRACY_LIBUNWIND_BACKTRACE "Use libunwind backtracing where supported" OFF)
set_option(TRACY_SYMBOL_OFFLINE_RESOLVE "Instead of full runtime symbol resolution, only resolve the image path and offset to enable offline symbol resolution" OFF)
set_option(TRACY_LIBBACKTRACE_ELF_DYNLOAD_SUPPORT "Enable libbacktrace to support dynamically loaded elfs in symbol resolution resolution after the first symbol resolve operation" OFF)
set_option(TRACY_NAME_BUFFER "Enable name buffer for other languages" OFF)
set_option(TRACY_DEBUGINFOD "Enable debuginfod support" OFF)

# advanced
Expand Down Expand Up @@ -221,6 +222,16 @@ set(common_includes
${TRACY_PUBLIC_DIR}/common/TracyWinFamily.hpp
${TRACY_PUBLIC_DIR}/common/TracyYield.hpp)

if(TRACY_NAME_BUFFER)
set(TRACY_BUFFER_SIZE 128 CACHE STRING "The size of the name buffer")
set(TRACY_NAME_LENGTH 128 CACHE STRING "The length of a name in the buffer")

list(APPEND common_includes ${TRACY_PUBLIC_DIR}/common/TracyNameBuffer.hpp)

target_compile_definitions(TracyClient PRIVATE TRACY_BUFFER_SIZE=${TRACY_BUFFER_SIZE})
target_compile_definitions(TracyClient PRIVATE TRACY_NAME_LENGTH=${TRACY_NAME_LENGTH})
endif()

install(TARGETS TracyClient
EXPORT TracyConfig
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/$<IF:$<CONFIG:Release>,,$<CONFIG>>
Expand Down Expand Up @@ -277,6 +288,9 @@ if(TRACY_CLIENT_PYTHON)
if(TRACY_STATIC)
message(FATAL_ERROR "Python-bindings require a shared client library")
endif()
if(NOT TRACY_NAME_BUFFER)
message(FATAL_ERROR "Python-bindings require name buffer being enabled")
endif()

add_subdirectory(python)
endif()
6 changes: 3 additions & 3 deletions manual/tracy.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3630,7 +3630,7 @@ \subsubsection{Timeline view}
\item \emph{Gray} -- Threads assigned to other programs running in the system.
\end{itemize}

When the \faMousePointer{}~mouse pointer is hovered over either the CPU data zone or the thread timeline label, Tracy will display a line connecting all zones associated with the selected thread. This can be used to quickly see how the thread migrated across the CPU cores.
When the \faMousePointer{}~mouse pointer is hovered over either the CPU data zone or the thread timeline label, Tracy will display a line connecting all zones associated with the selected thread. This can be used to quickly see how the thread migrated across the CPU cores.

It will also add lines starting with a filed circle to denote wake up events. Those are useful to pinpoint the origin of a thread waking up, especially when holding locks. It may also start from an empty region, denoting the time at which the kernel chose to schedule or boost the priority of your thread. Wake ups will have a different color based on the reason for which the thread was waiting to be scheduled.

Expand Down Expand Up @@ -3668,7 +3668,7 @@ \subsubsection{Timeline view}

In the above picture, \emph{Thread B} migrates from \emph{Core 3} to \emph{Core 4} due to a wake up from \emph{Thread A}. Then it migrates from \emph{Core 4} to \emph{Core 1}.

Clicking the \LMB{}~left mouse button on a tracked thread will make it visible on the timeline if it was either hidden or collapsed before. It will also lock the selected thread so that you may pan and explore data while retaining the visualization of thread migrations and wake up events.
Clicking the \LMB{}~left mouse button on a tracked thread will make it visible on the timeline if it was either hidden or collapsed before. It will also lock the selected thread so that you may pan and explore data while retaining the visualization of thread migrations and wake up events.
Clicking again somewhere empty on the timeline with the \LMB{}~left mouse button will unlock the selection.

Careful examination of the data presented on this graph may allow you to determine areas where the profiled application was fighting for system resources with other programs (see section~\ref{checkenvironmentos}) or give you a hint to add more instrumentation macros.
Expand Down Expand Up @@ -4717,7 +4717,7 @@ \subsubsection{Model selection}
There are many factors to take into consideration when choosing a model to use. First, you should determine which model family you want to use:

\begin{itemize}
\item \emph{Gemma 3} (\url{https://blog.google/technology/developers/gemma-3/}) is a well rounded model that can converse in multiple languages.
\item \emph{Gemma 3} (\url{https://blog.google/technology/developers/gemma-3/}) is a well rounded model that can converse in multiple languages.
\item \emph{Qwen3} (\url{https://qwenlm.github.io/blog/qwen3/}) has a more technical feeling to it, it likes to write bullet point lists.
\item \emph{Mistral Small} (\url{https://mistral.ai/news/mistral-small-3-1}) may also be considered. Despite the name, it is not small.
\end{itemize}
Expand Down
4 changes: 4 additions & 0 deletions public/TracyClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#ifdef TRACY_ROCPROF
# include "client/TracyRocprof.cpp"
#endif

#ifdef TRACY_NAME_BUFFER
#include "common/TracyNameBuffer.cpp"
#endif
#ifdef _MSC_VER
# pragma comment(lib, "ws2_32.lib")
# pragma comment(lib, "advapi32.lib")
Expand Down
44 changes: 44 additions & 0 deletions public/common/TracyNameBuffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "TracyNameBuffer.hpp"
using namespace tracy;

#include "TracyApi.h"

#ifndef TRACY_BUFFER_SIZE
#define TRACY_BUFFER_SIZE = 128
#endif

#ifndef TRACY_NAME_LENGTH
#define TRACY_NAME_LENGTH = 128
#endif

NameBuffer::NameBuffer() : m_buffer(TRACY_BUFFER_SIZE, nullptr), m_index(0ul) {
for (std::size_t index = 0ul, end = m_buffer.size(); index < end; ++index)
m_buffer[index] = new char[TRACY_NAME_LENGTH];
}

BufferEntry NameBuffer::add( const std::string& name ) {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_index >= TRACY_BUFFER_SIZE || name.size() > TRACY_NAME_LENGTH)
return std::make_pair(std::nullopt, nullptr);

auto index = m_index++;
name.copy(m_buffer[index], name.size());
return std::make_pair(index, m_buffer[index]);
}

const char* NameBuffer::get( uint16_t index ) {
std::lock_guard<std::mutex> lock(m_mutex);
if (index >= TRACY_BUFFER_SIZE) return nullptr;
return m_buffer[index];
}

#ifdef TRACY_NAME_BUFFER
TRACY_API const char* ___tracy_name_buffer_add( const char* name, uint16_t* id ) {
auto entry = NameBuffer::Add(name);
if (!entry.first) return nullptr;

if (id != nullptr) *id = *entry.first;
return entry.second;
}
TRACY_API const char* ___tracy_name_buffer_get( uint16_t id ) { return NameBuffer::Get(id); }
#endif
37 changes: 37 additions & 0 deletions public/common/TracyNameBuffer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <mutex>
#include <optional>
#include <string>
#include <vector>

namespace tracy {
using OptionalNumber = std::optional<uint16_t>;
using BufferEntry = std::pair<OptionalNumber, const char*>;

class NameBuffer {
public:
static inline BufferEntry Add( const std::string& name ) {
return getBuffer().add(name);
}

static inline const char* Get( uint16_t index ) {
return getBuffer().get(index);
}

private:
NameBuffer();

std::mutex m_mutex;
std::vector<char*> m_buffer;
std::size_t m_index;

static inline NameBuffer& getBuffer() {
static NameBuffer buffer;
return buffer;
}

BufferEntry add( const std::string& name );
const char* get( uint16_t index );
};
} // namespace tracy
4 changes: 4 additions & 0 deletions public/tracy/Tracy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@
# define TracyFiberLeave tracy::Profiler::LeaveFiber()
#endif

#ifdef TRACY_NAME_BUFFER
# include "../common/TracyNameBuffer.hpp"
#endif

#endif

#endif
17 changes: 17 additions & 0 deletions public/tracy/TracyC.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ TRACY_API void ___tracy_set_thread_name( const char* name );

#ifndef TRACY_ENABLE

#define TracyCEnabled() 0

typedef const void* TracyCZoneCtx;

typedef const void* TracyCLockCtx;
Expand Down Expand Up @@ -122,8 +124,15 @@ typedef const void* TracyCLockCtx;
# define TracyCFiberLeave
#endif

#ifdef TRACY_NAME_BUFFER
# define TracyCNameBufferAdd(name, id) 0
# define TracyCNameBufferGet(id) 0
#endif

#else

#define TracyCEnabled() 1

#ifndef TracyConcat
# define TracyConcat(x,y) TracyConcatIndirect(x,y)
#endif
Expand Down Expand Up @@ -384,6 +393,14 @@ TRACY_API void ___tracy_fiber_leave( void );
# define TracyCFiberLeave ___tracy_fiber_leave();
#endif

#ifdef TRACY_NAME_BUFFER
TRACY_API const char* ___tracy_name_buffer_add( const char* name, uint16_t* id );
TRACY_API const char* ___tracy_name_buffer_get( uint16_t id );

# define TracyCNameBufferAdd(name, id) ___tracy_name_buffer_add( name, id );
# define TracyCNameBufferGet(id) ___tracy_name_buffer_get( id );
#endif

#endif

#ifdef __cplusplus
Expand Down
6 changes: 0 additions & 6 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@ if(EXTERNAL_PYBIND11)
FetchContent_MakeAvailable(pybind11)
endif()

set(BUFFER_SIZE 128 CACHE STRING "The size of the pointer buffer")
set(NAME_LENGTH 128 CACHE STRING "The length of a name in the buffer")

pybind11_add_module(TracyClientBindings SHARED bindings/Module.cpp)
target_link_libraries(TracyClientBindings PUBLIC TracyClient)
target_link_libraries(TracyClientBindings PUBLIC ${Python_LIBRARIES})
target_compile_definitions(TracyClientBindings PUBLIC BUFFER_SIZE=${BUFFER_SIZE})
target_compile_definitions(TracyClientBindings PUBLIC NAME_LENGTH=${NAME_LENGTH})

if (UNIX)
set_target_properties(TracyClientBindings PROPERTIES
BUILD_RPATH_USE_ORIGIN TRUE
Expand Down
3 changes: 2 additions & 1 deletion python/bindings/Memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <pybind11/pybind11.h>
namespace py = pybind11;

#include "NameBuffer.hpp"
#include "tracy/Tracy.hpp"
using namespace tracy;

using OptionalString = std::optional<std::string>;
using OptionalInt = std::optional<int32_t>;
Expand Down Expand Up @@ -61,6 +61,7 @@ bool MemoryFree(const Type &type, const OptionalNumber &id = std::nullopt,
return true;
}
#else
using OptionalNumber = std::optional<uint16_t>;

template <typename Type = uint64_t>
OptionalNumber MemoryAllocate(const Type &, std::size_t, const OptionalString &,
Expand Down
Loading
Loading