mirror of https://github.com/grpc/grpc.git
[stats] Move core stats to C++ (#30936)
* begin c++ * Automated change: Fix sanity tests * progress * progress * missing-files * Automated change: Fix sanity tests * moved-from-stats * remove old benchmark cruft, get tests compiling * iwyu * Automated change: Fix sanity tests * fix * fix * fixes * fixes * add needed constructor * Automated change: Fix sanity tests * iwyu * fix * fix? * fix * fix * Remove ResetDefaultEventEngine Now that it is a weak_ptr, there's no need to explicitly reset it. When the tracked shared_ptr is deleted, the weak_ptr will fail to lock, and a new default EventEngine will be created. * forget existing engine with FactoryReset * add visibility * fix Co-authored-by: ctiller <ctiller@users.noreply.github.com> Co-authored-by: AJ Heller <hork@google.com>pull/31301/head
parent
90beb3f4c4
commit
20d1efc38a
64 changed files with 979 additions and 1124 deletions
@ -0,0 +1,69 @@ |
||||
// Copyright 2021 gRPC authors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/debug/histogram_view.h" |
||||
|
||||
namespace grpc_core { |
||||
|
||||
double HistogramView::Count() const { |
||||
double sum = 0; |
||||
for (int i = 0; i < num_buckets; i++) { |
||||
sum += buckets[i]; |
||||
} |
||||
return sum; |
||||
} |
||||
|
||||
double HistogramView::ThresholdForCountBelow(double count_below) const { |
||||
double lower_bound; |
||||
double upper_bound; |
||||
int upper_idx; |
||||
|
||||
// find the lowest bucket that gets us above count_below
|
||||
double count_so_far = 0.0; |
||||
int lower_idx = 0; |
||||
for (; lower_idx < num_buckets; lower_idx++) { |
||||
count_so_far += static_cast<double>(buckets[lower_idx]); |
||||
if (count_so_far >= count_below) { |
||||
break; |
||||
} |
||||
} |
||||
if (count_so_far == count_below) { |
||||
// this bucket hits the threshold exactly... we should be midway through
|
||||
// any run of zero values following the bucket
|
||||
for (upper_idx = lower_idx + 1; upper_idx < num_buckets; upper_idx++) { |
||||
if (buckets[upper_idx]) { |
||||
break; |
||||
} |
||||
} |
||||
return (bucket_boundaries[lower_idx] + bucket_boundaries[upper_idx]) / 2.0; |
||||
} else { |
||||
// treat values as uniform throughout the bucket, and find where this value
|
||||
// should lie
|
||||
lower_bound = bucket_boundaries[lower_idx]; |
||||
upper_bound = bucket_boundaries[lower_idx + 1]; |
||||
return upper_bound - (upper_bound - lower_bound) * |
||||
(count_so_far - count_below) / |
||||
static_cast<double>(buckets[lower_idx]); |
||||
} |
||||
} |
||||
|
||||
double HistogramView::Percentile(double p) const { |
||||
const double count = Count(); |
||||
if (count == 0) return 0.0; |
||||
return ThresholdForCountBelow(count * p / 100.0); |
||||
} |
||||
|
||||
} // namespace grpc_core
|
@ -1,17 +0,0 @@ |
||||
client_calls_created_per_iteration:FLOAT, |
||||
server_calls_created_per_iteration:FLOAT, |
||||
client_channels_created_per_iteration:FLOAT, |
||||
client_subchannels_created_per_iteration:FLOAT, |
||||
server_channels_created_per_iteration:FLOAT, |
||||
syscall_write_per_iteration:FLOAT, |
||||
syscall_read_per_iteration:FLOAT, |
||||
tcp_read_alloc_8k_per_iteration:FLOAT, |
||||
tcp_read_alloc_64k_per_iteration:FLOAT, |
||||
http2_settings_writes_per_iteration:FLOAT, |
||||
http2_pings_sent_per_iteration:FLOAT, |
||||
http2_writes_begun_per_iteration:FLOAT, |
||||
http2_transport_stalls_per_iteration:FLOAT, |
||||
http2_stream_stalls_per_iteration:FLOAT, |
||||
cq_pluck_creates_per_iteration:FLOAT, |
||||
cq_next_creates_per_iteration:FLOAT, |
||||
cq_callback_creates_per_iteration:FLOAT |
@ -1,97 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/cpp/util/core_stats.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <string> |
||||
|
||||
#include <grpc/support/atm.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
// IWYU pragma: no_include <google/protobuf/repeated_ptr_field.h>
|
||||
|
||||
using grpc::core::Bucket; |
||||
using grpc::core::Histogram; |
||||
using grpc::core::Metric; |
||||
using grpc::core::Stats; |
||||
|
||||
namespace grpc { |
||||
|
||||
void CoreStatsToProto(const grpc_stats_data& core, Stats* proto) { |
||||
for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { |
||||
Metric* m = proto->add_metrics(); |
||||
m->set_name(grpc_stats_counter_name[i]); |
||||
m->set_count(core.counters[i]); |
||||
} |
||||
for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { |
||||
Metric* m = proto->add_metrics(); |
||||
m->set_name(grpc_stats_histogram_name[i]); |
||||
Histogram* h = m->mutable_histogram(); |
||||
for (int j = 0; j < grpc_stats_histo_buckets[i]; j++) { |
||||
Bucket* b = h->add_buckets(); |
||||
b->set_start(grpc_stats_histo_bucket_boundaries[i][j]); |
||||
b->set_count(core.histograms[grpc_stats_histo_start[i] + j]); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void ProtoToCoreStats(const grpc::core::Stats& proto, grpc_stats_data* core) { |
||||
memset(core, 0, sizeof(*core)); |
||||
for (const auto& m : proto.metrics()) { |
||||
switch (m.value_case()) { |
||||
case Metric::VALUE_NOT_SET: |
||||
break; |
||||
case Metric::kCount: |
||||
for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { |
||||
if (m.name() == grpc_stats_counter_name[i]) { |
||||
core->counters[i] = m.count(); |
||||
break; |
||||
} |
||||
} |
||||
break; |
||||
case Metric::kHistogram: |
||||
for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { |
||||
if (m.name() == grpc_stats_histogram_name[i]) { |
||||
const auto& h = m.histogram(); |
||||
bool valid = true; |
||||
if (grpc_stats_histo_buckets[i] != h.buckets_size()) valid = false; |
||||
for (int j = 0; valid && j < h.buckets_size(); j++) { |
||||
if (grpc_stats_histo_bucket_boundaries[i][j] != |
||||
h.buckets(j).start()) { |
||||
valid = false; |
||||
} |
||||
} |
||||
if (!valid) { |
||||
gpr_log(GPR_ERROR, |
||||
"Found histogram %s but shape is different from proto", |
||||
m.name().c_str()); |
||||
} |
||||
for (int j = 0; valid && j < h.buckets_size(); j++) { |
||||
core->histograms[grpc_stats_histo_start[i] + j] = |
||||
h.buckets(j).count(); |
||||
} |
||||
} |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} // namespace grpc
|
@ -1,32 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016 gRPC authors. |
||||
* |
||||
* 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 GRPC_INTERNAL_CPP_UTIL_CORE_STATS_H |
||||
#define GRPC_INTERNAL_CPP_UTIL_CORE_STATS_H |
||||
|
||||
#include "src/core/lib/debug/stats.h" |
||||
#include "src/proto/grpc/core/stats.pb.h" |
||||
|
||||
namespace grpc { |
||||
|
||||
void CoreStatsToProto(const grpc_stats_data& core, grpc::core::Stats* proto); |
||||
void ProtoToCoreStats(const grpc::core::Stats& proto, grpc_stats_data* core); |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPC_INTERNAL_CPP_UTIL_CORE_STATS_H
|
@ -1,38 +0,0 @@ |
||||
# Copyright 2017 gRPC authors. |
||||
# |
||||
# 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. |
||||
|
||||
load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library") |
||||
load("//bazel:python_rules.bzl", "py_proto_library") |
||||
|
||||
licenses(["notice"]) |
||||
|
||||
grpc_package( |
||||
name = "core", |
||||
visibility = "public", |
||||
) |
||||
|
||||
grpc_proto_library( |
||||
name = "stats_proto", |
||||
srcs = ["stats.proto"], |
||||
) |
||||
|
||||
proto_library( |
||||
name = "stats_descriptor", |
||||
srcs = ["stats.proto"], |
||||
) |
||||
|
||||
py_proto_library( |
||||
name = "stats_py_pb2", |
||||
deps = [":stats_descriptor"], |
||||
) |
Loading…
Reference in new issue