From c3d0046aad591cf024dd2914da842814fa9a883c Mon Sep 17 00:00:00 2001
From: Vladimir Davydov <vdavydov.dev@gmail.com>
Date: Mon, 26 Jun 2017 19:13:54 +0300
Subject: [PATCH] vinyl: account reads and writes per index

Add the following counters to index.info:

  lookup                # number of lookups (read iter start)
  get                   # number of statements read (read iter next)
    rows
    bytes
  put                   # number of statements written
    rows
    bytes

Needed for #1662
---
 src/box/vinyl.c   | 10 ++++++++++
 src/box/vy_stat.h |  6 ++++++
 2 files changed, 16 insertions(+)

diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 4f729a135f..47ac2565bb 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -2639,6 +2639,8 @@ vy_index_commit_stmt(struct vy_index *index, struct vy_mem *mem,
 	if (vy_stmt_type(stmt) == IPROTO_UPSERT)
 		vy_index_commit_upsert(index, mem, stmt);
 
+	vy_stmt_counter_acct_tuple(&index->stat.put, stmt);
+
 	/* Invalidate cache element. */
 	vy_cache_on_write(&index->cache, stmt, NULL);
 }
@@ -4538,6 +4540,10 @@ vy_index_info(struct vy_index *index, struct info_handler *h)
 	vy_stmt_counter_add_disk(&count, &stat->disk.count);
 	vy_info_append_stmt_counter(h, NULL, &count);
 
+	info_append_int(h, "lookup", stat->lookup);
+	vy_info_append_stmt_counter(h, "get", &stat->get);
+	vy_info_append_stmt_counter(h, "put", &stat->put);
+
 	info_table_begin(h, "memory");
 	vy_info_append_stmt_counter(h, NULL, &stat->memory.count);
 	info_table_begin(h, "iterator");
@@ -7821,6 +7827,8 @@ vy_read_iterator_start(struct vy_read_iterator *itr)
 			       itr->index->space_format,
 			       itr->index->upsert_format, itr->index->id == 0);
 	vy_read_iterator_use_range(itr);
+
+	itr->index->stat.lookup++;
 }
 
 /**
@@ -8000,6 +8008,8 @@ vy_read_iterator_next(struct vy_read_iterator *itr, struct tuple **result)
 
 	*result = itr->curr_stmt;
 	assert(*result == NULL || vy_stmt_type(*result) == IPROTO_REPLACE);
+	if (*result != NULL)
+		vy_stmt_counter_acct_tuple(&index->stat.get, *result);
 
 	/**
 	 * Add a statement to the cache
diff --git a/src/box/vy_stat.h b/src/box/vy_stat.h
index c357750906..b1fe1dde4c 100644
--- a/src/box/vy_stat.h
+++ b/src/box/vy_stat.h
@@ -111,6 +111,12 @@ struct vy_compact_stat {
 
 /** Vinyl index statistics. */
 struct vy_index_stat {
+	/** Number of lookups in the index. */
+	int64_t lookup;
+	/** Number of statements read from this index. */
+	struct vy_stmt_counter get;
+	/** Number of statements written to this index. */
+	struct vy_stmt_counter put;
 	/** Memory related statistics. */
 	struct {
 		/** Number of statements stored in memory. */
-- 
GitLab