2015-03-30 15:39:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-17 14:27:09 +00:00
|
|
|
#include <IO/BufferWithOwnMemory.h>
|
|
|
|
#include <IO/SeekableReadBuffer.h>
|
|
|
|
#include <common/time.h>
|
|
|
|
|
2017-04-11 12:57:31 +00:00
|
|
|
#include <functional>
|
2020-02-14 14:28:33 +00:00
|
|
|
#include <string>
|
2020-02-17 14:27:09 +00:00
|
|
|
|
2015-03-30 15:39:55 +00:00
|
|
|
#include <fcntl.h>
|
2020-02-17 14:27:09 +00:00
|
|
|
|
2016-10-26 22:27:38 +00:00
|
|
|
|
2015-03-30 15:39:55 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2020-01-22 16:17:25 +00:00
|
|
|
class ReadBufferFromFileBase : public BufferWithOwnMemory<SeekableReadBuffer>
|
2015-03-30 15:39:55 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-01-04 05:46:50 +00:00
|
|
|
ReadBufferFromFileBase();
|
2017-04-01 07:20:54 +00:00
|
|
|
ReadBufferFromFileBase(size_t buf_size, char * existing_memory, size_t alignment);
|
2017-08-30 20:23:29 +00:00
|
|
|
ReadBufferFromFileBase(ReadBufferFromFileBase &&) = default;
|
2018-06-13 02:52:03 +00:00
|
|
|
~ReadBufferFromFileBase() override;
|
2017-04-01 07:20:54 +00:00
|
|
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
void setProfileCallback(const ProfileCallback & profile_callback_, clockid_t clock_type_ = CLOCK_MONOTONIC_COARSE)
|
|
|
|
{
|
|
|
|
profile_callback = profile_callback_;
|
|
|
|
clock_type = clock_type_;
|
|
|
|
}
|
2015-12-13 04:52:13 +00:00
|
|
|
|
2015-04-03 13:45:44 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
ProfileCallback profile_callback;
|
2019-06-16 18:12:14 +00:00
|
|
|
clockid_t clock_type{};
|
2015-03-30 15:39:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|