GRPC C++  1.26.0
stats.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 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_CORE_LIB_DEBUG_STATS_H
20 #define GRPC_CORE_LIB_DEBUG_STATS_H
21 
23 
24 #include <grpc/support/atm.h>
27 
28 typedef struct grpc_stats_data {
32 
34 
35 #define GRPC_THREAD_STATS_DATA() \
36  (&grpc_stats_per_cpu_storage[grpc_core::ExecCtx::Get()->starting_cpu()])
37 
38 /* Only collect stats if GRPC_COLLECT_STATS is defined or it is a debug build.
39  */
40 #if defined(GRPC_COLLECT_STATS) || !defined(NDEBUG)
41 #define GRPC_STATS_INC_COUNTER(ctr) \
42  (gpr_atm_no_barrier_fetch_add(&GRPC_THREAD_STATS_DATA()->counters[(ctr)], 1))
43 
44 #define GRPC_STATS_INC_HISTOGRAM(histogram, index) \
45  (gpr_atm_no_barrier_fetch_add( \
46  &GRPC_THREAD_STATS_DATA()->histograms[histogram##_FIRST_SLOT + (index)], \
47  1))
48 #else /* defined(GRPC_COLLECT_STATS) || !defined(NDEBUG) */
49 #define GRPC_STATS_INC_COUNTER(ctr)
50 #define GRPC_STATS_INC_HISTOGRAM(histogram, index)
51 #endif /* defined(GRPC_COLLECT_STATS) || !defined(NDEBUG) */
52 
53 void grpc_stats_init(void);
56 // c = b-a
58  grpc_stats_data* c);
60 int grpc_stats_histo_find_bucket_slow(int value, const int* table,
61  int table_size);
63  grpc_stats_histograms histogram,
64  double percentile);
66  grpc_stats_histograms histogram);
67 
68 #endif
intptr_t gpr_atm
Definition: atm_gcc_atomic.h:30
void grpc_stats_collect(grpc_stats_data *output)
void grpc_stats_init(void)
char * grpc_stats_data_as_json(const grpc_stats_data *data)
void grpc_stats_shutdown(void)
void grpc_stats_diff(const grpc_stats_data *b, const grpc_stats_data *a, grpc_stats_data *c)
double grpc_stats_histo_percentile(const grpc_stats_data *data, grpc_stats_histograms histogram, double percentile)
size_t grpc_stats_histo_count(const grpc_stats_data *data, grpc_stats_histograms histogram)
struct grpc_stats_data grpc_stats_data
grpc_stats_data * grpc_stats_per_cpu_storage
int grpc_stats_histo_find_bucket_slow(int value, const int *table, int table_size)
@ GRPC_STATS_COUNTER_COUNT
Definition: stats_data.h:128
@ GRPC_STATS_HISTOGRAM_BUCKETS
Definition: stats_data.h:177
grpc_stats_histograms
Definition: stats_data.h:132
Definition: stats.h:28
gpr_atm counters[GRPC_STATS_COUNTER_COUNT]
Definition: stats.h:29
gpr_atm histograms[GRPC_STATS_HISTOGRAM_BUCKETS]
Definition: stats.h:30