본문으로 바로가기
본문으로 바로가기

flameGraph

flameGraph

도입 버전: v23.8

스택 트레이스 목록을 사용해 flamegraph을(를) 생성합니다. flamegraph의 SVG를 렌더링하기 위해 flamegraph.pl 유틸리티에서 사용할 수 있는 문자열 배열을 출력합니다.

참고

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

구문

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

인수

  • traces — 스택 트레이스입니다. Array(UInt64)
  • size — 선택적 인수입니다. 메모리 프로파일링을 위한 할당 크기입니다(기본값 1). UInt64
  • ptr — 선택적 인수입니다. 할당 주소입니다(기본값 0). UInt64

반환 값

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

예시

CPU 쿼리 프로파일러를 기반으로 flamegraph를 생성하기

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

메모리 쿼리 프로파일러를 기반으로 모든 메모리 할당을 시각화하는 flamegraph 생성

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

메모리 쿼리 프로파일러를 기반으로 해제되지 않은 메모리 할당을 보여주는 flamegraph 생성하기

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