Merge pull request #10444 from ClickHouse/server-memory-profiler

Simple server wide memory profiler
This commit is contained in:
alexey-milovidov 2020-04-23 00:34:23 +03:00 committed by GitHub
commit fd27ce619b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -617,9 +617,19 @@ int Server::main(const std::vector<std::string> & /*args*/)
/// Look at compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h /// Look at compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
/// ///
#if USE_UNWIND && !WITH_COVERAGE && !defined(SANITIZER) #if USE_UNWIND && !WITH_COVERAGE && !defined(SANITIZER)
/// QueryProfiler cannot work reliably with any other libunwind or without PHDR cache. /// Profilers cannot work reliably with any other libunwind or without PHDR cache.
if (hasPHDRCache()) if (hasPHDRCache())
{
global_context->initializeTraceCollector(); global_context->initializeTraceCollector();
/// Set up server-wide memory profiler (for total memory tracker).
UInt64 total_memory_profiler_step = config().getUInt64("total_memory_profiler_step", 0);
if (total_memory_profiler_step)
{
total_memory_tracker.setOrRaiseProfilerLimit(total_memory_profiler_step);
total_memory_tracker.setProfilerStep(total_memory_profiler_step);
}
}
#endif #endif
/// Describe multiple reasons when query profiler cannot work. /// Describe multiple reasons when query profiler cannot work.

View File

@ -107,6 +107,12 @@
--> -->
<max_server_memory_usage_to_ram_ratio>0.9</max_server_memory_usage_to_ram_ratio> <max_server_memory_usage_to_ram_ratio>0.9</max_server_memory_usage_to_ram_ratio>
<!-- Simple server-wide memory profiler. Collect a stack trace at every peak allocation step (in bytes).
Data will be stored in system.trace_log table with query_id = empty string.
Zero means disabled. Minimal effective value is 4 MiB.
-->
<total_memory_profiler_step>4194304</total_memory_profiler_step>
<!-- Set limit on number of open files (default: maximum). This setting makes sense on Mac OS X because getrlimit() fails to retrieve <!-- Set limit on number of open files (default: maximum). This setting makes sense on Mac OS X because getrlimit() fails to retrieve
correct maximum value. --> correct maximum value. -->
<!-- <max_open_files>262144</max_open_files> --> <!-- <max_open_files>262144</max_open_files> -->

View File

@ -65,7 +65,7 @@ void TraceCollector::collect(TraceType trace_type, const StackTrace & stack_trac
sizeof(StackTrace::Frames) + // collected stack trace, maximum capacity sizeof(StackTrace::Frames) + // collected stack trace, maximum capacity
sizeof(TraceType) + // trace type sizeof(TraceType) + // trace type
sizeof(UInt64) + // thread_id sizeof(UInt64) + // thread_id
sizeof(UInt64); // size sizeof(UInt64); // size
char buffer[buf_size]; char buffer[buf_size];
WriteBufferFromFileDescriptorDiscardOnFailure out(pipe.fds_rw[1], buf_size, buffer); WriteBufferFromFileDescriptorDiscardOnFailure out(pipe.fds_rw[1], buf_size, buffer);