[tracing] Pass index in stream for traced byte ranges

PiperOrigin-RevId: 609821314
pull/35976/head
Yousuk Seung 9 months ago committed by Copybara-Service
parent ca36ff84ba
commit ad06808bf6
  1. 23
      src/core/ext/transport/chttp2/transport/context_list_entry.h
  2. 3
      src/core/ext/transport/chttp2/transport/internal.h
  3. 4
      src/core/ext/transport/chttp2/transport/writing.cc

@ -38,38 +38,41 @@ namespace grpc_core {
// sent over the wire. A data chunk being written over the wire is multiplexed
// with bytes from multiple RPCs. If one such RPC is traced, we store the
// following information about the traced RPC:
// - byte_offset_in_stream: Number of bytes belonging to that traced RPC which
// have been sent so far from the start of the RPC stream.
// - relative_start_pos_in_chunk: Starting offset of the traced RPC within
// the current chunk that is being sent.
// - num_traced_bytes_in_chunk: Number of bytes belonging to the traced RPC
// within the current chunk.
class ContextListEntry {
public:
ContextListEntry(void* context, int64_t relative_start_pos,
ContextListEntry(void* context, int64_t outbuf_offset,
int64_t num_traced_bytes, size_t byte_offset,
size_t stream_index,
std::shared_ptr<TcpTracerInterface> tcp_tracer)
: trace_context_(context),
relative_start_pos_in_chunk_(relative_start_pos),
outbuf_offset_(outbuf_offset),
num_traced_bytes_in_chunk_(num_traced_bytes),
byte_offset_in_stream_(byte_offset),
stream_index_(stream_index),
tcp_tracer_(std::move(tcp_tracer)) {}
ContextListEntry() = delete;
void* TraceContext() { return trace_context_; }
int64_t RelativeStartPosInChunk() { return relative_start_pos_in_chunk_; }
int64_t OutbufOffset() { return outbuf_offset_; }
int64_t NumTracedBytesInChunk() { return num_traced_bytes_in_chunk_; }
size_t ByteOffsetInStream() { return byte_offset_in_stream_; }
size_t StreamIndex() { return stream_index_; }
std::shared_ptr<TcpTracerInterface> ReleaseTcpTracer() {
return std::move(tcp_tracer_);
}
private:
void* trace_context_;
int64_t relative_start_pos_in_chunk_;
// Offset of the head of the current chunk in the output buffer.
int64_t outbuf_offset_;
// Number of bytes traced in the current chunk.
int64_t num_traced_bytes_in_chunk_;
// Offset of the head of the current chunk in the RPC stream.
size_t byte_offset_in_stream_;
// Index of the current chunk in the RPC stream.
// Set to zero for the first chunk of the RPC stream.
size_t stream_index_;
std::shared_ptr<TcpTracerInterface> tcp_tracer_;
};

@ -640,6 +640,9 @@ struct grpc_chttp2_stream {
/// Byte counter for number of bytes written
size_t byte_counter = 0;
/// Number of times written
int64_t write_counter = 0;
/// Only set when enabled.
grpc_core::CallTracerInterface* call_tracer = nullptr;

@ -665,6 +665,7 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write(
// Add this stream to the list of the contexts to be traced at TCP
num_stream_bytes = t->outbuf.c_slice_buffer()->length - orig_len;
s->byte_counter += static_cast<size_t>(num_stream_bytes);
++s->write_counter;
if (s->traced && grpc_endpoint_can_track_err(t->ep)) {
grpc_core::CopyContextFn copy_context_fn =
grpc_core::GrpcHttp2GetCopyContextFn();
@ -672,7 +673,8 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write(
grpc_core::GrpcHttp2GetWriteTimestampsCallback() != nullptr) {
t->cl->emplace_back(copy_context_fn(s->context),
outbuf_relative_start_pos, num_stream_bytes,
s->byte_counter, s->tcp_tracer);
s->byte_counter, s->write_counter - 1,
s->tcp_tracer);
}
}
outbuf_relative_start_pos += num_stream_bytes;

Loading…
Cancel
Save