aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/statistics
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/statistics')
-rw-r--r--src/core/statistics/census_interface.h4
-rw-r--r--src/core/statistics/census_log.c29
-rw-r--r--src/core/statistics/census_rpc_stats.c4
-rw-r--r--src/core/statistics/census_rpc_stats.h6
-rw-r--r--src/core/statistics/census_tracing.c6
-rw-r--r--src/core/statistics/hash_table.c22
-rw-r--r--src/core/statistics/hash_table.h8
-rw-r--r--src/core/statistics/window_stats.c27
8 files changed, 52 insertions, 54 deletions
diff --git a/src/core/statistics/census_interface.h b/src/core/statistics/census_interface.h
index e870357276..c43acbd317 100644
--- a/src/core/statistics/census_interface.h
+++ b/src/core/statistics/census_interface.h
@@ -42,8 +42,8 @@
/* Structure of a census op id. Define as structure because 64bit integer is not
available on every platform for C89. */
typedef struct census_op_id {
- gpr_uint32 upper;
- gpr_uint32 lower;
+ uint32_t upper;
+ uint32_t lower;
} census_op_id;
typedef struct census_rpc_stats census_rpc_stats;
diff --git a/src/core/statistics/census_log.c b/src/core/statistics/census_log.c
index 88e338038d..257ba586a3 100644
--- a/src/core/statistics/census_log.c
+++ b/src/core/statistics/census_log.c
@@ -116,7 +116,7 @@ typedef struct census_log_block {
simultaneously by reader and writer. */
gpr_atm bytes_committed;
/* Bytes already read */
- gpr_int32 bytes_read;
+ int32_t bytes_read;
/* Links for list */
cl_block_list_struct link;
/* We want this structure to be cacheline aligned. We assume the following
@@ -124,7 +124,7 @@ typedef struct census_log_block {
type 32b size 64b size
char* 4 8
3x gpr_atm 12 24
- gpr_int32 4 8 (assumes padding)
+ int32_t 4 8 (assumes padding)
cl_block_list_struct 12 24
TOTAL 32 64
@@ -147,7 +147,7 @@ typedef struct census_log_block {
/* A list of cl_blocks, doubly-linked through cl_block::link. */
typedef struct census_log_block_list {
- gpr_int32 count; /* Number of items in list. */
+ int32_t count; /* Number of items in list. */
cl_block_list_struct ht; /* head/tail of linked list. */
} cl_block_list;
@@ -175,7 +175,7 @@ struct census_log {
/* Number of cores (aka hardware-contexts) */
unsigned num_cores;
/* number of CENSUS_LOG_2_MAX_RECORD_SIZE blocks in log */
- gpr_int32 num_blocks;
+ int32_t num_blocks;
cl_block *blocks; /* Block metadata. */
cl_core_local_block *core_local_blocks; /* Keeps core to block mappings. */
gpr_mu lock;
@@ -183,7 +183,7 @@ struct census_log {
/* Keeps the state of the reader iterator. A value of 0 indicates that
iterator has reached the end. census_log_init_reader() resets the
value to num_core to restart iteration. */
- gpr_uint32 read_iterator_state;
+ uint32_t read_iterator_state;
/* Points to the block being read. If non-NULL, the block is locked for
reading (block_being_read_->reader_lock is held). */
cl_block *block_being_read;
@@ -276,11 +276,11 @@ static void cl_block_initialize(cl_block *block, char *buffer) {
/* Guards against exposing partially written buffer to the reader. */
static void cl_block_set_bytes_committed(cl_block *block,
- gpr_int32 bytes_committed) {
+ int32_t bytes_committed) {
gpr_atm_rel_store(&block->bytes_committed, bytes_committed);
}
-static gpr_int32 cl_block_get_bytes_committed(cl_block *block) {
+static int32_t cl_block_get_bytes_committed(cl_block *block) {
return gpr_atm_acq_load(&block->bytes_committed);
}
@@ -317,7 +317,7 @@ static void cl_block_enable_access(cl_block *block) {
/* Returns with writer_lock held. */
static void *cl_block_start_write(cl_block *block, size_t size) {
- gpr_int32 bytes_committed;
+ int32_t bytes_committed;
if (!cl_try_lock(&block->writer_lock)) {
return NULL;
}
@@ -395,8 +395,7 @@ static cl_block *cl_allocate_block(void) {
- allocated a new block OR
- 'core_id' => 'old_block' mapping changed (another thread allocated a
block before lock was acquired). */
-static int cl_allocate_core_local_block(gpr_int32 core_id,
- cl_block *old_block) {
+static int cl_allocate_core_local_block(int32_t core_id, cl_block *old_block) {
/* Now that we have the lock, check if core-local mapping has changed. */
cl_core_local_block *core_local_block = &g_log.core_local_blocks[core_id];
cl_block *block = cl_core_local_block_get_block(core_local_block);
@@ -418,8 +417,8 @@ static int cl_allocate_core_local_block(gpr_int32 core_id,
}
static cl_block *cl_get_block(void *record) {
- gpr_uintptr p = (gpr_uintptr)((char *)record - g_log.buffer);
- gpr_uintptr index = p >> CENSUS_LOG_2_MAX_RECORD_SIZE;
+ uintptr_t p = (uintptr_t)((char *)record - g_log.buffer);
+ uintptr_t index = p >> CENSUS_LOG_2_MAX_RECORD_SIZE;
return &g_log.blocks[index];
}
@@ -460,7 +459,7 @@ static cl_block *cl_next_block_to_read(cl_block *prev) {
/* External functions: primary stats_log interface */
void census_log_initialize(size_t size_in_mb, int discard_old_records) {
- gpr_int32 ix;
+ int32_t ix;
/* Check cacheline alignment. */
GPR_ASSERT(sizeof(cl_block) % GPR_CACHELINE_SIZE == 0);
GPR_ASSERT(sizeof(cl_core_local_block) % GPR_CACHELINE_SIZE == 0);
@@ -510,9 +509,9 @@ void census_log_shutdown(void) {
void *census_log_start_write(size_t size) {
/* Used to bound number of times block allocation is attempted. */
- gpr_int32 attempts_remaining = g_log.num_blocks;
+ int32_t attempts_remaining = g_log.num_blocks;
/* TODO(aveitch): move this inside the do loop when current_cpu is fixed */
- gpr_int32 core_id = gpr_cpu_current_cpu();
+ int32_t core_id = gpr_cpu_current_cpu();
GPR_ASSERT(g_log.initialized);
if (size > CENSUS_LOG_MAX_RECORD_SIZE) {
return NULL;
diff --git a/src/core/statistics/census_rpc_stats.c b/src/core/statistics/census_rpc_stats.c
index d6638ed641..524a60793a 100644
--- a/src/core/statistics/census_rpc_stats.c
+++ b/src/core/statistics/census_rpc_stats.c
@@ -70,9 +70,9 @@ static int cmp_str_keys(const void *k1, const void *k2) {
}
/* TODO(hongyu): replace it with cityhash64 */
-static gpr_uint64 simple_hash(const void *k) {
+static uint64_t simple_hash(const void *k) {
size_t len = strlen(k);
- gpr_uint64 higher = gpr_murmur_hash3((const char *)k, len / 2, 0);
+ uint64_t higher = gpr_murmur_hash3((const char *)k, len / 2, 0);
return higher << 32 |
gpr_murmur_hash3((const char *)k + len / 2, len - len / 2, 0);
}
diff --git a/src/core/statistics/census_rpc_stats.h b/src/core/statistics/census_rpc_stats.h
index 5edbe9f478..8bdbc49490 100644
--- a/src/core/statistics/census_rpc_stats.h
+++ b/src/core/statistics/census_rpc_stats.h
@@ -42,9 +42,9 @@ extern "C" {
#endif
struct census_rpc_stats {
- gpr_uint64 cnt;
- gpr_uint64 rpc_error_cnt;
- gpr_uint64 app_error_cnt;
+ uint64_t cnt;
+ uint64_t rpc_error_cnt;
+ uint64_t app_error_cnt;
double elapsed_time_ms;
double api_request_bytes;
double wire_request_bytes;
diff --git a/src/core/statistics/census_tracing.c b/src/core/statistics/census_tracing.c
index ecbe27e536..dc0f8a26f5 100644
--- a/src/core/statistics/census_tracing.c
+++ b/src/core/statistics/census_tracing.c
@@ -68,14 +68,14 @@ static const census_ht_option ht_opt = {
static gpr_once g_init_mutex_once = GPR_ONCE_INIT;
static gpr_mu g_mu; /* Guards following two static variables. */
static census_ht *g_trace_store = NULL;
-static gpr_uint64 g_id = 0;
+static uint64_t g_id = 0;
static census_ht_key op_id_as_key(census_op_id *id) {
return *(census_ht_key *)id;
}
-static gpr_uint64 op_id_2_uint64(census_op_id *id) {
- gpr_uint64 ret;
+static uint64_t op_id_2_uint64(census_op_id *id) {
+ uint64_t ret;
memcpy(&ret, id, sizeof(census_op_id));
return ret;
}
diff --git a/src/core/statistics/hash_table.c b/src/core/statistics/hash_table.c
index 39b760f0e0..0cadcd4740 100644
--- a/src/core/statistics/hash_table.c
+++ b/src/core/statistics/hash_table.c
@@ -54,29 +54,29 @@ typedef struct bucket {
/* NULL if bucket is empty */
ht_entry *next;
/* -1 if all buckets are empty. */
- gpr_int32 prev_non_empty_bucket;
+ int32_t prev_non_empty_bucket;
/* -1 if all buckets are empty. */
- gpr_int32 next_non_empty_bucket;
+ int32_t next_non_empty_bucket;
} bucket;
struct unresizable_hash_table {
/* Number of entries in the table */
size_t size;
/* Number of buckets */
- gpr_uint32 num_buckets;
+ uint32_t num_buckets;
/* Array of buckets initialized at creation time. Memory consumption is
16 bytes per bucket on a 64-bit platform. */
bucket *buckets;
/* Index of the first non-empty bucket. -1 iff size == 0. */
- gpr_int32 first_non_empty_bucket;
+ int32_t first_non_empty_bucket;
/* Index of the last non_empty bucket. -1 iff size == 0. */
- gpr_int32 last_non_empty_bucket;
+ int32_t last_non_empty_bucket;
/* Immutable options of this hash table, initialized at creation time. */
census_ht_option options;
};
typedef struct entry_locator {
- gpr_int32 bucket_idx;
+ int32_t bucket_idx;
int is_first_in_chain;
int found;
ht_entry *prev_entry;
@@ -113,7 +113,7 @@ static void delete_entry(const census_ht_option *opt, ht_entry *p) {
gpr_free(p);
}
-static gpr_uint64 hash(const census_ht_option *opt, census_ht_key key) {
+static uint64_t hash(const census_ht_option *opt, census_ht_key key) {
return opt->key_type == CENSUS_HT_UINT64 ? key.val : opt->hash(key.ptr);
}
@@ -135,7 +135,7 @@ census_ht *census_ht_create(const census_ht_option *option) {
return ret;
}
-static gpr_int32 find_bucket_idx(const census_ht *ht, census_ht_key key) {
+static int32_t find_bucket_idx(const census_ht *ht, census_ht_key key) {
return hash(&ht->options, key) % ht->num_buckets;
}
@@ -149,7 +149,7 @@ static int keys_match(const census_ht_option *opt, const ht_entry *p,
static entry_locator ht_find(const census_ht *ht, census_ht_key key) {
entry_locator loc = {0, 0, 0, NULL};
- gpr_int32 idx = 0;
+ int32_t idx = 0;
ht_entry *ptr = NULL;
GPR_ASSERT(ht != NULL);
idx = find_bucket_idx(ht, key);
@@ -188,7 +188,7 @@ void *census_ht_find(const census_ht *ht, census_ht_key key) {
}
void census_ht_insert(census_ht *ht, census_ht_key key, void *data) {
- gpr_int32 idx = find_bucket_idx(ht, key);
+ int32_t idx = find_bucket_idx(ht, key);
ht_entry *ptr = NULL;
entry_locator loc = ht_find(ht, key);
if (loc.found) {
@@ -259,7 +259,7 @@ void census_ht_erase(census_ht *ht, census_ht_key key) {
census_ht_kv *census_ht_get_all_elements(const census_ht *ht, size_t *num) {
census_ht_kv *ret = NULL;
int i = 0;
- gpr_int32 idx = -1;
+ int32_t idx = -1;
GPR_ASSERT(ht != NULL && num != NULL);
*num = ht->size;
if (*num == 0) {
diff --git a/src/core/statistics/hash_table.h b/src/core/statistics/hash_table.h
index 8b39f536fd..d9860a909f 100644
--- a/src/core/statistics/hash_table.h
+++ b/src/core/statistics/hash_table.h
@@ -60,7 +60,7 @@ typedef struct unresizable_hash_table census_ht;
/* Currently, the hash_table can take two types of keys. (uint64 for trace
store and const char* for stats store). */
typedef union {
- gpr_uint64 val;
+ uint64_t val;
void *ptr;
} census_ht_key;
@@ -73,10 +73,10 @@ typedef struct census_ht_option {
/* Type of hash key */
census_ht_key_type key_type;
/* Desired number of buckets, preferably a prime number */
- gpr_int32 num_buckets;
+ int32_t num_buckets;
/* Fucntion to calculate uint64 hash value of the key. Only takes effect if
key_type is POINTER. */
- gpr_uint64 (*hash)(const void *);
+ uint64_t (*hash)(const void *);
/* Function to compare two keys, returns 0 iff equal. Only takes effect if
key_type is POINTER */
int (*compare_keys)(const void *k1, const void *k2);
@@ -126,6 +126,6 @@ typedef void (*census_ht_itr_cb)(census_ht_key key, const void *val_ptr,
/* Iterates through all key-value pairs in the hash_table. The callback function
should not invalidate data entries. */
-gpr_uint64 census_ht_for_all(const census_ht *ht, census_ht_itr_cb);
+uint64_t census_ht_for_all(const census_ht *ht, census_ht_itr_cb);
#endif /* GRPC_INTERNAL_CORE_STATISTICS_HASH_TABLE_H */
diff --git a/src/core/statistics/window_stats.c b/src/core/statistics/window_stats.c
index e744006bb5..3f2940853a 100644
--- a/src/core/statistics/window_stats.c
+++ b/src/core/statistics/window_stats.c
@@ -47,7 +47,7 @@ typedef struct census_window_stats_sum cws_sum;
/* Each interval is composed of a number of buckets, which hold a count of
entries and a single statistic */
typedef struct census_window_stats_bucket {
- gpr_int64 count;
+ int64_t count;
void *statistic;
} cws_bucket;
@@ -59,11 +59,11 @@ typedef struct census_window_stats_interval_stats {
/* Index of the bucket containing the smallest time interval. */
int bottom_bucket;
/* The smallest time storable in the current window. */
- gpr_int64 bottom;
+ int64_t bottom;
/* The largest time storable in the current window + 1ns */
- gpr_int64 top;
+ int64_t top;
/* The width of each bucket in ns. */
- gpr_int64 width;
+ int64_t width;
} cws_interval_stats;
typedef struct census_window_stats {
@@ -76,7 +76,7 @@ typedef struct census_window_stats {
/* Stats for each interval. */
cws_interval_stats *interval_stats;
/* The time the newset stat was recorded. */
- gpr_int64 newest_time;
+ int64_t newest_time;
} window_stats;
/* Calculate an actual bucket index from a logical index 'IDX'. Other
@@ -87,10 +87,9 @@ typedef struct census_window_stats {
/* The maximum seconds value we can have in a valid timespec. More than this
will result in overflow in timespec_to_ns(). This works out to ~292 years.
TODO: consider using doubles instead of int64. */
-static gpr_int64 max_seconds =
- (GPR_INT64_MAX - GPR_NS_PER_SEC) / GPR_NS_PER_SEC;
+static int64_t max_seconds = (GPR_INT64_MAX - GPR_NS_PER_SEC) / GPR_NS_PER_SEC;
-static gpr_int64 timespec_to_ns(const gpr_timespec ts) {
+static int64_t timespec_to_ns(const gpr_timespec ts) {
if (ts.tv_sec > max_seconds) {
return GPR_INT64_MAX - 1;
}
@@ -123,7 +122,7 @@ window_stats *census_window_stats_create(int nintervals,
GPR_ASSERT(nintervals > 0 && granularity > 2 && intervals != NULL &&
stat_info != NULL);
for (i = 0; i < nintervals; i++) {
- gpr_int64 ns = timespec_to_ns(intervals[i]);
+ int64_t ns = timespec_to_ns(intervals[i]);
GPR_ASSERT(intervals[i].tv_sec >= 0 && intervals[i].tv_nsec >= 0 &&
intervals[i].tv_nsec < GPR_NS_PER_SEC && ns >= 100 &&
granularity * 10 <= ns);
@@ -136,7 +135,7 @@ window_stats *census_window_stats_create(int nintervals,
ret->interval_stats =
(cws_interval_stats *)gpr_malloc(nintervals * sizeof(cws_interval_stats));
for (i = 0; i < nintervals; i++) {
- gpr_int64 size_ns = timespec_to_ns(intervals[i]);
+ int64_t size_ns = timespec_to_ns(intervals[i]);
cws_interval_stats *is = ret->interval_stats + i;
cws_bucket *buckets = is->buckets =
(cws_bucket *)gpr_malloc(ret->nbuckets * sizeof(cws_bucket));
@@ -169,7 +168,7 @@ window_stats *census_window_stats_create(int nintervals,
/* When we try adding a measurement above the current interval range, we
need to "shift" the buckets sufficiently to cover the new range. */
static void cws_shift_buckets(const window_stats *wstats,
- cws_interval_stats *is, gpr_int64 when_ns) {
+ cws_interval_stats *is, int64_t when_ns) {
int i;
/* number of bucket time widths to "shift" */
int shift;
@@ -194,7 +193,7 @@ static void cws_shift_buckets(const window_stats *wstats,
void census_window_stats_add(window_stats *wstats, const gpr_timespec when,
const void *stat_value) {
int i;
- gpr_int64 when_ns = timespec_to_ns(when);
+ int64_t when_ns = timespec_to_ns(when);
GPR_ASSERT(wstats->interval_stats != NULL);
for (i = 0; i < wstats->nintervals; i++) {
cws_interval_stats *is = wstats->interval_stats + i;
@@ -235,7 +234,7 @@ static void cws_add_proportion_to_sum(double p, cws_sum *sum,
void census_window_stats_get_sums(const window_stats *wstats,
const gpr_timespec when, cws_sum sums[]) {
int i;
- gpr_int64 when_ns = timespec_to_ns(when);
+ int64_t when_ns = timespec_to_ns(when);
GPR_ASSERT(wstats->interval_stats != NULL);
for (i = 0; i < wstats->nintervals; i++) {
int when_bucket;
@@ -264,7 +263,7 @@ void census_window_stats_get_sums(const window_stats *wstats,
when_bucket = (when_ns - is->bottom) / is->width;
new_bucket = (wstats->newest_time - is->bottom) / is->width;
if (new_bucket == when_bucket) {
- gpr_int64 bottom_bucket_time = is->bottom + when_bucket * is->width;
+ int64_t bottom_bucket_time = is->bottom + when_bucket * is->width;
if (when_ns < wstats->newest_time) {
last_proportion = (double)(when_ns - bottom_bucket_time) /
(double)(wstats->newest_time - bottom_bucket_time);