Send log message about peak memory usage to client #3230

This commit is contained in:
Alexey Milovidov 2018-09-27 00:19:49 +03:00
parent 99927a3518
commit 30da8de1b6
3 changed files with 14 additions and 3 deletions

View File

@ -199,8 +199,10 @@ void TCPHandler::runImpl()
else
processOrdinaryQuery();
sendLogs();
/// Do it before sending end of stream, to have a chance to show log message in client.
query_scope->logPeakMemoryUsage();
sendLogs();
sendEndOfStream();
query_scope.reset();

View File

@ -80,6 +80,9 @@ public:
{
explicit QueryScope(Context & query_context);
~QueryScope();
void logPeakMemoryUsage();
bool log_peak_memory_usage_in_destructor = true;
};
/// Implicitly finalizes current thread in the destructor

View File

@ -237,12 +237,18 @@ CurrentThread::QueryScope::QueryScope(Context & query_context)
CurrentThread::attachQueryContext(query_context);
}
void CurrentThread::QueryScope::logPeakMemoryUsage()
{
log_peak_memory_usage_in_destructor = false;
CurrentThread::getGroup()->memory_tracker.logPeakMemoryUsage();
}
CurrentThread::QueryScope::~QueryScope()
{
try
{
/// For better logging ({query_id} will be shown here)
CurrentThread::getGroup()->memory_tracker.logPeakMemoryUsage();
if (log_peak_memory_usage_in_destructor)
logPeakMemoryUsage();
CurrentThread::detachQueryIfNotDetached();
}