How to check what code is currently running on a server?
· 3 min read
ClickHouse provides introspection tools like `system.stack_trace` for inspecting what code is currently running on each server thread, helping with debugging and performance monitoring.
Check what code is currently running on a server
ClickHouse has a built-in debugger and introspection capabilities.
For example, you can get the stack traces of every server's thread at runtime by querying the system.stack_trace
table:
SELECT
count(),
arrayStringConcat(arrayMap(x -> concat(demangle(addressToSymbol(x)), '\n ', addressToLine(x)), trace), '\n') AS sym
FROM system.stack_trace
GROUP BY trace
ORDER BY count() DESC
LIMIT 10
FORMAT Vertical
SETTINGS allow_introspection_functions = 1;
The query result will show the locations in the ClickHouse source code where the threads are running or waiting. (You will need to set allow_introspection_functions
to 1
to enable the introspection functions.) The response looks like:
Row 1:
──────
count(): 144
sym: pthread_cond_wait
DB::BackgroundSchedulePool::threadFunction()
/usr/bin/clickhouse
/usr/bin/clickhouse
ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>)
/usr/bin/clickhouse
/usr/bin/clickhouse
clone
Row 2: