PerfettoSQL과 Perfetto 표준 라이브러리의 모듈을 사용하여 ProfilingManager 프로필을 쿼리할 수 있습니다. ProfilingManager은 앱의 프로세스 데이터만 포함하도록 시스템 트레이스를 수정하므로 다른 프로세스에 종속된 시스템 전체 표준 라이브러리 쿼리는 지원되지 않습니다. 하지만 대부분의 앱 범위 쿼리와 표준 라이브러리 모듈은 수정 없이 작동합니다. 바로 사용할 수 있는 추가 쿼리는 Android 트레이스 분석을 참고하세요.
ProfilingManager 샘플 쿼리
다음 샘플 쿼리를 직접 사용하거나 자체 PerfettoSQL 분석의 템플릿으로 사용하세요.
가장 많이 중복된 슬라이스 찾기
반복되는 슬라이스는 중복 작업을 나타내는 경우가 많습니다. 함수 문법에 관한 자세한 내용은 PerfettoSQL에서 함수 정의를 참고하세요. 다음 쿼리는 GLOB 패턴과 일치하는 슬라이스를 찾아 빈도별로 정렬하는 재사용 가능한 PerfettoSQL 함수를 정의합니다.
-- You only need to call this once in the session to create or update the function
CREATE OR REPLACE PERFETTO FUNCTION find_duplicates(pattern STRING) RETURNS
TABLE(name STRING, count_slice LONG) AS SELECT name, COUNT(dur) as count_slice FROM slice WHERE name GLOB $pattern GROUP BY name HAVING COUNT(name) >= 2 ORDER BY count_slice DESC;
-- Subsequent calls can just use the function to find dupes
SELECT * FROM find_duplicates('*Text*')
버벅거림 쿼리
다음 쿼리를 사용하여 시스템 트레이스에서 느리거나 버벅거리는 프레임을 식별합니다.
느린 프레임 찾기
이 쿼리는 렌더링하는 데 16.6ms(60Hz)보다 오래 걸리는 프레임을 찾습니다. Perfetto는 슬라이스 기간을 나노초 단위로 저장하므로 dur은 16660000과 비교됩니다.
INCLUDE PERFETTO module android.frames.timeline;
SELECT * FROM android_frames WHERE dur > 16660000;
버벅거림을 유발하는 프레임 찾기
이 쿼리는 프레임 타임라인 모듈을 사용하여 기기의 화면 재생 빈도에 따라 앱이 렌더링 기한을 놓친 프레임을 찾습니다.
INCLUDE PERFETTO module android.frames.timeline;
SELECT * FROM actual_frame_timeline_slice WHERE jank_type GLOB '*App Deadline Missed*';
가장 많이 중복된 객체 찾기
Java 힙 덤프에서 이 쿼리는 의도하지 않은 중복 또는 캐싱 기회를 파악하는 데 도움이 되도록 인스턴스가 2개 이상인 상위 100개 클래스를 반환합니다.
INCLUDE PERFETTO MODULE android.memory.heap_graph.heap_graph_class_aggregation;
SELECT * FROM android_heap_graph_class_aggregation WHERE obj_count >= 2
ORDER BY obj_count DESC LIMIT 100
콜드 스타트 지연 시간
이 쿼리는 bindApplication와 첫 번째 Choreographer#doFrame 슬라이스 사이의 시간을 측정하여 첫 프레임까지의 콜드 스타트 시간(TTFF)을 추정합니다.
-- This function finds slices that match the given GLOB $pattern
CREATE OR REPLACE PERFETTO FUNCTION find_slices(pattern STRING) RETURNS
TABLE (name STRING, ts LONG, dur LONG) AS
SELECT name,ts,dur FROM slice WHERE name GLOB $pattern;
-- This function generates a slice that starts at $startSlicePattern and finishes at the slice matched by $endSlicePattern. If $inclusive is true, then the end slice dur will be added, otherwise, the end slice start time will be used.
CREATE OR REPLACE PERFETTO FUNCTION generate_start_to_end_slices(startSlicePattern STRING, endSlicePattern STRING, inclusive BOOL) RETURNS
TABLE(name STRING, ts LONG, dur LONG) AS
SELECT name, ts, MIN(startToEndDur) as dur
FROM
(SELECT S.name as name, S.ts as ts, E.ts + IIF($inclusive, E.dur, 0) - S.ts as startToEndDur
FROM find_slices($startSlicePattern) as S CROSS JOIN find_slices($endSlicePattern) as E
WHERE startToEndDur > 0)
GROUP BY name, ts;
-- Using these functions we can estimate cold startup time by generating a slice between bindApplication and first frame.
SELECT * from generate_start_to_end_slices('bindApplication','*Choreographer#doFrame [0-9]*', true)