LCOV - code coverage report
Current view: top level - src/node - caches.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 18 18
Test Date: 2024-11-04 05:10:19 Functions: 100.0 % 1 1
Branches: 65.0 % 20 13

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2021-2022 The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <node/caches.h>
       6                 :             : 
       7                 :             : #include <common/args.h>
       8                 :             : #include <index/txindex.h>
       9                 :             : #include <txdb.h>
      10                 :             : 
      11                 :             : namespace node {
      12                 :        1082 : CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
      13                 :             : {
      14         [ +  - ]:        1082 :     int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20);
      15         [ +  - ]:        1082 :     nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
      16                 :        1082 :     CacheSizes sizes;
      17         [ -  + ]:        1082 :     sizes.block_tree_db = std::min(nTotalCache / 8, nMaxBlockDBCache << 20);
      18                 :        1082 :     nTotalCache -= sizes.block_tree_db;
      19   [ +  -  +  +  :        2164 :     sizes.tx_index = std::min(nTotalCache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? nMaxTxIndexCache << 20 : 0);
                   +  + ]
      20                 :        1082 :     nTotalCache -= sizes.tx_index;
      21                 :        1082 :     sizes.filter_index = 0;
      22         [ +  + ]:        1082 :     if (n_indexes > 0) {
      23         [ +  - ]:          58 :         int64_t max_cache = std::min(nTotalCache / 8, max_filter_index_cache << 20);
      24                 :          58 :         sizes.filter_index = max_cache / n_indexes;
      25                 :          58 :         nTotalCache -= sizes.filter_index * n_indexes;
      26                 :             :     }
      27         [ -  + ]:        1082 :     sizes.coins_db = std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); // use 25%-50% of the remainder for disk cache
      28         [ -  + ]:        1082 :     sizes.coins_db = std::min(sizes.coins_db, nMaxCoinsDBCache << 20); // cap total coins db cache
      29                 :        1082 :     nTotalCache -= sizes.coins_db;
      30                 :        1082 :     sizes.coins = nTotalCache; // the rest goes to in-memory cache
      31                 :        1082 :     return sizes;
      32                 :             : }
      33                 :             : } // namespace node
        

Generated by: LCOV version 2.0-1