Skip to content

Commit f23e18a

Browse files
chenxingqiangalice
andcommitted
Merge branch 'dev/tracy-tracesmith-integration-5314' - Tracy Profiler Integration v0.11.0
Features: - Bidirectional Tracy Profiler integration - Full GPU timeline support for Ascend/MetaX/ROCm - Tracy client wrapper (tracy_client.hpp) - Tracy exporter (tracy_exporter.hpp/cpp) - Tracy importer (tracy_importer.hpp/cpp) - TracyGpuContext for native GPU timeline visualization - Unified profiling macros (TracySmithZoneScoped, etc.) - 45+ unit tests - Comprehensive example (tracy_integration_example.cpp) This enables real-time visualization of GPU profiling data in Tracy for platforms that Tracy doesn't natively support, including: - Huawei Ascend NPUs - MetaX MACA GPUs - AMD ROCm GPUs Co-authored-by: alice <alice@thinkcode.me>
2 parents a3f4408 + 51ce81c commit f23e18a

18 files changed

Lines changed: 3949 additions & 0 deletions

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "third_party/tracy"]
2+
path = third_party/tracy
3+
url = https://github.com/wolfpld/tracy.git

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ option(TRACESMITH_ENABLE_ROCM "Enable ROCm support" OFF)
2828
option(TRACESMITH_ENABLE_METAL "Enable Metal support" OFF)
2929
option(TRACESMITH_ENABLE_MACA "Enable MetaX MACA/MCPTI support" OFF)
3030
option(TRACESMITH_ENABLE_ASCEND "Enable Huawei Ascend/CANN support" OFF)
31+
option(TRACESMITH_ENABLE_TRACY "Enable Tracy Profiler integration" ON)
3132
option(TRACESMITH_USE_LIBUNWIND "Use libunwind for call stack capture" ON)
3233
option(TRACESMITH_USE_PERFETTO_SDK "Use Perfetto SDK for protobuf export" OFF)
3334

@@ -188,6 +189,11 @@ add_subdirectory(src/state)
188189
add_subdirectory(src/replay)
189190
add_subdirectory(src/cluster)
190191

192+
# Tracy integration
193+
if(TRACESMITH_ENABLE_TRACY)
194+
add_subdirectory(src/tracy)
195+
endif()
196+
191197
# GDB RSP backend (Linux only for now)
192198
option(TRACESMITH_BUILD_GDB "Build GDB RSP backend" ON)
193199
if(TRACESMITH_BUILD_GDB AND UNIX)
@@ -260,6 +266,7 @@ message(STATUS " ROCm support: ${TRACESMITH_ENABLE_ROCM}")
260266
message(STATUS " Metal support: ${TRACESMITH_ENABLE_METAL}")
261267
message(STATUS " MACA support: ${TRACESMITH_ENABLE_MACA}")
262268
message(STATUS " Ascend support: ${TRACESMITH_ENABLE_ASCEND}")
269+
message(STATUS " Tracy support: ${TRACESMITH_ENABLE_TRACY}")
263270
message(STATUS " Perfetto SDK: ${TRACESMITH_USE_PERFETTO_SDK}")
264271
message(STATUS " libunwind: ${TRACESMITH_USE_LIBUNWIND}")
265272
message(STATUS "")

README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- **GPU Memory Profiler**: Allocation tracking, leak detection, peak usage monitoring
3434
- **CLI Tools**: Easy-to-use command-line interface for recording and viewing traces
3535
- **GDB Integration** (v0.10.0): GPU-aware debugging via GDB Remote Serial Protocol (RSP)
36+
- **Tracy Profiler Integration** (v0.11.0): Real-time visualization with full GPU timeline support for Ascend/MetaX/ROCm
3637

3738
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/chenxingqiang/TraceSmith)
3839

