flameGraph

flameGraph

스택트레이스(stacktrace) 목록으로 플레임그래프(flamegraph)를 만드는 집계 함수예요. flamegraph.pl 유틸리티가 SVG로 렌더링할 수 있는 문자열 배열을 출력합니다.

출처: 문서

본문

도입 버전: v23.8.0

스택트레이스 목록을 사용해 플레임그래프를 만듭니다. flamegraph.pl 유틸리티가 플레임그래프의 SVG를 렌더링할 때 사용할 수 있는 문자열 배열을 출력합니다.

참고: ptr != 0인 경우, flameGraph는 동일한 size와 ptr을 갖는 할당(size > 0)과 해제(size < 0)를 매핑합니다. 해제되지 않은 할당만 표시됩니다. 매핑되지 않은 해제는 무시됩니다.

구문 (Syntax)

flameGraph(traces[, size[, ptr]])

인자 (Arguments)

  • traces — 스택트레이스. 원시 주소(raw address)이거나 이미 심볼화된 문자열(예: arrayMap(addressToSymbol, trace))입니다. Array(UInt64) 또는 Array(String)
  • size — 선택 사항. 메모리 프로파일링을 위한 할당 크기(기본값 1). UInt64
  • ptr — 선택 사항. 할당 주소(기본값 0). UInt64

반환 값

flamegraph.pl 유틸리티에서 사용할 문자열 배열을 반환합니다. Array(String)

예제

CPU 쿼리 프로파일러 기반 플레임그래프 만들기

SET query_profiler_cpu_time_period_ns=10000000;
SELECT SearchPhrase, COUNT(DISTINCT UserID) AS u FROM hits WHERE SearchPhrase <> '' GROUP BY SearchPhrase ORDER BY u DESC LIMIT 10;
clickhouse client --allow_introspection_functions=1 -q "select arrayJoin(flameGraph(arrayReverse(trace))) from system.trace_log where trace_type = 'CPU' and query_id = 'xxx'" | ~/dev/FlameGraph/flamegraph.pl  > flame_cpu.svg

메모리 쿼리 프로파일러 기반 플레임그래프 만들기 - 모든 할당 표시

SET memory_profiler_sample_probability=1, max_untracked_memory=1;
SELECT SearchPhrase, COUNT(DISTINCT UserID) AS u FROM hits WHERE SearchPhrase <> '' GROUP BY SearchPhrase ORDER BY u DESC LIMIT 10;
clickhouse client --allow_introspection_functions=1 -q "select arrayJoin(flameGraph(trace, size)) from system.trace_log where trace_type = 'MemorySample' and query_id = 'xxx'" | ~/dev/FlameGraph/flamegraph.pl --countname=bytes --color=mem > flame_mem.svg

메모리 쿼리 프로파일러 기반 플레임그래프 만들기 - 해제되지 않은 할당 표시

SET memory_profiler_sample_probability=1, max_untracked_memory=1, use_uncompressed_cache=1, merge_tree_max_rows_to_use_cache=100000000000, merge_tree_max_bytes_to_use_cache=1000000000000;
SELECT SearchPhrase, COUNT(DISTINCT UserID) AS u FROM hits WHERE SearchPhrase <> '' GROUP BY SearchPhrase ORDER BY u DESC LIMIT 10;
clickhouse client --allow_introspection_functions=1 -q "SELECT arrayJoin(flameGraph(trace, size, ptr)) FROM system.trace_log WHERE trace_type = 'MemorySample' AND query_id = 'xxx'" | ~/dev/FlameGraph/flamegraph.pl --countname=bytes --color=mem > flame_mem_untracked.svg

메모리 쿼리 프로파일러 기반 플레임그래프 만들기 - 고정 시점의 활성 할당 표시

SET memory_profiler_sample_probability=1, max_untracked_memory=1;
SELECT SearchPhrase, COUNT(DISTINCT UserID) AS u FROM hits WHERE SearchPhrase <> '' GROUP BY SearchPhrase ORDER BY u DESC LIMIT 10;

-- 1. Memory usage per second
SELECT event_time, m, formatReadableSize(max(s) AS m) FROM (SELECT event_time, sum(size) OVER (ORDER BY event_time) AS s FROM system.trace_log WHERE query_id = 'xxx' AND trace_type = 'MemorySample') GROUP BY event_time ORDER BY event_time;

-- 2. Find a time point with maximal memory usage
SELECT argMax(event_time, s), max(s) FROM (SELECT event_time, sum(size) OVER (ORDER BY event_time) AS s FROM system.trace_log WHERE query_id = 'xxx' AND trace_type = 'MemorySample');
-- 3. Fix active allocations at fixed point of time
clickhouse client --allow_introspection_functions=1 -q "SELECT arrayJoin(flameGraph(trace, size, ptr)) FROM (SELECT * FROM system.trace_log WHERE trace_type = 'MemorySample' AND query_id = 'xxx' AND event_time <= 'yyy' ORDER BY event_time\)\"" | ~/dev/FlameGraph/flamegraph.pl --countname=bytes --color=mem > flame_mem_time_point_pos.svg

-- 4. Find deallocations at fixed point of time
clickhouse client --allow_introspection_functions=1 -q "SELECT arrayJoin(flameGraph(trace, -size, ptr)) FROM (SELECT * FROM system.trace_log WHERE trace_type = 'MemorySample' AND query_id = 'xxx' AND event_time > 'yyy' ORDER BY event_time desc\)\"" | ~/dev/FlameGraph/flamegraph.pl --countname=bytes --color=mem > flame_mem_time_point_neg.svg

더 알아보기 (Learn more)