aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/util/searchable_stats.h
blob: e785a4c44833ddc3eaebe904ff87b62d39ce2981 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/vespalib/util/memoryusage.h>

namespace search {

/**
 * Simple statistics for a single Searchable component or multiple components that are merged together.
 *
 * E.g. used for internal aggregation before inserting numbers into the metrics framework.
 **/
class SearchableStats
{
private:
    vespalib::MemoryUsage _memoryUsage;
    size_t _docsInMemory;
    size_t _sizeOnDisk; // in bytes
    size_t _fusion_size_on_disk; // in bytes

public:
    SearchableStats() : _memoryUsage(), _docsInMemory(0), _sizeOnDisk(0), _fusion_size_on_disk(0) {}
    SearchableStats &memoryUsage(const vespalib::MemoryUsage &usage) {
        _memoryUsage = usage;
        return *this;
    }
    const vespalib::MemoryUsage &memoryUsage() const { return _memoryUsage; }
    SearchableStats &docsInMemory(size_t value) {
        _docsInMemory = value;
        return *this;
    }
    size_t docsInMemory() const { return _docsInMemory; }
    SearchableStats &sizeOnDisk(size_t value) {
        _sizeOnDisk = value;
        return *this;
    }
    size_t sizeOnDisk() const { return _sizeOnDisk; }
    SearchableStats& fusion_size_on_disk(size_t value) {
        _fusion_size_on_disk = value;
        return *this;
    }
    size_t fusion_size_on_disk() const { return _fusion_size_on_disk; }

    SearchableStats &merge(const SearchableStats &rhs) {
        _memoryUsage.merge(rhs._memoryUsage);
        _docsInMemory += rhs._docsInMemory;
        _sizeOnDisk += rhs._sizeOnDisk;
        _fusion_size_on_disk += rhs._fusion_size_on_disk;
        return *this;
    }
};

} // namespace search