• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //
3 // Copyright 2018 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #ifndef GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CONTEXT_LIST_ENTRY_H
20 #define GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CONTEXT_LIST_ENTRY_H
21 
22 #include <grpc/support/port_platform.h>
23 #include <stddef.h>
24 #include <stdint.h>
25 
26 #include <memory>
27 #include <utility>
28 #include <vector>
29 
30 #include "src/core/telemetry/tcp_tracer.h"
31 
32 namespace grpc_core {
33 
34 /// An RPC trace context and associated information. Each RPC/stream is
35 /// associated with a unique \a context. A new ContextList entry is created when
36 /// a chunk of data stored in an outgoing buffer is going to be
37 // sent over the wire. A data chunk being written over the wire is multiplexed
38 // with bytes from multiple RPCs. If one such RPC is traced, we store the
39 // following information about the traced RPC:
40 class ContextListEntry {
41  public:
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)42   ContextListEntry(void* context, int64_t outbuf_offset,
43                    int64_t num_traced_bytes, size_t byte_offset,
44                    size_t stream_index,
45                    std::shared_ptr<TcpTracerInterface> tcp_tracer)
46       : trace_context_(context),
47         outbuf_offset_(outbuf_offset),
48         num_traced_bytes_in_chunk_(num_traced_bytes),
49         byte_offset_in_stream_(byte_offset),
50         stream_index_(stream_index),
51         tcp_tracer_(std::move(tcp_tracer)) {}
52 
53   ContextListEntry() = delete;
54 
TraceContext()55   void* TraceContext() { return trace_context_; }
OutbufOffset()56   int64_t OutbufOffset() { return outbuf_offset_; }
NumTracedBytesInChunk()57   int64_t NumTracedBytesInChunk() { return num_traced_bytes_in_chunk_; }
ByteOffsetInStream()58   size_t ByteOffsetInStream() { return byte_offset_in_stream_; }
StreamIndex()59   size_t StreamIndex() { return stream_index_; }
ReleaseTcpTracer()60   std::shared_ptr<TcpTracerInterface> ReleaseTcpTracer() {
61     return std::move(tcp_tracer_);
62   }
63 
64  private:
65   void* trace_context_;
66   // Offset of the head of the current chunk in the output buffer.
67   int64_t outbuf_offset_;
68   // Number of bytes traced in the current chunk.
69   int64_t num_traced_bytes_in_chunk_;
70   // Offset of the head of the current chunk in the RPC stream.
71   size_t byte_offset_in_stream_;
72   // Index of the current chunk in the RPC stream.
73   // Set to zero for the first chunk of the RPC stream.
74   size_t stream_index_;
75   std::shared_ptr<TcpTracerInterface> tcp_tracer_;
76 };
77 
78 /// A list of RPC Contexts
79 typedef std::vector<ContextListEntry> ContextList;
80 }  // namespace grpc_core
81 
82 #endif  // GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CONTEXT_LIST_ENTRY_H
83