src/cpp/server/load_reporter/util.cc
Go to the documentation of this file.
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 
20 
21 #include <string.h>
22 
23 #include <cmath>
24 #include <string>
25 
26 #include <grpc/load_reporting.h>
27 #include <grpc/support/log.h>
29 #include <grpcpp/server_context.h>
30 #include <grpcpp/support/config.h>
31 
32 namespace grpc {
33 namespace load_reporter {
34 namespace experimental {
35 
37  const std::string& cost_name, double cost_value) {
38  if (std::isnormal(cost_value)) {
40  buf.resize(sizeof(cost_value) + cost_name.size());
41  memcpy(&(*buf.begin()), &cost_value, sizeof(cost_value));
42  memcpy(&(*buf.begin()) + sizeof(cost_value), cost_name.data(),
43  cost_name.size());
44  ctx->AddTrailingMetadata(GRPC_LB_COST_MD_KEY, buf);
45  } else {
46  gpr_log(GPR_ERROR, "Call metric value is not normal.");
47  }
48 }
49 
50 } // namespace experimental
51 } // namespace load_reporter
52 } // namespace grpc
load_reporting.h
grpc::ServerContext
Definition: grpcpp/impl/codegen/server_context.h:566
log.h
ctx
Definition: benchmark-async.c:30
grpc::load_reporter::experimental::AddLoadReportingCost
void AddLoadReportingCost(grpc::ServerContext *ctx, const std::string &cost_name, double cost_value)
Definition: src/cpp/server/load_reporter/util.cc:36
grpc
Definition: grpcpp/alarm.h:33
string.h
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
GRPC_LB_COST_MD_KEY
#define GRPC_LB_COST_MD_KEY
Definition: load_reporting.h:42
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
GPR_ERROR
#define GPR_ERROR
Definition: include/grpc/impl/codegen/log.h:57
config.h
port_platform.h
server_context.h
server_load_reporting.h


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:49