Querying in ClickHouse CloudThe data in this system table is held locally on each node in ClickHouse Cloud. Obtaining a complete view of all data, therefore, requires the
clusterAllReplicas function. See here for further details.Description
Contains stack traces collected by the sampling query profiler. ClickHouse creates this table when the trace_log server configuration section is set. Also see settings: query_profiler_real_time_period_ns, query_profiler_cpu_time_period_ns, memory_profiler_step, memory_profiler_sample_probability, trace_profile_events. When symbolization is enabled (the default), the demangled function names and source locations are already available in thesymbols and lines columns, so you can analyze the logs directly without introspection functions. The symbolize setting applies to profiler-collected trace types; rows with the Instrumentation trace type are symbolized regardless of it. Symbolization is supported on ELF platforms (such as Linux) and macOS; on FreeBSD the symbols and lines columns are always empty. Function names in symbols come from the binary’s symbol table and are available by default, while source locations in lines are best-effort: they require debug info (a .dSYM bundle on macOS) and, on ELF platforms, are resolved only for frames inside the main ClickHouse binary; unresolved frames have empty lines entries.
If symbolization is disabled, or you want to resolve the raw addresses in the trace column on the fly (for example, to expand inline frames), use the addressToLine, addressToLineWithInlines, addressToSymbol and demangle introspection functions. These functions are available on the same platforms as symbolization (ELF platforms such as Linux, and macOS); on FreeBSD they are not compiled in either, so the addresses in trace have to be resolved outside the server.
Columns
hostname(LowCardinality(String)) — Hostname of the server executing the query.event_date(Date) — Date of sampling moment.event_time(DateTime) — Timestamp of the sampling moment.event_time_microseconds(DateTime64(6)) — Timestamp of the sampling moment with microseconds precision.timestamp_ns(UInt64) — Timestamp of the sampling moment in nanoseconds.revision(UInt32) — ClickHouse server build revision. When connecting to the server byclickhouse-client, you see a string similar toConnected to ClickHouse server version 19.18.1.. This field contains therevision, but not theversionof a server.trace_type(Enum8(‘Real’ = 0, ‘CPU’ = 1, ‘Memory’ = 2, ‘MemorySample’ = 3, ‘MemoryPeak’ = 4, ‘ProfileEvent’ = 5, ‘JemallocSample’ = 6, ‘MemoryAllocatedWithoutCheck’ = 7, ‘Instrumentation’ = 8)) — Trace type:Realrepresents collecting stack traces by wall-clock time.CPUrepresents collecting stack traces by CPU time.Memoryrepresents collecting allocations and deallocations when memory allocation exceeds the subsequent watermark.MemorySamplerepresents collecting random allocations and deallocations.MemoryPeakrepresents collecting updates of peak memory usage.ProfileEventrepresents collecting of increments of profile events.JemallocSamplerepresents collecting of jemalloc samples.MemoryAllocatedWithoutCheckrepresents collection of significant allocations (>16MiB) that is done with ignoring any memory limits (for ClickHouse developers only).Instrumentationrepresents traces collected by the instrumentation performed through XRay.cpu_id(UInt64) — CPU identifier.thread_id(UInt64) — Thread identifier.thread_name(LowCardinality(String)) — Thread name.query_id(String) — Query identifier that can be used to get details about a query that was running from the query_log system table.trace(Array(UInt64)) — Stack trace at the moment of sampling. For profiler-collected trace types, on ELF platforms except FreeBSD, addresses inside the main ClickHouse binary are stored as physical file offsets, and other addresses are virtual memory addresses inside the ClickHouse server process. Instrumentation trace rows are an exception: they store raw virtual memory addresses.size(Int64) — For trace types Memory, MemorySample, MemoryAllocatedWithoutCheck or MemoryPeak is the amount of memory allocated, for other trace types is 0.ptr(UInt64) — The address of the allocated chunk.memory_context(Enum8(‘Unknown’ = -1, ‘Global’ = 0, ‘User’ = 1, ‘Process’ = 2, ‘Thread’ = 3, ‘Max’ = 4)) — Memory Tracker context (only for Memory/MemoryPeak):Unknowncontext is not defined for this trace_type.Globalrepresents server context.Userrepresents user/merge context.Processrepresents process (i.e. query) context.Threadrepresents thread (thread of particular process) context.Maxthis is a special value means that memory tracker is not blocked (for blocked_context column).memory_blocked_context(Enum8(‘Unknown’ = -1, ‘Global’ = 0, ‘User’ = 1, ‘Process’ = 2, ‘Thread’ = 3, ‘Max’ = 4)) — Context for which memory tracker is blocked (for ClickHouse developers only):Unknowncontext is not defined for this trace_type.Globalrepresents server context.Userrepresents user/merge context.Processrepresents process (i.e. query) context.Threadrepresents thread (thread of particular process) context.Maxthis is a special value means that memory tracker is not blocked (for blocked_context column).event(LowCardinality(String)) — For trace type ProfileEvent is the name of updated profile event, for other trace types is an empty string.increment(Int64) — For trace type ProfileEvent is the amount of increment of profile event, for other trace types is 0.symbols(Array(LowCardinality(String))) — If the symbolization is enabled, contains demangled symbol names, corresponding to thetrace. Symbolization can be enabled or disabled in thesymbolizesetting undertrace_login the server configuration file; the setting applies to profiler-collected trace types, while rows with theInstrumentationtrace type are symbolized regardless of it. Symbolization is supported on ELF platforms (such as Linux) and macOS; on FreeBSD this column is always empty.lines(Array(LowCardinality(String))) — If the symbolization is enabled, contains strings with file names with line numbers, corresponding to thetrace. Thesymbolizesetting applies to profiler-collected trace types, while rows with theInstrumentationtrace type are symbolized regardless of it. Symbolization is supported on ELF platforms (such as Linux) and macOS; on FreeBSD this column is always empty. Source locations are best-effort: they require debug info (a.dSYMbundle on macOS) and, on ELF platforms, are resolved only for frames inside the main ClickHouse binary; unresolved frames have empty entries.function_id(Nullable(Int32)) — For trace type Instrumentation, ID assigned to the function in xray_instr_map section of elf-binary.function_name(Nullable(String)) — For trace type Instrumentation, name of the instrumented function.handler(Nullable(String)) — For trace type Instrumentation, handler of the instrumented function.entry_type(Nullable(Enum8(‘Entry’ = 0, ‘Exit’ = 1))) — For trace type Instrumentation, entry type of the instrumented function.duration_nanoseconds(Nullable(UInt64)) — For trace type Instrumentation, time the function was running for in nanoseconds.
build_id— Alias for'9CDEA1FF0B705C46147FAFB1C612F4811AF80D54'.
symbolize setting under trace_log in the server’s configuration file. It is enabled by default. The setting applies to profiler-collected trace types; rows with the Instrumentation trace type are symbolized regardless of it.
Example
Converting to Chrome Event Trace Format
The profiling data can be converted to Chrome’s Event Trace Format with the following query. Save the query to achrome_trace.sql file:
trace.json file that we can import either with Perfetto or speedscope.
See Also
- SYSTEM INSTRUMENT — Add or remove instrumentation points.
- system.instrumentation — Inspect instrumented points.
- system.symbols — Inspect symbols to add instrumentation points.