Skip to content
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
1 change: 1 addition & 0 deletions tpu_sync/transport/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ cc_library(
name = "transport_adapter",
hdrs = ["transport_adapter.h"],
deps = [
"//tpu_sync/transport/peregrine/src/api:transport_metrics",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
Expand Down
5 changes: 5 additions & 0 deletions tpu_sync/transport/lib/transport_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/types/span.h"
#include "tpu_sync/transport/peregrine/src/api/transport_metrics.h"

namespace tpu_raiden {
namespace transport {
Expand Down Expand Up @@ -86,6 +87,10 @@ class TransportAdapter {
CompletionCallback on_complete = nullptr) = 0;

virtual absl::StatusOr<Status> Poll(Handle handle) = 0;

virtual ::peregrine::TransportMetrics GetTransportMetrics() const {
return {};
}
};

} // namespace lib
Expand Down
9 changes: 9 additions & 0 deletions tpu_sync/transport/peregrine/src/api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")

package(default_visibility = ["//visibility:public"])

cc_library(
name = "transport_metrics",
hdrs = ["transport_metrics.h"],
deps = [
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
],
)

cc_library(
name = "transport_types",
hdrs = ["transport_types.h"],
Expand Down
86 changes: 86 additions & 0 deletions tpu_sync/transport/peregrine/src/api/transport_metrics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2026 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef THIRD_PARTY_PEREGRINE_SRC_API_TRANSPORT_METRICS_H_
#define THIRD_PARTY_PEREGRINE_SRC_API_TRANSPORT_METRICS_H_

#include <array>
#include <cstdint>
#include <numeric>
#include <string>

#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"

namespace peregrine {

// A log2-spaced metric histogram.
// Sample value vs bucket mapping (N = #buckets):
// Value Rrange Bucket
// [0, 1) 0
// [1, 2) 1
// [2, 4) 2
// ...
// [2^(i-1), 2^i) i
// ...
// [2^(N-2), inf) N-1
template <int N = 32>
struct Log2Histogram final {
uint64_t sum = 0;
std::array<uint64_t, N> buckets{};

constexpr int NumBuckets() const { return N; }

constexpr uint64_t Count() const {
return std::accumulate(buckets.begin(), buckets.end(), uint64_t{0});
}

std::string ToString() const {
return absl::StrFormat("Log2Histogram(sum: %d, count: %d, buckets: [%s])",
sum, Count(), absl::StrJoin(buckets, ", "));
}
};

// Per-operation (read or write) end-to-end metrics.
struct OpMetrics final {
// End-to-end transfer duration in microseconds.
Log2Histogram<32> e2e_latency_us{};
// Request per-op size in bytes.
Log2Histogram<32> request_size_bytes{};
// Total payload bytes transferred across all data channels.
uint64_t bytes = 0;
// Total transfer failures.
uint64_t errors = 0;
};

// High-level end-to-end metrics for transport users.
struct TransportMetrics final {
OpMetrics write{};
OpMetrics read{};

// Transport Pipeline Breakdown
// ---------------------------------------------------------------------------
// TODO(yyd): Add tier 2 metrics here

// Hardware & Subsystem Internals
// ---------------------------------------------------------------------------
// Number of failed TCP connection attempts to peers
uint64_t tcp_connect_failures = 0;
// Number of RPC requests received by the control plane
uint64_t rpc_requests_received = 0;
};

} // namespace peregrine

#endif // THIRD_PARTY_PEREGRINE_SRC_API_TRANSPORT_METRICS_H_
Loading