Skip to content

Add lightweight, zero-overhead tracing macros in tpu_sync/common/trace.h supporting both TraceMe and Perfetto backends. - #856

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_976476264
Sep 5, 2026
Merged

Add lightweight, zero-overhead tracing macros in tpu_sync/common/trace.h supporting both TraceMe and Perfetto backends.#856
copybara-service[bot] merged 1 commit into
mainfrom
test_976476264

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Sep 4, 2026

Copy link
Copy Markdown

Add lightweight, zero-overhead tracing macros in tpu_sync/common/trace.h supporting both TraceMe and Perfetto backends.

  • Define RAIDEN_TRACE(name, ...), RAIDEN_TRACE_SCOPE(name, ...), and RAIDEN_TRACE_FN(name, metadata_fn, ...) wrapping ScopedTrace for fine-grained host timeline instrumentation.
  • Support tsl::profiler::TraceMe and Perfetto track event backends, selectable at runtime via TPU_RAIDEN_TRACE_BACKEND or RAIDEN_TRACE_BACKEND ("traceme", "perfetto", "both", "none"), or via TPU_RAIDEN_USE_PERFETTO / RAIDEN_USE_PERFETTO.
  • Add file-based trace export via StartPerfettoTraceToFile() / StopPerfettoTraceToFile() and automated file capture using TPU_RAIDEN_PERFETTO_OUTPUT_FILE with std::atexit flush.
  • Annotate core Raiden components with sample RAIDEN_TRACE macros across internal/raiden_component.cc, internal/weight_sync_component.cc, internal/raiden_server.cc, and weight_sync/weight_synchronizer_base.cc.
  • Support explicit backend tracing via RAIDEN_PERFETTO_TRACE(...) and RAIDEN_TRACEME_TRACE(...).
  • Implement thread-safe initialization and track event category registration for Perfetto in tpu_sync/common/trace.cc.
  • Provide programmatic backend override via SetTraceBackendForTesting(...) for unit tests.
  • Define RAIDEN_TRACE_LOG(...) and IsTraceLoggingEnabled() for debug trace logging to stderr controlled by TPU_RAIDEN_TRACE and RAIDEN_TRACE environment variables.
  • Add comprehensive unit tests in tpu_sync/common/trace_test.cc covering backend selection, dynamic name lambdas, metadata callbacks, and in-process Perfetto trace sessions.
  • Add bidirectional open-source Copybara transformations for tsl and perfetto dependencies and includes.
  • Declare perfetto Bzlmod dependency and git_override in MODULE.bazel pointing to https://github.com/google/perfetto.
  • Add no_android_deps.patch for Perfetto to remove Android SDK/NDK requirements and fix protoc_lib dependencies for open-source Protobuf 32.1 compatibility.
  • Expose @tsl repository from OpenXLA via tsl_extension in MODULE.bazel and map TSL dependencies to @tsl//tsl in copy.bara.sky for profiler targets.

[skip-perf-gate]

@copybara-service copybara-service Bot changed the title Add lightweight, zero-overhead tracing macros in tpu_sync/common/trace.h. Add lightweight, zero-overhead tracing macros in tpu_sync/common/trace.h supporting both TraceMe and Perfetto backends. Sep 4, 2026
@copybara-service
copybara-service Bot force-pushed the test_976476264 branch 9 times, most recently from 3a574e4 to 35b87f9 Compare September 5, 2026 02:42
@copybara-service
copybara-service Bot force-pushed the test_976476264 branch 2 times, most recently from a094513 to 0878572 Compare September 5, 2026 03:54
…ce.h` supporting both TraceMe and Perfetto backends.

* Define `RAIDEN_TRACE(name, ...)`, `RAIDEN_TRACE_SCOPE(name, ...)`, and `RAIDEN_TRACE_FN(name, metadata_fn, ...)` wrapping `ScopedTrace` for fine-grained host timeline instrumentation.
* Support `tsl::profiler::TraceMe` and `Perfetto` track event backends, selectable at runtime via `TPU_RAIDEN_TRACE_BACKEND` or `RAIDEN_TRACE_BACKEND` ("traceme", "perfetto", "both", "none"), or via `TPU_RAIDEN_USE_PERFETTO` / `RAIDEN_USE_PERFETTO`.
* Add file-based trace export via `StartPerfettoTraceToFile()` / `StopPerfettoTraceToFile()` and automated file capture using `TPU_RAIDEN_PERFETTO_OUTPUT_FILE` with `std::atexit` flush.
* Annotate core Raiden components with sample `RAIDEN_TRACE` macros across `internal/raiden_component.cc`, `internal/weight_sync_component.cc`, `internal/raiden_server.cc`, and `weight_sync/weight_synchronizer_base.cc`.
* Support explicit backend tracing via `RAIDEN_PERFETTO_TRACE(...)` and `RAIDEN_TRACEME_TRACE(...)`.
* Implement thread-safe initialization and track event category registration for Perfetto in `tpu_sync/common/trace.cc`.
* Provide programmatic backend override via `SetTraceBackendForTesting(...)` for unit tests.
* Define `RAIDEN_TRACE_LOG(...)` and `IsTraceLoggingEnabled()` for debug trace logging to stderr controlled by `TPU_RAIDEN_TRACE` and `RAIDEN_TRACE` environment variables.
* Add comprehensive unit tests in `tpu_sync/common/trace_test.cc` covering backend selection, dynamic name lambdas, metadata callbacks, and in-process Perfetto trace sessions.
* Add bidirectional open-source Copybara transformations for `tsl` and `perfetto` dependencies and includes.
* Declare `perfetto` Bzlmod dependency and `git_override` in `MODULE.bazel` pointing to `https://github.com/google/perfetto`.
* Add `no_android_deps.patch` for Perfetto to remove Android SDK/NDK requirements and fix protoc_lib dependencies for open-source Protobuf 32.1 compatibility.
* Expose `@tsl` repository from OpenXLA via `tsl_extension` in `MODULE.bazel` and map TSL dependencies to `@tsl//tsl` in `copy.bara.sky` for profiler targets.

[skip-perf-gate]

PiperOrigin-RevId: 976630278
@copybara-service
copybara-service Bot merged commit 622f9b5 into main Sep 5, 2026
8 checks passed
@copybara-service
copybara-service Bot deleted the test_976476264 branch September 5, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants