From ab4e9e9b1ae64c196e54d284004a7b4f067082f3 Mon Sep 17 00:00:00 2001 From: Vladimir Davydov <vdavydov.dev@gmail.com> Date: Wed, 14 Jun 2017 17:26:53 +0300 Subject: [PATCH] box: replace info_append_{u32,u64} with info_append_int It's no use having a separate method for every kind of integer we want to append to box info - int64_t should suit everyone. --- src/box/info.h | 35 +++++++------------------ src/box/lua/info.c | 19 +++----------- src/box/vinyl.c | 64 +++++++++++++++++++++++----------------------- 3 files changed, 45 insertions(+), 73 deletions(-) diff --git a/src/box/info.h b/src/box/info.h index a8f54325d2..df82becd52 100644 --- a/src/box/info.h +++ b/src/box/info.h @@ -43,9 +43,9 @@ * * { -- info_begin * section = { -- info_begin_table - * key1 = u32; -- info_append_u32 - * key2 = u64; -- info_append_u64 - * key3 = str; -- info_append_str; + * key1 = int; -- info_append_int + * key2 = double; -- info_append_double + * key3 = str; -- info_append_str * }; -- info_end_table * * section2 = { @@ -83,12 +83,9 @@ struct info_handler_vtab { /** Set string value. */ void (*append_str)(struct info_handler *, const char *key, const char *value); - /** Set uint32_t value. */ - void (*append_u32)(struct info_handler *, const char *key, - uint32_t value); - /** Set uint64_t value. */ - void (*append_u64)(struct info_handler *, const char *key, - uint64_t value); + /** Set int64_t value. */ + void (*append_int)(struct info_handler *, const char *key, + int64_t value); /** Set double value. */ void (*append_double)(struct info_handler *, const char *key, double value); @@ -128,7 +125,7 @@ info_end(struct info_handler *info) } /** - * Associates uint32_t value with @a key in the current associative array. + * Associates int64_t value with @a key in the current associative array. * @param info box.info() adapter. * @param key key. * @param value value. @@ -136,23 +133,9 @@ info_end(struct info_handler *info) * @pre associative array is started. */ static inline void -info_append_u32(struct info_handler *info, const char *key, uint32_t value) +info_append_int(struct info_handler *info, const char *key, int64_t value) { - return info->vtab->append_u32(info, key, value); -} - -/** - * Associates uint64_t value with @a key in the current associative array. - * @param info box.info() adapter. - * @param key key. - * @param value value. - * @throws C++ exception on OOM, see info.h comments. - * @pre associative array is started. - */ -static inline void -info_append_u64(struct info_handler *info, const char *key, uint64_t value) -{ - return info->vtab->append_u64(info, key, value); + return info->vtab->append_int(info, key, value); } /** diff --git a/src/box/lua/info.c b/src/box/lua/info.c index 90041853ad..9ce80c022a 100644 --- a/src/box/lua/info.c +++ b/src/box/lua/info.c @@ -318,22 +318,12 @@ luaT_info_append_double(struct info_handler *info, } static void -luaT_info_append_u32(struct info_handler *info, const char *key, - uint32_t value) +luaT_info_append_int(struct info_handler *info, const char *key, + int64_t value) { lua_State *L = (lua_State *) info->ctx; lua_pushstring(L, key); - lua_pushnumber(L, value); - lua_settable(L, -3); -} - -static void -luaT_info_append_u64(struct info_handler *info, const char *key, - uint64_t value) -{ - lua_State *L = (lua_State *) info->ctx; - lua_pushstring(L, key); - luaL_pushuint64(L, value); + luaL_pushint64(L, value); lua_settable(L, -3); } @@ -355,8 +345,7 @@ luaT_info_handler_create(struct info_handler *h, struct lua_State *L) .end = luaT_info_end, .begin_table = luaT_info_begin_table, .end_table = luaT_info_end_table, - .append_u32 = luaT_info_append_u32, - .append_u64 = luaT_info_append_u64, + .append_int = luaT_info_append_int, .append_str = luaT_info_append_str, .append_double = luaT_info_append_double }; diff --git a/src/box/vinyl.c b/src/box/vinyl.c index 8392abd1ef..cead64c9a8 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -4390,9 +4390,9 @@ vy_info_append_memory(struct vy_env *env, struct info_handler *h) char buf[16]; struct vy_quota *q = &env->quota; info_table_begin(h, "memory"); - info_append_u64(h, "used", q->used); - info_append_u64(h, "limit", q->limit); - info_append_u64(h, "watermark", q->watermark); + info_append_int(h, "used", q->used); + info_append_int(h, "limit", q->limit); + info_append_int(h, "watermark", q->watermark); snprintf(buf, sizeof(buf), "%d%%", (int)(100 * q->used / q->limit)); info_append_str(h, "ratio", buf); info_table_end(h); @@ -4403,8 +4403,8 @@ vy_info_append_stat_rmean(const char *name, int rps, int64_t total, void *ctx) { struct info_handler *h = ctx; info_table_begin(h, name); - info_append_u32(h, "rps", rps); - info_append_u64(h, "total", total); + info_append_int(h, "rps", rps); + info_append_int(h, "total", total); info_table_end(h); return 0; } @@ -4414,8 +4414,8 @@ vy_info_append_stat_latency(struct info_handler *h, const char *name, struct vy_latency *lat) { info_table_begin(h, name); - info_append_u64(h, "max", lat->max * 1000000000); - info_append_u64(h, "avg", lat->count == 0 ? 0 : + info_append_int(h, "max", lat->max * 1000000000); + info_append_int(h, "avg", lat->count == 0 ? 0 : lat->total / lat->count * 1000000000); info_table_end(h); } @@ -4425,9 +4425,9 @@ vy_info_append_iterator_stat(struct info_handler *h, const char *name, struct vy_iterator_stat *stat) { info_table_begin(h, name); - info_append_u64(h, "lookup_count", stat->lookup_count); - info_append_u64(h, "step_count", stat->step_count); - info_append_u64(h, "bloom_reflect_count", stat->bloom_reflections); + info_append_int(h, "lookup_count", stat->lookup_count); + info_append_int(h, "step_count", stat->step_count); + info_append_int(h, "bloom_reflect_count", stat->bloom_reflections); info_table_end(h); } @@ -4440,32 +4440,32 @@ vy_info_append_performance(struct vy_env *env, struct info_handler *h) rmean_foreach(stat->rmean, vy_info_append_stat_rmean, h); - info_append_u64(h, "write_count", stat->write_count); + info_append_int(h, "write_count", stat->write_count); vy_info_append_stat_latency(h, "tx_latency", &stat->tx_latency); vy_info_append_stat_latency(h, "get_latency", &stat->get_latency); vy_info_append_stat_latency(h, "cursor_latency", &stat->cursor_latency); - info_append_u64(h, "tx_rollback", stat->tx_rlb); - info_append_u64(h, "tx_conflict", stat->tx_conflict); - info_append_u32(h, "tx_active", env->xm->tx_count); + info_append_int(h, "tx_rollback", stat->tx_rlb); + info_append_int(h, "tx_conflict", stat->tx_conflict); + info_append_int(h, "tx_active", env->xm->tx_count); struct mempool_stats mstats; mempool_stats(&env->xm->tx_mempool, &mstats); - info_append_u32(h, "tx_allocated", mstats.objcount); + info_append_int(h, "tx_allocated", mstats.objcount); mempool_stats(&env->xm->txv_mempool, &mstats); - info_append_u32(h, "txv_allocated", mstats.objcount); + info_append_int(h, "txv_allocated", mstats.objcount); mempool_stats(&env->xm->read_view_mempool, &mstats); - info_append_u32(h, "read_view", mstats.objcount); + info_append_int(h, "read_view", mstats.objcount); - info_append_u64(h, "dump_bandwidth", vy_stat_dump_bandwidth(stat)); - info_append_u64(h, "dump_total", stat->dump_total); - info_append_u64(h, "dumped_statements", stat->dumped_statements); + info_append_int(h, "dump_bandwidth", vy_stat_dump_bandwidth(stat)); + info_append_int(h, "dump_total", stat->dump_total); + info_append_int(h, "dumped_statements", stat->dumped_statements); struct vy_cache_env *ce = &env->cache_env; info_table_begin(h, "cache"); - info_append_u64(h, "count", ce->cached_count); - info_append_u64(h, "used", ce->quota.used); + info_append_int(h, "count", ce->cached_count); + info_append_int(h, "used", ce->quota.used); info_table_end(h); info_table_begin(h, "iterator"); @@ -4484,7 +4484,7 @@ vy_info(struct vy_env *env, struct info_handler *h) info_begin(h); vy_info_append_memory(env, h); vy_info_append_performance(env, h); - info_append_u64(h, "lsn", env->xm->lsn); + info_append_int(h, "lsn", env->xm->lsn); info_end(h); } @@ -4493,15 +4493,15 @@ vy_index_info(struct vy_index *index, struct info_handler *h) { char buf[1024]; info_begin(h); - info_append_u64(h, "range_size", index->opts.range_size); - info_append_u64(h, "page_size", index->opts.page_size); - info_append_u64(h, "memory_used", index->mem_used); - info_append_u64(h, "size", index->size); - info_append_u64(h, "count", index->stmt_count); - info_append_u32(h, "page_count", index->page_count); - info_append_u32(h, "range_count", index->range_count); - info_append_u32(h, "run_count", index->run_count); - info_append_u32(h, "run_avg", index->run_count / index->range_count); + info_append_int(h, "range_size", index->opts.range_size); + info_append_int(h, "page_size", index->opts.page_size); + info_append_int(h, "memory_used", index->mem_used); + info_append_int(h, "size", index->size); + info_append_int(h, "count", index->stmt_count); + info_append_int(h, "page_count", index->page_count); + info_append_int(h, "range_count", index->range_count); + info_append_int(h, "run_count", index->run_count); + info_append_int(h, "run_avg", index->run_count / index->range_count); histogram_snprint(buf, sizeof(buf), index->run_hist); info_append_str(h, "run_histogram", buf); info_append_double(h, "bloom_fpr", index->opts.bloom_fpr); -- GitLab