ClickHouse/dbms/src/IO/ReadBufferFromFileBase.h

50 lines
1.3 KiB
C++
Raw Normal View History

#pragma once
#include <string>
2017-01-17 18:03:32 +00:00
#include <ctime>
#include <functional>
#include <fcntl.h>
#include <IO/ReadBuffer.h>
#include <IO/BufferWithOwnMemory.h>
#include <port/clock.h>
#include "SeekableReadBuffer.h"
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 off_t getPositionInFile() = 0;
virtual std::string getFileName() const = 0;
virtual int getFD() 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{};
};
}