@@ -72,8 +73,15 @@
7273
- `.json` - Perfetto JSON (chrome://tracing)
7374
- `.perfetto` - Perfetto Protobuf (85% smaller)
7475
- `.dot` - Graphviz dependency graph
76+
- `.tracy` - Tracy profiler format (via import)
7577
- ASCII Timeline - Terminal visualization
7678

79+
**Integrations:**
80+
- [Tracy Profiler](https://github.com/wolfpld/tracy) - Real-time visualization (v0.11.0+)
81+
- [Perfetto SDK](https://perfetto.dev/) - Native protobuf export
82+
- [LLVM XRay](https://llvm.org/docs/XRay.html) - Compiler-instrumented traces
83+
- [PyTorch Kineto](https://github.com/pytorch/kineto) - Compatible schema
84+
7785
## Prerequisites & Dependencies
7886

7987
Before installing TraceSmith, install the required dependencies for your platform.
@@ -847,6 +855,143 @@ if ts.is_ascend_available():
847855
ts.export_perfetto(events, "ascend_trace.json")
848856
```
849857

858+
#### Tracy Profiler Integration (v0.11.0)
859+
860+
TraceSmith provides bidirectional integration with [Tracy Profiler](https://github.com/wolfpld/tracy), enabling real-time visualization of GPU profiling data alongside Tracy's existing CPU profiling capabilities.
861+
862+
**Features:**
863+
- **Full GPU Timeline** for Ascend, MetaX, ROCm (not just messages!)
864+
- Export TraceSmith events to Tracy for real-time visualization
865+
- Import Tracy captures (`.tracy` files) into TraceSmith format
866+
- Unified profiling macros that work with both profilers
867+
- GPU zone emission for kernel timing visualization
868+
- Memory allocation tracking in Tracy
869+
- Counter/plot data for metrics visualization
870+
- Frame marking for game/real-time applications
871+
872+
**GPU Timeline Support:**
873+
874+
| GPU Platform | Tracy Native | TraceSmith Integration |
875+
|--------------|--------------|------------------------|
876+
| NVIDIA CUDA | ✅ Native | ✅ Full Timeline |
877+
| Vulkan | ✅ Native | ✅ Full Timeline |
878+
| Metal | ✅ Native | ✅ Full Timeline |
879+
| **Huawei Ascend** | ❌ None |**Full Timeline** |
880+
| **MetaX MACA** | ❌ None |**Full Timeline** |
881+
| **AMD ROCm** | ❌ None |**Full Timeline** |
882+
883+
TraceSmith enables **full GPU timeline visualization** in Tracy for platforms that Tracy doesn't natively support, including Ascend NPUs and MetaX GPUs.
884+
885+
**Quick Start:**
886+
887+
```bash
888+
# Build with Tracy integration
889+
cmake .. -DTRACESMITH_ENABLE_TRACY=ON
890+
make -j$(nproc)
891+
892+
# Run example (connect Tracy server for visualization)
893+
./bin/tracy_integration_example
894+
```
895+
896+
**Full GPU Timeline API (Ascend/MetaX/ROCm):**
897+
898+
```cpp
899+
#include <tracesmith/tracy/tracy_gpu_context.hpp>
900+
901+
using namespace tracesmith;
902+
903+
// Create GPU context for Ascend NPU
904+
auto& ascend_ctx = tracy::getOrCreateGpuContext(
905+
"Ascend 910B NPU", tracy::GpuContextType::Ascend, 0);
906+
907+
// Create GPU context for MetaX GPU
908+
auto& metax_ctx = tracy::getOrCreateGpuContext(
909+
"MetaX C500 GPU", tracy::GpuContextType::MACA, 0);
910+
911+
// Method 1: Emit GPU zone directly (creates timeline bar in Tracy)
912+
ascend_ctx.emitGpuZone("AscendMatMul",
913+
cpu_start, cpu_end, // CPU timestamps
914+
gpu_start, gpu_end, // GPU timestamps
915+
thread_id, color);
916+
917+
// Method 2: Use RAII macro
918+
{
919+
TracySmithGpuZone(metax_ctx, "MetaXGEMM");
920+
// ... kernel execution ...
921+
} // Zone emitted on scope exit
922+
923+
// Method 3: Convert TraceSmith events to GPU timeline
924+
std::vector<TraceEvent> events;
925+
profiler->getEvents(events);
926+
ascend_ctx.emitGpuZones(events); // Batch convert to timeline
927+
```
928+
929+
**Tracy Visualization Result:**
930+
931+
```
932+
┌─────────────────────────────────────────────────────────┐
933+
│ CPU Timeline │
934+
│ ████ submit ████████████████████ submit ████ │
935+
├─────────────────────────────────────────────────────────┤
936+
│ Ascend 910B NPU │
937+
│ ▓▓▓▓▓▓▓▓ AscendMatMul ▓▓▓▓▓▓ AscendConv2D │
938+
├─────────────────────────────────────────────────────────┤
939+
│ MetaX C500 GPU │
940+
│ ▓▓▓▓ MetaXGEMM ▓▓▓▓▓▓▓▓▓▓▓▓ MetaXReduce │
941+
└─────────────────────────────────────────────────────────┘
942+
```
943+
944+
**Basic C++ API:**
945+
946+
```cpp
947+
#include <tracesmith/tracy/tracy_client.hpp>
948+
#include <tracesmith/tracy/tracy_exporter.hpp>
949+
950+
using namespace tracesmith;
951+
952+
// Use unified profiling macros
953+
TracySmithZoneScopedC("MyKernel", tracy::colors::KernelLaunch);
954+
955+
// Create Tracy exporter
956+
tracy::TracyExporter exporter;
957+
exporter.initialize();
958+
959+
// Export TraceSmith events to Tracy
960+
TraceEvent event;
961+
event.type = EventType::KernelLaunch;
962+
event.name = "matmul_f32";
963+
event.duration = 1500000; // 1.5ms
964+
exporter.emitEvent(event);
965+
966+
// Frame marking
967+
tracy::markFrame("RenderFrame");
968+
969+
// Plot metrics
970+
exporter.emitPlotValue("GPU Utilization %", 85.0);
971+
```
972+
973+
**Import Tracy Captures:**
974+
975+
```cpp
976+
#include <tracesmith/tracy/tracy_importer.hpp>
977+
978+
tracy::TracyImporter importer;
979+
auto result = importer.importFile("profile.tracy");
980+
981+
if (result.success()) {
982+
// Access TraceSmith events
983+
for (const auto& event : result.record.events()) {
984+
std::cout << event.name << ": " << event.duration << " ns\n";
985+
}
986+
}
987+
```
988+
989+
**CMake Options:**
990+
991+
| Option | Default | Description |
992+
|--------|---------|-------------|
993+
| `TRACESMITH_ENABLE_TRACY` | ON | Enable Tracy profiler integration |
994+
850995
#### GDB Integration (v0.10.0)
851996

852997
TraceSmith provides a GDB Remote Serial Protocol (RSP) backend for GPU-aware debugging, enabling developers to debug GPU applications with full visibility into GPU state.
@@ -1337,6 +1482,7 @@ for (int i = 0; i < 10000; ++i) {
13371482
13381483
| Version | Date | Highlights |
13391484
|---------|------|------------|
1485+
| **v0.11.0** | 2026-01 | **Tracy Integration** - Bidirectional Tracy profiler integration, **full GPU timeline for Ascend/MetaX/ROCm**, real-time visualization, unified profiling macros, 45+ unit tests |
13401486
| **v0.10.0** | 2025-12 | **GDB Integration** - GPU-aware debugging via RSP, kernel breakpoints, trace replay debugging, 85 unit tests |
13411487
| **v0.9.0** | 2025-12 | **Huawei Ascend NPU** - Full CANN/ACL integration, msprof profiling, Multi-GPU simulation verified |
13421488
| **v0.8.2** | 2025-12 | **CLI Breaking Change** - Enforce --nsys/--mctracer for CUDA/MACA, record command blocked, clearer API limitation messages |
@@ -1364,6 +1510,7 @@ TraceSmith draws inspiration from:
13641510
- [NVIDIA CUPTI](https://docs.nvidia.com/cupti/)
13651511
- [ROCm ROCProfiler](https://github.com/ROCm/rocprofiler)
13661512
- [Google Perfetto](https://perfetto.dev/)
1513+
- [Tracy Profiler](https://github.com/wolfpld/tracy)
13671514
- [LLVM XRay](https://llvm.org/docs/XRay.html)
13681515
- [RenderDoc](https://renderdoc.org/)
13691516
- [PyTorch Kineto](https://github.com/pytorch/kineto)

examples/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,24 @@ target_link_libraries(goal_validation_example PRIVATE
356356
tracesmith-replay
357357
)
358358

359+
# ----------------------------------------------------------------------------
360+
# Tracy Integration Example - Bidirectional Tracy profiler integration
361+
# ----------------------------------------------------------------------------
362+
if(TRACESMITH_ENABLE_TRACY)
363+
add_executable(tracy_integration_example
364+
tracy_integration_example.cpp
365+
)
366+
367+
target_link_libraries(tracy_integration_example PRIVATE
368+
tracesmith-common
369+
tracesmith-tracy
370+
)
371+
372+
# Add threading support
373+
find_package(Threads REQUIRED)
374+
target_link_libraries(tracy_integration_example PRIVATE Threads::Threads)
375+
endif()
376+
359377
# ----------------------------------------------------------------------------
360378
# Benchmark: 10K Call Stacks - Validates core goal
361379
# "Capture 10K+ instruction-level GPU call stacks without interrupting business"
@@ -459,5 +477,9 @@ if(TRACESMITH_ENABLE_MACA)
459477
message(STATUS " - metax_benchmark (MetaX memory bandwidth test)")
460478
message(STATUS " - metax_cluster_example (MetaX multi-GPU cluster profiling)")
461479
endif()
480+
if(TRACESMITH_ENABLE_TRACY)
481+
message(STATUS " Tracy integration examples:")
482+
message(STATUS " - tracy_integration_example (Tracy profiler integration)")
483+
endif()
462484
message(STATUS " Python examples:")
463485
message(STATUS " - python_example.py (Python API demonstration)")

0 commit comments

Comments
 (0)