Tracy

From goniz/mlx-vulkan · View interactive version

Tracy is an AI agent skill from the GitHub repository goniz/mlx-vulkan. Set up and use Tracy profiler for MLX Vulkan backend profiling

How to use this skill

Skill file

Tracy Setup and Usage for MLX Vulkan

Purpose

Use this skill when you need to add, enable, or analyze Tracy profiling in a native C++ project, especially an MLX backend or Vulkan-heavy codebase. The goal is to get from “no profiling” to actionable traces with minimal nonsense and minimal hot-path damage.

This skill is grounded in the Tracy user manual quick-start and feature documentation. Tracy integration requires adding TracyClient.cpp, including tracy/Tracy.hpp, defining TRACY_ENABLE project-wide, and instrumenting code with macros such as ZoneScoped and FrameMark. Tracy also supports GPU profiling, memory profiling, plots, message logs, and call stacks. fileciteturn1file0

When to use

Use this skill when the user asks to:

When not to use

Do not use this skill when:

Core facts to rely on

Workflow

1. Add Tracy to the project

Preferred options:

Minimal source integration:

2. Wire build system

For CMake-based native projects, do one of these:

Option A: submodule
option(TRACY_ENABLE "Enable Tracy profiler" ON)
add_subdirectory(third_party/tracy)

target_link_libraries(my_target PRIVATE Tracy::TracyClient)
target_compile_definitions(my_target PRIVATE TRACY_ENABLE)
Option B: FetchContent
include(FetchContent)
option(TRACY_ENABLE "Enable Tracy profiler" ON)

FetchContent_Declare(
  tracy
  GIT_REPOSITORY https://github.com/wolfpld/tracy.git
  GIT_TAG master
  GIT_SHALLOW TRUE
  GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(tracy)

target_link_libraries(my_target PRIVATE Tracy::TracyClient)
target_compile_definitions(my_target PRIVATE TRACY_ENABLE)

3. Add CPU instrumentation first

Start embarrassingly small:

#include <tracy/Tracy.hpp>

void run_graph(Graph& g) {
    ZoneScoped;
    // work
}

For thread entry points:

void worker_thread_main() {
    tracy::SetThreadName("mlx-vk-worker");
    ZoneScoped;
    // loop
}

For frame-like iterations or benchmark iterations:

void render_or_step() {
    ZoneScoped;
    // work
    FrameMark;
}

ZoneScoped records scope timing plus source location metadata, while FrameMark establishes frame boundaries for the frame profiler. fileciteturn1file0 fileciteturn1file9

4. Add richer CPU annotations where useful

Use these when the trace starts looking like spaghetti thrown into a server rack:

ZoneScopedN("encode_command_buffer");
ZoneText(cmd_name.c_str(), cmd_name.size());
ZoneValue(batch_size);

Useful macros include:

5. Add message log and plots for runtime state

For queue depth, bytes uploaded, command buffers submitted, descriptor set pressure, split-k count, and similar bread-and-butter signals:

TracyPlot("vk.pending_submissions", pending_submissions);
TracyPlot("vk.bytes_uploaded", static_cast<int64_t>(bytes_uploaded));
TracyMessageL("transfer queue stalled");

You can configure plot presentation with TracyPlotConfig(name, format, step, fill, color). Tracy supports number, memory, and percentage plot formats. fileciteturn1file5

6. Add memory instrumentation if allocator behavior matters

Wrap custom allocators or strategic allocation sites:

void* p = allocate(sz);
TracyAlloc(p, sz);

TracyFree(p);
free(p);

This enables memory graphs, leak visibility, active-allocation rewind, and memory hot-spot analysis. fileciteturn1file5

7. Add Vulkan GPU profiling carefully

Tracy supports Vulkan GPU profiling. Use it for command-buffer spans, dispatch batches, copy/upload passes, and queue submission analysis. The exact Vulkan API wrappers/macros are documented in the Tracy manual’s GPU profiling section. fileciteturn1file1

Recommended pattern for an MLX Vulkan backend:

Suggested first-pass zone map for MLX Vulkan:

8. Build and run the Tracy profiler

The manual states the profiler/analyzer is built separately with CMake, for example:

cmake -B profiler/build -S profiler -DCMAKE_BUILD_TYPE=Release
cmake --build profiler/build --config Release --parallel

The analyzer can connect to localhost or remote clients. Tracy recommends using matching client/server versions because protocol changes between releases can break connections. fileciteturn1file7

9. Capture and analyze

Basic loop:

Tracy can also be used in interactive or command-line capture flows, and the manual has dedicated sections for capture and later analysis. fileciteturn1file1

Practical rules

Troubleshooting checklist

Output expectations

When using this skill, produce:

Example response skeleton

Use this structure when helping the user:

  1. explain the smallest viable Tracy integration
  2. show the exact CMake changes
  3. show CPU instrumentation examples
  4. show MLX Vulkan-specific placement points
  5. optionally add plots, memory, and GPU zones
  6. explain how to capture and read the first trace

Reference

Primary source: Tracy Profiler user manual, including quick-start, build, instrumentation, plots, memory profiling, and GPU profiling sections. fileciteturn1file0

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.