You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2022/08/08 22:48:38 UTC
[couchdb] 02/03: Add btree cost
This is an automated email from the ASF dual-hosted git repository.
chewbranca pushed a commit to branch cost-counting
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit d9c0e894243ca4ef9dec988979ccf714cf6fc6eb
Author: Russell Branca <ch...@apache.org>
AuthorDate: Thu Jul 21 13:03:28 2022 -0700
Add btree cost
---
src/couch/src/couch_btree.erl | 1 +
src/couch/src/couch_cost.erl | 22 ++++++++++++++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/couch/src/couch_btree.erl b/src/couch/src/couch_btree.erl
index b974a22ee..2c75287ee 100644
--- a/src/couch/src/couch_btree.erl
+++ b/src/couch/src/couch_btree.erl
@@ -1077,6 +1077,7 @@ stream_node(Bt, Reds, Node, StartKey, InRange, Dir, Fun, Acc) ->
stream_node(Bt, Reds, Node, InRange, Dir, Fun, Acc) ->
Pointer = element(1, Node),
{NodeType, NodeList} = get_node(Bt, Pointer),
+ couch_cost:inc_get_node(NodeType),
case NodeType of
kp_node ->
stream_kp_node(Bt, Reds, adjust_dir(Dir, NodeList), InRange, Dir, Fun, Acc);
diff --git a/src/couch/src/couch_cost.erl b/src/couch/src/couch_cost.erl
index b37f34381..25929501d 100644
--- a/src/couch/src/couch_cost.erl
+++ b/src/couch/src/couch_cost.erl
@@ -2,7 +2,8 @@
-export([
inc_doc/0, inc_doc/1, inc_doc/2,
- inc_ioq/0, inc_ioq/1, inc_ioq/2%%,
+ inc_ioq/0, inc_ioq/1, inc_ioq/2,
+ inc_get_node/1
%%io_bytes_read/1, io_bytes_read/2,
%%io_bytes_written/1, io_bytes_written/2,
%%inc_js_evals/0, inc_js_evals/1, inc_js_evals/2
@@ -17,7 +18,9 @@
ioq_calls = 0,
io_bytes_read = 0,
io_bytes_written = 0,
- js_evals = 0
+ js_evals = 0,
+ get_kv_node = 0,
+ get_kp_node = 0
}).
get_cost() ->
@@ -40,3 +43,18 @@ inc_doc(N, #cost{docs_read=DR0}=Cost) -> update_cost(Cost#cost{docs_read=DR0+N})
inc_ioq() -> inc_ioq(1).
inc_ioq(N) -> inc_ioq(N, get_cost()).
inc_ioq(N, #cost{ioq_calls=IOQ0}=Cost) -> update_cost(Cost#cost{ioq_calls=IOQ0+N}).
+
+
+inc_get_node(Type) when Type =:= kp_node orelse Type =:= kv_node ->
+%%inc_get_node(Type) when Type =:= kp_node; Type =:= kv_node ->
+ update_cost(inc(Type, get_cost())).
+
+
+inc(Key, Cost) ->
+ inc(Key, Cost, 1).
+
+
+inc(kp_node, #cost{get_kp_node=GKP}=Cost, N) ->
+ Cost#cost{get_kp_node = GKP + N};
+inc(kv_node, #cost{get_kv_node=GKV}=Cost, N) ->
+ Cost#cost{get_kp_node = GKV + N}.