1#!/usr/bin/env python3 2# Copyright (C) 2023 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License a 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16from python.generators.diff_tests.testing import Path, DataPath, Metric 17from python.generators.diff_tests.testing import Csv, Json, TextProto 18from python.generators.diff_tests.testing import DiffTestBlueprint 19from python.generators.diff_tests.testing import TestSuite 20 21 22class ProfilingLlvmSymbolizer(TestSuite): 23 # this uses llvm-symbolizer to test the offline symbolization built into 24 def test_stack_profile_symbols(self): 25 return DiffTestBlueprint( 26 trace=DataPath('heapprofd_standalone_client_example-trace'), 27 query=""" 28 SELECT name, source_file, line_number FROM stack_profile_symbol; 29 """, 30 out=Path('stack_profile_symbols.out')) 31 32 def test_callstack_sampling_flamegraph(self): 33 return DiffTestBlueprint( 34 trace=DataPath('callstack_sampling.pftrace'), 35 query=""" 36 SELECT ef.* 37 FROM experimental_flamegraph ef 38 JOIN process USING (upid) 39 WHERE pid = 1728 40 AND profile_type = 'perf' 41 AND ts <= 7689491063351 42 LIMIT 10; 43 """, 44 out=Path('callstack_sampling_flamegraph.out')) 45 46 def test_callstack_sampling_flamegraph_multi_process(self): 47 return DiffTestBlueprint( 48 trace=DataPath('callstack_sampling.pftrace'), 49 query=""" 50 SELECT count(*) AS count, 'BothProcesses' AS description 51 FROM experimental_flamegraph 52 WHERE 53 upid_group = ( 54 SELECT group_concat(DISTINCT upid) 55 FROM perf_sample JOIN thread t USING (utid) JOIN process p USING (upid) 56 ) 57 AND profile_type = 'perf' 58 AND ts <= 7689491063351 59 AND size > 0 60 UNION ALL 61 SELECT count(*) AS count, 'FirstProcess' AS description 62 FROM experimental_flamegraph 63 JOIN process USING (upid) 64 WHERE pid = 1728 65 AND profile_type = 'perf' 66 AND ts <= 7689491063351 67 AND size > 0 68 UNION ALL 69 SELECT count(*) AS count, 'SecondProcess' AS description 70 FROM experimental_flamegraph 71 JOIN process USING (upid) 72 WHERE pid = 703 73 AND profile_type = 'perf' 74 AND ts <= 7689491063351 75 AND size > 0; 76 """, 77 out=Csv(""" 78 "count","description" 79 658,"BothProcesses" 80 483,"FirstProcess" 81 175,"SecondProcess" 82 """)) 83 84 def test_no_build_id(self): 85 return DiffTestBlueprint( 86 trace=Path('heap_profile_data_local_tmp.textproto'), 87 query=""" 88 SELECT value FROM stats WHERE name = 'symbolization_tmp_build_id_not_found'; 89 """, 90 out=Csv(""" 91 "value" 92 1 93 """)) 94