aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/util/drainingbufferwriter.h
blob: 59430ec863ddf332a660e6b1b27e9090bdd86304 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "bufferwriter.h"
#include <vector>
#include <cstdint>

namespace search {

/**
 * Class to write to a "drain" buffer, used to measure performance of
 * BufferWriter and measure number of bytes written.
 */
class DrainingBufferWriter : public BufferWriter
{
    std::vector<char> _buf;
    size_t _bytesWritten;
    uint32_t _incompleteBuffers;
public:
    static constexpr size_t BUFFER_SIZE = 262144;

    DrainingBufferWriter();
    ~DrainingBufferWriter() override;
    void flush() override;
    size_t getBytesWritten() const { return _bytesWritten; }
};

} // namespace search