• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //
3 // Copyright 2024 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 #include "src/core/ext/transport/chttp2/transport/call_tracer_wrapper.h"
20 
21 #include "src/core/ext/transport/chttp2/transport/internal.h"
22 
23 namespace grpc_core {
24 
RecordIncomingBytes(const CallTracerInterface::TransportByteSize & transport_byte_size)25 void Chttp2CallTracerWrapper::RecordIncomingBytes(
26     const CallTracerInterface::TransportByteSize& transport_byte_size) {
27   // Update legacy API.
28   stream_->stats.incoming.framing_bytes += transport_byte_size.framing_bytes;
29   stream_->stats.incoming.data_bytes += transport_byte_size.data_bytes;
30   stream_->stats.incoming.header_bytes += transport_byte_size.header_bytes;
31   // Update new API.
32   if (!IsCallTracerInTransportEnabled()) return;
33   auto* call_tracer = stream_->arena->GetContext<CallTracerInterface>();
34   if (call_tracer != nullptr) {
35     call_tracer->RecordIncomingBytes(transport_byte_size);
36   }
37 }
38 
RecordOutgoingBytes(const CallTracerInterface::TransportByteSize & transport_byte_size)39 void Chttp2CallTracerWrapper::RecordOutgoingBytes(
40     const CallTracerInterface::TransportByteSize& transport_byte_size) {
41   // Update legacy API.
42   stream_->stats.outgoing.framing_bytes += transport_byte_size.framing_bytes;
43   stream_->stats.outgoing.data_bytes += transport_byte_size.data_bytes;
44   stream_->stats.outgoing.header_bytes +=
45       transport_byte_size.header_bytes;  // Update new API.
46   if (!IsCallTracerInTransportEnabled()) return;
47   auto* call_tracer = stream_->arena->GetContext<CallTracerInterface>();
48   if (call_tracer != nullptr) {
49     call_tracer->RecordOutgoingBytes(transport_byte_size);
50   }
51 }
52 
53 }  // namespace grpc_core