dbms: added profile events for AIO and ordinary IO [#METR-15090].

This commit is contained in:
Alexey Milovidov 2015-04-16 15:06:05 +03:00
parent 456b10a02b
commit 4c703cbfd7
7 changed files with 46 additions and 3 deletions

View File

@ -14,6 +14,13 @@
M(FileOpen) \
M(Seek) \
M(ReadBufferFromFileDescriptorRead) \
M(ReadBufferFromFileDescriptorReadBytes) \
M(WriteBufferFromFileDescriptorWrite) \
M(WriteBufferFromFileDescriptorWriteBytes) \
M(ReadBufferAIORead) \
M(ReadBufferAIOReadBytes) \
M(WriteBufferAIOWrite) \
M(WriteBufferAIOWriteBytes) \
M(ReadCompressedBytes) \
M(CompressedReadBufferBlocks) \
M(CompressedReadBufferBytes) \
@ -27,6 +34,10 @@
M(FunctionExecute) \
M(MarkCacheHits) \
M(MarkCacheMisses) \
M(CreatedReadBufferOrdinary) \
M(CreatedReadBufferAIO) \
M(CreatedWriteBufferOrdinary) \
M(CreatedWriteBufferAIO) \
\
M(ReplicatedPartFetches) \
M(ReplicatedPartFailedFetches) \

View File

@ -24,7 +24,7 @@ class ReadBufferFromFileDescriptor : public ReadBufferFromFileBase
protected:
int fd;
off_t pos_in_file; /// Какому сдвигу в файле соответствует working_buffer.end().
bool nextImpl()
{
size_t bytes_read = 0;
@ -35,7 +35,7 @@ protected:
ssize_t res = ::read(fd, internal_buffer.begin(), internal_buffer.size());
if (!res)
break;
if (-1 == res && errno != EINTR)
throwFromErrno("Cannot read from file " + getFileName(), ErrorCodes::CANNOT_READ_FROM_FILE_DESCRIPTOR);
@ -46,7 +46,10 @@ protected:
pos_in_file += bytes_read;
if (bytes_read)
{
ProfileEvents::increment(ProfileEvents::ReadBufferFromFileDescriptorReadBytes, bytes_read);
working_buffer.resize(bytes_read);
}
else
return false;

View File

@ -5,6 +5,7 @@
#include <DB/Core/Exception.h>
#include <DB/Core/ErrorCodes.h>
#include <DB/Common/ProfileEvents.h>
#include <DB/IO/WriteBufferFromFileBase.h>
#include <DB/IO/WriteBuffer.h>
@ -21,7 +22,7 @@ class WriteBufferFromFileDescriptor : public WriteBufferFromFileBase
{
protected:
int fd;
void nextImpl()
{
if (!offset())
@ -30,6 +31,8 @@ protected:
size_t bytes_written = 0;
while (bytes_written != offset())
{
ProfileEvents::increment(ProfileEvents::WriteBufferFromFileDescriptorWrite);
ssize_t res = ::write(fd, working_buffer.begin() + bytes_written, offset() - bytes_written);
if ((-1 == res || 0 == res) && errno != EINTR)
@ -38,6 +41,8 @@ protected:
if (res > 0)
bytes_written += res;
}
ProfileEvents::increment(ProfileEvents::WriteBufferFromFileDescriptorWriteBytes, bytes_written);
}
/// Имя или описание файла

View File

@ -151,6 +151,10 @@ void ReadBufferAIO::synchronousRead()
{
prepare();
bytes_read = ::pread(fd, buffer_begin, region_aligned_size, region_aligned_begin);
ProfileEvents::increment(ProfileEvents::ReadBufferAIORead);
ProfileEvents::increment(ProfileEvents::ReadBufferAIOReadBytes, bytes_read);
finalize();
}
@ -190,6 +194,9 @@ bool ReadBufferAIO::waitForAIOCompletion()
is_pending_read = false;
bytes_read = events[0].res;
ProfileEvents::increment(ProfileEvents::ReadBufferAIORead);
ProfileEvents::increment(ProfileEvents::ReadBufferAIOReadBytes, bytes_read);
return true;
}

View File

@ -175,6 +175,9 @@ bool WriteBufferAIO::waitForAIOCompletion()
is_pending_write = false;
bytes_written = events[0].res;
ProfileEvents::increment(ProfileEvents::WriteBufferAIOWrite);
ProfileEvents::increment(ProfileEvents::WriteBufferAIOWriteBytes, bytes_written);
return true;
}

View File

@ -1,6 +1,7 @@
#include <DB/IO/createReadBufferFromFileBase.h>
#include <DB/IO/ReadBufferFromFile.h>
#include <DB/IO/ReadBufferAIO.h>
#include <DB/Common/ProfileEvents.h>
namespace DB
{
@ -9,9 +10,15 @@ ReadBufferFromFileBase * createReadBufferFromFileBase(const std::string & filena
size_t aio_threshold, size_t buffer_size_, int flags_, char * existing_memory_, size_t alignment)
{
if ((aio_threshold == 0) || (estimated_size < aio_threshold))
{
ProfileEvents::increment(ProfileEvents::CreatedReadBufferOrdinary);
return new ReadBufferFromFile(filename_, buffer_size_, flags_, existing_memory_, alignment);
}
else
{
ProfileEvents::increment(ProfileEvents::CreatedReadBufferAIO);
return new ReadBufferAIO(filename_, buffer_size_, flags_, existing_memory_);
}
}
}

View File

@ -1,6 +1,7 @@
#include <DB/IO/createWriteBufferFromFileBase.h>
#include <DB/IO/WriteBufferFromFile.h>
#include <DB/IO/WriteBufferAIO.h>
#include <DB/Common/ProfileEvents.h>
namespace DB
{
@ -10,9 +11,15 @@ WriteBufferFromFileBase * createWriteBufferFromFileBase(const std::string & file
size_t alignment)
{
if ((aio_threshold == 0) || (estimated_size < aio_threshold))
{
ProfileEvents::increment(ProfileEvents::CreatedWriteBufferOrdinary);
return new WriteBufferFromFile(filename_, buffer_size_, flags_, mode, existing_memory_, alignment);
}
else
{
ProfileEvents::increment(ProfileEvents::CreatedWriteBufferAIO);
return new WriteBufferAIO(filename_, buffer_size_, flags_, mode, existing_memory_);
}
}
}