2015-03-30 15:39:55 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
#include <DB/IO/ReadBuffer.h>
|
|
|
|
|
#include <DB/IO/BufferWithOwnMemory.h>
|
|
|
|
|
|
2016-10-26 22:27:38 +00:00
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
#include <common/apple_rt.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-03-30 15:39:55 +00:00
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class ReadBufferFromFileBase : public BufferWithOwnMemory<ReadBuffer>
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-04-03 13:45:44 +00:00
|
|
|
|
ReadBufferFromFileBase(size_t buf_size, char * existing_memory, size_t alignment);
|
|
|
|
|
virtual ~ReadBufferFromFileBase();
|
|
|
|
|
off_t seek(off_t off, int whence = SEEK_SET);
|
2015-03-30 15:39:55 +00:00
|
|
|
|
virtual off_t getPositionInFile() = 0;
|
2015-04-14 11:35:10 +00:00
|
|
|
|
virtual std::string getFileName() const = 0;
|
|
|
|
|
virtual int getFD() const = 0;
|
2015-04-03 13:45:44 +00:00
|
|
|
|
|
2015-12-13 04:52:13 +00:00
|
|
|
|
/// Есть возможность получать информацию о времени каждого чтения.
|
|
|
|
|
struct ProfileInfo
|
|
|
|
|
{
|
|
|
|
|
size_t bytes_requested;
|
|
|
|
|
size_t bytes_read;
|
|
|
|
|
size_t nanoseconds;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using ProfileCallback = std::function<void(ProfileInfo)>;
|
|
|
|
|
|
|
|
|
|
/// CLOCK_MONOTONIC_COARSE более чем достаточно для отслеживания долгих чтений - например, залипаний на секунды.
|
|
|
|
|
void setProfileCallback(const ProfileCallback & profile_callback_, clockid_t clock_type_ = CLOCK_MONOTONIC_COARSE)
|
|
|
|
|
{
|
|
|
|
|
profile_callback = profile_callback_;
|
|
|
|
|
clock_type = clock_type_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-03 13:45:44 +00:00
|
|
|
|
protected:
|
2015-12-13 04:52:13 +00:00
|
|
|
|
ProfileCallback profile_callback;
|
|
|
|
|
clockid_t clock_type;
|
|
|
|
|
|
2015-04-03 13:45:44 +00:00
|
|
|
|
virtual off_t doSeek(off_t off, int whence) = 0;
|
2015-03-30 15:39:55 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|