ClickHouse/dbms/src/DataStreams/IProfilingBlockInputStream.cpp

65 lines
1.5 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();
2011-09-05 00:51:25 +00:00
if (column_names.empty())
column_names = block.dumpNames();
2011-08-27 22:43:31 +00:00
}
void BlockStreamProfileInfo::print(std::ostream & ostr) const
{
ostr << std::fixed << std::setprecision(2)
2011-09-05 00:51:25 +00:00
<< "Columns: " << column_names << std::endl
2011-09-05 00:32:22 +00:00
<< "Elapsed: " << work_stopwatch.elapsed() / 1000000.0 << " sec. "
<< "(" << work_stopwatch.elapsed() * 100.0 / total_stopwatch.elapsed() << "%), " << std::endl
2011-08-27 22:43:31 +00:00
<< "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
2011-09-05 00:32:22 +00:00
<< "Average block size: " << rows / blocks << "." << std::endl;
2011-08-27 22:43:31 +00:00
}
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);
2011-09-25 03:37:09 +00:00
2011-09-25 05:07:47 +00:00
/* if (res)
2011-09-25 03:37:09 +00:00
{
std::cerr << std::endl;
std::cerr << getName() << std::endl;
getInfo().print(std::cerr);
2011-09-25 05:07:47 +00:00
}*/
2011-09-25 03:37:09 +00:00
2011-08-27 22:43:31 +00:00
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;
}
}