| 1 |
/* |
| 2 |
* Copyright 2017 gRPC authors. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
/* |
| 18 |
* Automatically generated by tools/codegen/core/gen_stats_data.py |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifndef GRPC_CORE_LIB_DEBUG_STATS_DATA_H |
| 22 |
#define GRPC_CORE_LIB_DEBUG_STATS_DATA_H |
| 23 |
|
| 24 |
#include <grpc/support/port_platform.h> |
| 25 |
|
| 26 |
#include <stdint.h> |
| 27 |
|
| 28 |
#include <atomic> |
| 29 |
#include <memory> |
| 30 |
|
| 31 |
#include "absl/strings/string_view.h" |
| 32 |
|
| 33 |
#include "src/core/lib/debug/histogram_view.h" |
| 34 |
#include "src/core/lib/gprpp/per_cpu.h" |
| 35 |
|
| 36 |
namespace grpc_core { |
| 37 |
class HistogramCollector_32768_24; |
| 38 |
class Histogram_32768_24 { |
| 39 |
public: |
| 40 |
static int BucketFor(int value); |
| 41 |
const uint64_t* buckets() const { return buckets_; } |
| 42 |
friend Histogram_32768_24 operator-(const Histogram_32768_24& left, |
| 43 |
const Histogram_32768_24& right); |
| 44 |
|
| 45 |
private: |
| 46 |
friend class HistogramCollector_32768_24; |
| 47 |
uint64_t buckets_[24]{}; |
| 48 |
}; |
| 49 |
class HistogramCollector_32768_24 { |
| 50 |
public: |
| 51 |
void Increment(int value) { |
| 52 |
buckets_[Histogram_32768_24::BucketFor(value)].fetch_add( |
| 53 |
1, std::memory_order_relaxed); |
| 54 |
} |
| 55 |
void Collect(Histogram_32768_24* result) const; |
| 56 |
|
| 57 |
private: |
| 58 |
std::atomic<uint64_t> buckets_[24]{}; |
| 59 |
}; |
| 60 |
class HistogramCollector_16777216_20; |
| 61 |
class Histogram_16777216_20 { |
| 62 |
public: |
| 63 |
static int BucketFor(int value); |
| 64 |
const uint64_t* buckets() const { return buckets_; } |
| 65 |
friend Histogram_16777216_20 operator-(const Histogram_16777216_20& left, |
| 66 |
const Histogram_16777216_20& right); |
| 67 |
|
| 68 |
private: |
| 69 |
friend class HistogramCollector_16777216_20; |
| 70 |
uint64_t buckets_[20]{}; |
| 71 |
}; |
| 72 |
class HistogramCollector_16777216_20 { |
| 73 |
public: |
| 74 |
void Increment(int value) { |
| 75 |
buckets_[Histogram_16777216_20::BucketFor(value)].fetch_add( |
| 76 |
1, std::memory_order_relaxed); |
| 77 |
} |
| 78 |
void Collect(Histogram_16777216_20* result) const; |
| 79 |
|
| 80 |
private: |
| 81 |
std::atomic<uint64_t> buckets_[20]{}; |
| 82 |
}; |
| 83 |
class HistogramCollector_80_10; |
| 84 |
class Histogram_80_10 { |
| 85 |
public: |
| 86 |
static int BucketFor(int value); |
| 87 |
const uint64_t* buckets() const { return buckets_; } |
| 88 |
friend Histogram_80_10 operator-(const Histogram_80_10& left, |
| 89 |
const Histogram_80_10& right); |
| 90 |
|
| 91 |
private: |
| 92 |
friend class HistogramCollector_80_10; |
| 93 |
uint64_t buckets_[10]{}; |
| 94 |
}; |
| 95 |
class HistogramCollector_80_10 { |
| 96 |
public: |
| 97 |
void Increment(int value) { |
| 98 |
buckets_[Histogram_80_10::BucketFor(value)].fetch_add( |
| 99 |
1, std::memory_order_relaxed); |
| 100 |
} |
| 101 |
void Collect(Histogram_80_10* result) const; |
| 102 |
|
| 103 |
private: |
| 104 |
std::atomic<uint64_t> buckets_[10]{}; |
| 105 |
}; |
| 106 |
struct GlobalStats { |
| 107 |
enum class Counter { |
| 108 |
kClientCallsCreated, |
| 109 |
kServerCallsCreated, |
| 110 |
kClientChannelsCreated, |
| 111 |
kClientSubchannelsCreated, |
| 112 |
kServerChannelsCreated, |
| 113 |
kSyscallWrite, |
| 114 |
kSyscallRead, |
| 115 |
kTcpReadAlloc8k, |
| 116 |
kTcpReadAlloc64k, |
| 117 |
kHttp2SettingsWrites, |
| 118 |
kHttp2PingsSent, |
| 119 |
kHttp2WritesBegun, |
| 120 |
kHttp2TransportStalls, |
| 121 |
kHttp2StreamStalls, |
| 122 |
kCqPluckCreates, |
| 123 |
kCqNextCreates, |
| 124 |
kCqCallbackCreates, |
| 125 |
COUNT |
| 126 |
}; |
| 127 |
enum class Histogram { |
| 128 |
kCallInitialSize, |
| 129 |
kTcpWriteSize, |
| 130 |
kTcpWriteIovSize, |
| 131 |
kTcpReadSize, |
| 132 |
kTcpReadOffer, |
| 133 |
kTcpReadOfferIovSize, |
| 134 |
kHttp2SendMessageSize, |
| 135 |
COUNT |
| 136 |
}; |
| 137 |
GlobalStats(); |
| 138 |
static const absl::string_view counter_name[static_cast<int>(Counter::COUNT)]; |
| 139 |
static const absl::string_view |
| 140 |
histogram_name[static_cast<int>(Histogram::COUNT)]; |
| 141 |
static const absl::string_view counter_doc[static_cast<int>(Counter::COUNT)]; |
| 142 |
static const absl::string_view |
| 143 |
histogram_doc[static_cast<int>(Histogram::COUNT)]; |
| 144 |
union { |
| 145 |
struct { |
| 146 |
uint64_t client_calls_created; |
| 147 |
uint64_t server_calls_created; |
| 148 |
uint64_t client_channels_created; |
| 149 |
uint64_t client_subchannels_created; |
| 150 |
uint64_t server_channels_created; |
| 151 |
uint64_t syscall_write; |
| 152 |
uint64_t syscall_read; |
| 153 |
uint64_t tcp_read_alloc_8k; |
| 154 |
uint64_t tcp_read_alloc_64k; |
| 155 |
uint64_t http2_settings_writes; |
| 156 |
uint64_t http2_pings_sent; |
| 157 |
uint64_t http2_writes_begun; |
| 158 |
uint64_t http2_transport_stalls; |
| 159 |
uint64_t http2_stream_stalls; |
| 160 |
uint64_t cq_pluck_creates; |
| 161 |
uint64_t cq_next_creates; |
| 162 |
uint64_t cq_callback_creates; |
| 163 |
}; |
| 164 |
uint64_t counters[static_cast<int>(Counter::COUNT)]; |
| 165 |
}; |
| 166 |
Histogram_32768_24 call_initial_size; |
| 167 |
Histogram_16777216_20 tcp_write_size; |
| 168 |
Histogram_80_10 tcp_write_iov_size; |
| 169 |
Histogram_16777216_20 tcp_read_size; |
| 170 |
Histogram_16777216_20 tcp_read_offer; |
| 171 |
Histogram_80_10 tcp_read_offer_iov_size; |
| 172 |
Histogram_16777216_20 http2_send_message_size; |
| 173 |
HistogramView histogram(Histogram which) const; |
| 174 |
std::unique_ptr<GlobalStats> Diff(const GlobalStats& other) const; |
| 175 |
}; |
| 176 |
class GlobalStatsCollector { |
| 177 |
public: |
| 178 |
std::unique_ptr<GlobalStats> Collect() const; |
| 179 |
void IncrementClientCallsCreated() { |
| 180 |
data_.this_cpu().client_calls_created.fetch_add(1, |
| 181 |
std::memory_order_relaxed); |
| 182 |
} |
| 183 |
void IncrementServerCallsCreated() { |
| 184 |
data_.this_cpu().server_calls_created.fetch_add(1, |
| 185 |
std::memory_order_relaxed); |
| 186 |
} |
| 187 |
void IncrementClientChannelsCreated() { |
| 188 |
data_.this_cpu().client_channels_created.fetch_add( |
| 189 |
1, std::memory_order_relaxed); |
| 190 |
} |
| 191 |
void IncrementClientSubchannelsCreated() { |
| 192 |
data_.this_cpu().client_subchannels_created.fetch_add( |
| 193 |
1, std::memory_order_relaxed); |
| 194 |
} |
| 195 |
void IncrementServerChannelsCreated() { |
| 196 |
data_.this_cpu().server_channels_created.fetch_add( |
| 197 |
1, std::memory_order_relaxed); |
| 198 |
} |
| 199 |
void IncrementSyscallWrite() { |
| 200 |
data_.this_cpu().syscall_write.fetch_add(1, std::memory_order_relaxed); |
| 201 |
} |
| 202 |
void IncrementSyscallRead() { |
| 203 |
data_.this_cpu().syscall_read.fetch_add(1, std::memory_order_relaxed); |
| 204 |
} |
| 205 |
void IncrementTcpReadAlloc8k() { |
| 206 |
data_.this_cpu().tcp_read_alloc_8k.fetch_add(1, std::memory_order_relaxed); |
| 207 |
} |
| 208 |
void IncrementTcpReadAlloc64k() { |
| 209 |
data_.this_cpu().tcp_read_alloc_64k.fetch_add(1, std::memory_order_relaxed); |
| 210 |
} |
| 211 |
void IncrementHttp2SettingsWrites() { |
| 212 |
data_.this_cpu().http2_settings_writes.fetch_add(1, |
| 213 |
std::memory_order_relaxed); |
| 214 |
} |
| 215 |
void IncrementHttp2PingsSent() { |
| 216 |
data_.this_cpu().http2_pings_sent.fetch_add(1, std::memory_order_relaxed); |
| 217 |
} |
| 218 |
void IncrementHttp2WritesBegun() { |
| 219 |
data_.this_cpu().http2_writes_begun.fetch_add(1, std::memory_order_relaxed); |
| 220 |
} |
| 221 |
void IncrementHttp2TransportStalls() { |
| 222 |
data_.this_cpu().http2_transport_stalls.fetch_add( |
| 223 |
1, std::memory_order_relaxed); |
| 224 |
} |
| 225 |
void IncrementHttp2StreamStalls() { |
| 226 |
data_.this_cpu().http2_stream_stalls.fetch_add(1, |
| 227 |
std::memory_order_relaxed); |
| 228 |
} |
| 229 |
void IncrementCqPluckCreates() { |
| 230 |
data_.this_cpu().cq_pluck_creates.fetch_add(1, std::memory_order_relaxed); |
| 231 |
} |
| 232 |
void IncrementCqNextCreates() { |
| 233 |
data_.this_cpu().cq_next_creates.fetch_add(1, std::memory_order_relaxed); |
| 234 |
} |
| 235 |
void IncrementCqCallbackCreates() { |
| 236 |
data_.this_cpu().cq_callback_creates.fetch_add(1, |
| 237 |
std::memory_order_relaxed); |
| 238 |
} |
| 239 |
void IncrementCallInitialSize(int value) { |
| 240 |
data_.this_cpu().call_initial_size.Increment(value); |
| 241 |
} |
| 242 |
void IncrementTcpWriteSize(int value) { |
| 243 |
data_.this_cpu().tcp_write_size.Increment(value); |
| 244 |
} |
| 245 |
void IncrementTcpWriteIovSize(int value) { |
| 246 |
data_.this_cpu().tcp_write_iov_size.Increment(value); |
| 247 |
} |
| 248 |
void IncrementTcpReadSize(int value) { |
| 249 |
data_.this_cpu().tcp_read_size.Increment(value); |
| 250 |
} |
| 251 |
void IncrementTcpReadOffer(int value) { |
| 252 |
data_.this_cpu().tcp_read_offer.Increment(value); |
| 253 |
} |
| 254 |
void IncrementTcpReadOfferIovSize(int value) { |
| 255 |
data_.this_cpu().tcp_read_offer_iov_size.Increment(value); |
| 256 |
} |
| 257 |
void IncrementHttp2SendMessageSize(int value) { |
| 258 |
data_.this_cpu().http2_send_message_size.Increment(value); |
| 259 |
} |
| 260 |
|
| 261 |
private: |
| 262 |
struct Data { |
| 263 |
std::atomic<uint64_t> client_calls_created{0}; |
| 264 |
std::atomic<uint64_t> server_calls_created{0}; |
| 265 |
std::atomic<uint64_t> client_channels_created{0}; |
| 266 |
std::atomic<uint64_t> client_subchannels_created{0}; |
| 267 |
std::atomic<uint64_t> server_channels_created{0}; |
| 268 |
std::atomic<uint64_t> syscall_write{0}; |
| 269 |
std::atomic<uint64_t> syscall_read{0}; |
| 270 |
std::atomic<uint64_t> tcp_read_alloc_8k{0}; |
| 271 |
std::atomic<uint64_t> tcp_read_alloc_64k{0}; |
| 272 |
std::atomic<uint64_t> http2_settings_writes{0}; |
| 273 |
std::atomic<uint64_t> http2_pings_sent{0}; |
| 274 |
std::atomic<uint64_t> http2_writes_begun{0}; |
| 275 |
std::atomic<uint64_t> http2_transport_stalls{0}; |
| 276 |
std::atomic<uint64_t> http2_stream_stalls{0}; |
| 277 |
std::atomic<uint64_t> cq_pluck_creates{0}; |
| 278 |
std::atomic<uint64_t> cq_next_creates{0}; |
| 279 |
std::atomic<uint64_t> cq_callback_creates{0}; |
| 280 |
HistogramCollector_32768_24 call_initial_size; |
| 281 |
HistogramCollector_16777216_20 tcp_write_size; |
| 282 |
HistogramCollector_80_10 tcp_write_iov_size; |
| 283 |
HistogramCollector_16777216_20 tcp_read_size; |
| 284 |
HistogramCollector_16777216_20 tcp_read_offer; |
| 285 |
HistogramCollector_80_10 tcp_read_offer_iov_size; |
| 286 |
HistogramCollector_16777216_20 http2_send_message_size; |
| 287 |
}; |
| 288 |
PerCpu<Data> data_; |
| 289 |
}; |
| 290 |
} // namespace grpc_core |
| 291 |
|
| 292 |
#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ |