ClickHouse/dbms/src/DataStreams/IProfilingBlockInputStream.cpp

54 lines
1.3 KiB
C++
Raw Normal View History

2011-08-27 22:43:31 +00:00
#include <iomanip>
2011-09-04 21:23:19 +00:00
#include <DB/DataStreams/IProfilingBlockInputStream.h>
2011-08-27 22:43:31 +00:00
namespace DB
{
void BlockStreamProfileInfo::update(Block & block)
{
++blocks;
rows += block.rows();
for (size_t i = 0; i < block.columns(); ++i)
bytes += block.getByPosition(i).column->byteSize();
}
void BlockStreamProfileInfo::print(std::ostream & ostr) const
{
ostr << std::fixed << std::setprecision(2)
<< "Elapsed: " << work_stopwatch.elapsed() / 1000000.0 << " sec., " << std::endl
<< "Rows: " << rows << ", per second: " << rows * 1000000 / work_stopwatch.elapsed() << ", " << std::endl
<< "Blocks: " << blocks << ", per second: " << blocks * 1000000.0 / work_stopwatch.elapsed() << ", " << std::endl
<< bytes / 1000000.0 << " MB (memory), " << bytes / work_stopwatch.elapsed() << " MB/s (memory), " << std::endl
<< "Average block size: " << rows / blocks << "." << std::endl
<< "Idle time: " << (total_stopwatch.elapsed() - work_stopwatch.elapsed()) * 100.0 / total_stopwatch.elapsed() << "%" << std::endl;
}
2011-09-04 21:23:19 +00:00
Block IProfilingBlockInputStream::read()
2011-08-27 22:43:31 +00:00
{
if (!info.started)
info.total_stopwatch.start();
info.work_stopwatch.start();
2011-09-04 21:23:19 +00:00
Block res = readImpl();
2011-08-27 22:43:31 +00:00
info.work_stopwatch.stop();
if (res)
info.update(res);
return res;
}
2011-09-04 21:23:19 +00:00
const BlockStreamProfileInfo & IProfilingBlockInputStream::getInfo() const
2011-08-27 22:43:31 +00:00
{
return info;
}
}