Skip to content

Add simple memory profiler#8765

Merged
abyss7 merged 20 commits intoClickHouse:masterfrom
abyss7:memory-profiler
Feb 12, 2020
Merged

Add simple memory profiler#8765
abyss7 merged 20 commits intoClickHouse:masterfrom
abyss7:memory-profiler

Conversation

@abyss7
Copy link
Copy Markdown
Contributor

@abyss7 abyss7 commented Jan 21, 2020

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • New Feature

Changelog entry (up to few sentences, required except for Non-significant/Documentation categories):
Implement simple memory-profiler that dumps stacktraces to system.trace_log every N bytes over soft allocation limit

Copy link
Copy Markdown
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some questions in TG chat.

@alexey-milovidov
Copy link
Copy Markdown
Member

Test failure is related.

@abyss7
Copy link
Copy Markdown
Contributor Author

abyss7 commented Jan 24, 2020

Test failure is related.

Yes, I will fix it.

{std::make_shared<DataTypeString>(), "query_id"},
{std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>()), "trace"}
{std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>()), "trace"},
{std::make_shared<DataTypeInt64>(), "size"},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest allocated_bytes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's Ok. Because what else we will add to the trace_log.

@alexey-milovidov
Copy link
Copy Markdown
Member

sizeof(UInt32) + // thread_number
sizeof(Int64); // size
char buffer[buf_size];
WriteBufferFromFileDescriptorDiscardOnFailure out(pipe.fds_rw[1], buf_size, buffer);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it time to write a ser/de method for TraceLogElement? Or to even switch a trace from Array to std::array, so that TraceLogElement is fixed size and we can ship it verbatim over the pipe. Actually we can ship it even if it has pointers inside, because we're in the same process -- this would have move semantics. But I don't trust these pipes enough, maybe it'll leak :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch a trace from Array to std::array, so that TraceLogElement is fixed size

No need for that. When traces comes frequently, pipe is overflowed.

It allows to workaround first call inside signal handler
@abyss7
Copy link
Copy Markdown
Contributor Author

abyss7 commented Jan 29, 2020

It is not possible to initialize singleton inside signal handler:

https://clickhouse-test-reports.s3.yandex.net/8765/df0a3ce221c794160d668a0a3a4b1e8e5c8b8d09/functional_stateless_tests_(debug)/clickhouse-server.log

It's because the writeTraceInfo() contents were outside of TraceCollector - will try to simplify the constructor.

@alexey-milovidov
Copy link
Copy Markdown
Member

BTW, non-trivial static function variables contain spinlock and mutex - cannot be used in signal handlers.

@qoega qoega added the doc-alert label Feb 6, 2020
@abyss7 abyss7 self-assigned this Feb 10, 2020
@abyss7 abyss7 merged commit bef233f into ClickHouse:master Feb 12, 2020
@abyss7 abyss7 deleted the memory-profiler branch February 12, 2020 12:37
@abyss7 abyss7 added the pr-feature Pull request with new product feature label Feb 21, 2020
@alexey-milovidov
Copy link
Copy Markdown
Member

You forgot to mention about backward incompatible changes in system.trace_log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants