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 ProfilingHeapProfiling(TestSuite): 23 24 def test_heap_profile_jit(self): 25 return DiffTestBlueprint( 26 trace=Path('heap_profile_jit.textproto'), 27 query=""" 28 SELECT name, mapping, rel_pc FROM stack_profile_frame ORDER BY name; 29 """, 30 out=Csv(""" 31 "name","mapping","rel_pc" 32 "java_frame_1",0,4096 33 "java_frame_2",0,4096 34 """)) 35 36 def test_heap_profile_deobfuscate(self): 37 return DiffTestBlueprint( 38 trace=Path('heap_profile_deobfuscate.textproto'), 39 query=Path('heap_profile_deobfuscate_test.sql'), 40 out=Csv(""" 41 "deobfuscated_name","mapping","rel_pc" 42 "Bar.function1",0,4096 43 """)) 44 45 def test_heap_profile_deobfuscate_2(self): 46 return DiffTestBlueprint( 47 trace=Path('heap_profile_deobfuscate_memfd.textproto'), 48 query=Path('heap_profile_deobfuscate_test.sql'), 49 out=Csv(""" 50 "deobfuscated_name","mapping","rel_pc" 51 "Bar.function1",0,4096 52 """)) 53 54 def test_heap_profile_dump_max_legacy(self): 55 return DiffTestBlueprint( 56 trace=Path('heap_profile_dump_max_legacy.textproto'), 57 query=""" 58 SELECT * FROM heap_profile_allocation; 59 """, 60 out=Csv(""" 61 "id","type","ts","upid","heap_name","callsite_id","count","size" 62 0,"heap_profile_allocation",-10,2,"malloc",2,0,1000 63 1,"heap_profile_allocation",-10,2,"malloc",3,0,90 64 """)) 65 66 def test_heap_profile_dump_max(self): 67 return DiffTestBlueprint( 68 trace=Path('heap_profile_dump_max.textproto'), 69 query=""" 70 SELECT * FROM heap_profile_allocation; 71 """, 72 out=Csv(""" 73 "id","type","ts","upid","heap_name","callsite_id","count","size" 74 0,"heap_profile_allocation",-10,2,"malloc",2,6,1000 75 1,"heap_profile_allocation",-10,2,"malloc",3,1,90 76 """)) 77