summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Branca <chewbranca@apache.org>2022-08-08 15:55:07 -0700
committerRussell Branca <chewbranca@apache.org>2022-08-08 15:55:07 -0700
commitdce7a7805a15540dada34d88b3781ef581220160 (patch)
treea1b8410cba3ea7338d4325794ddcde0756965ccd
parent94341d283c4bad1951d92edd4b970c16cfba4eed (diff)
downloadcouchdb-cost-counting.tar.gz
Whitespacecost-counting
-rw-r--r--src/couch/src/couch_cost.erl6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/couch/src/couch_cost.erl b/src/couch/src/couch_cost.erl
index ebb25cf8f..243748cf7 100644
--- a/src/couch/src/couch_cost.erl
+++ b/src/couch/src/couch_cost.erl
@@ -34,6 +34,7 @@
get_kp_node = 0
}).
+
get_cost() ->
case get(cost_accounting_context) of
undefined ->
@@ -44,6 +45,7 @@ get_cost() ->
Cost
end.
+
get_costs() ->
case get(cost_accounting_context_aggregation) of
undefined ->
@@ -54,17 +56,21 @@ get_costs() ->
Costs
end.
+
update_cost(#cost{}=Cost) ->
put(cost_accounting_context, Cost).
+
accumulate_costs(#cost{}=Cost) ->
Costs = get_costs(),
put(cost_accounting_context_aggregation, [Cost | Costs]).
+
inc_doc() -> inc_doc(1).
inc_doc(N) -> inc_doc(N, get_cost()).
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}).