ClickHouse/dbms/IO/ReadBufferFromFileBase.h

47 lines
1.2 KiB
C++
Raw Normal View History

#pragma once
2020-02-17 14:27:09 +00:00
#include <IO/BufferWithOwnMemory.h>
#include <IO/SeekableReadBuffer.h>
#include <common/time.h>
#include <functional>
2020-02-14 14:28:33 +00:00
#include <string>
2020-02-17 14:27:09 +00:00
#include <fcntl.h>
2020-02-17 14:27:09 +00:00
namespace DB
{
class ReadBufferFromFileBase : public BufferWithOwnMemory<SeekableReadBuffer>
{
public:
ReadBufferFromFileBase();
ReadBufferFromFileBase(size_t buf_size, char * existing_memory, size_t alignment);
ReadBufferFromFileBase(ReadBufferFromFileBase &&) = default;
2018-06-13 02:52:03 +00:00
~ReadBufferFromFileBase() override;
virtual std::string getFileName() const = 0;
2017-05-28 14:29:40 +00:00
/// It is possible to get information about the time of each reading.
struct ProfileInfo
{
size_t bytes_requested;
size_t bytes_read;
size_t nanoseconds;
};
using ProfileCallback = std::function<void(ProfileInfo)>;
2017-05-28 14:29:40 +00:00
/// CLOCK_MONOTONIC_COARSE is more than enough to track long reads - for example, hanging for a second.
void setProfileCallback(const ProfileCallback & profile_callback_, clockid_t clock_type_ = CLOCK_MONOTONIC_COARSE)
{
profile_callback = profile_callback_;
clock_type = clock_type_;
}
protected:
ProfileCallback profile_callback;
2019-06-16 18:12:14 +00:00
clockid_t clock_type{};
};
}