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 Csv, TextProto 17from python.generators.diff_tests.testing import DiffTestBlueprint 18from python.generators.diff_tests.testing import TestSuite 19 20 21class MemoryParser(TestSuite): 22 # cma alloc 23 def test_cma(self): 24 return DiffTestBlueprint( 25 trace=TextProto(r""" 26 packet { 27 system_info { 28 utsname { 29 sysname: "Linux" 30 release: "5.10.0" 31 } 32 } 33 } 34 packet { 35 ftrace_events { 36 cpu: 4 37 event { 38 timestamp: 74288080958099 39 pid: 537 40 cma_alloc_start { 41 align: 4 42 count: 6592 43 name: "farawimg" 44 } 45 } 46 event { 47 timestamp: 74288191109751 48 pid: 537 49 cma_alloc_info { 50 align: 4 51 count: 6592 52 err_iso: 0 53 err_mig: 0 54 err_test: 0 55 name: "farawimg" 56 nr_mapped: 832596 57 nr_migrated: 6365 58 nr_reclaimed: 7 59 pfn: 10365824 60 } 61 } 62 } 63 } 64 """), 65 query=""" 66 SELECT ts, dur, name FROM slice WHERE name = 'mm_cma_alloc'; 67 """, 68 out=Csv(""" 69 "ts","dur","name" 70 74288080958099,110151652,"mm_cma_alloc" 71 """)) 72 73 def test_android_dma_buffer_tracks(self): 74 return DiffTestBlueprint( 75 trace=TextProto(r""" 76 packet { 77 ftrace_events { 78 cpu: 0 79 event { 80 timestamp: 100 81 pid: 1 82 dma_heap_stat { 83 inode: 123 84 len: 1024 85 total_allocated: 2048 86 } 87 } 88 } 89 } 90 packet { 91 ftrace_events { 92 cpu: 0 93 event { 94 timestamp: 200 95 pid: 1 96 dma_heap_stat { 97 inode: 123 98 len: -1024 99 total_allocated: 1024 100 } 101 } 102 } 103 } 104 """), 105 query=""" 106 SELECT track.name, slice.ts, slice.dur, slice.name 107 FROM slice JOIN track ON slice.track_id = track.id 108 WHERE track.name = 'mem.dma_buffer'; 109 """, 110 out=Csv(""" 111 "name","ts","dur","name" 112 "mem.dma_buffer",100,100,"1 kB" 113 """)) 114