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, BinaryProto 18from python.generators.diff_tests.testing import DiffTestBlueprint 19from python.generators.diff_tests.testing import TestSuite 20from google.protobuf import text_format 21 22 23class Slices(TestSuite): 24 25 def test_thread_slice(self): 26 return DiffTestBlueprint( 27 trace=Path('trace.py'), 28 query=""" 29 INCLUDE PERFETTO MODULE slices.with_context; 30 31 SELECT name, ts, dur, depth, thread_name, tid, process_name, pid 32 FROM thread_slice; 33 """, 34 out=Csv(""" 35 "name","ts","dur","depth","thread_name","tid","process_name","pid" 36 "ThreadSlice",5,6,0,"Thread",5,"Process",3 37 """)) 38 39 def test_process_slice(self): 40 return DiffTestBlueprint( 41 trace=Path('trace.py'), 42 query=""" 43 INCLUDE PERFETTO MODULE slices.with_context; 44 45 SELECT name, ts, dur, depth, process_name, pid 46 FROM process_slice; 47 """, 48 out=Csv(""" 49 "name","ts","dur","depth","process_name","pid" 50 "ProcessSlice",3,4,0,"Process",3 51 """)) 52 53 def test_slice_with_process_and_thread_info(self): 54 return DiffTestBlueprint( 55 trace=Path('trace.py'), 56 query=""" 57 INCLUDE PERFETTO MODULE slices.slices; 58 59 SELECT name, ts, dur, depth, thread_name, tid, process_name, pid 60 FROM _slice_with_thread_and_process_info; 61 """, 62 out=Csv(""" 63 "name","ts","dur","depth","thread_name","tid","process_name","pid" 64 "AsyncSlice",1,2,0,"[NULL]","[NULL]","[NULL]","[NULL]" 65 "ProcessSlice",3,4,0,"[NULL]","[NULL]","Process",3 66 "ThreadSlice",5,6,0,"Thread",5,"Process",3 67 """)) 68 69 # Common functions 70 71 def test_slice_flattened(self): 72 return DiffTestBlueprint( 73 trace=DataPath('chrome_input_with_frame_view.pftrace'), 74 query=""" 75 INCLUDE PERFETTO MODULE slices.flat_slices; 76 77 SELECT e.name, e.ts, e.dur, e.depth 78 FROM _slice_flattened e 79 JOIN thread_track ON e.track_id = thread_track.id 80 JOIN thread USING(utid) 81 WHERE thread.tid = 30196 82 ORDER BY ts 83 LIMIT 10; 84 """, 85 out=Csv(""" 86 "name","ts","dur","depth" 87 "EventForwarder::OnTouchEvent",1035865509936036,211000,0 88 "GestureProvider::OnTouchEvent",1035865510147036,87000,1 89 "EventForwarder::OnTouchEvent",1035865510234036,48000,0 90 "RenderWidgetHostImpl::ForwardTouchEvent",1035865510282036,41000,1 91 "LatencyInfo.Flow",1035865510323036,8000,2 92 "RenderWidgetHostImpl::ForwardTouchEvent",1035865510331036,16000,1 93 "PassthroughTouchEventQueue::QueueEvent",1035865510347036,30000,2 94 "InputRouterImpl::FilterAndSendWebInputEvent",1035865510377036,8000,3 95 "LatencyInfo.Flow",1035865510385036,126000,4 96 "RenderWidgetHostImpl::UserInputStarted",1035865510511036,7000,5 97 """)) 98 99 def test_thread_slice_cpu_time(self): 100 return DiffTestBlueprint( 101 trace=DataPath('example_android_trace_30s.pb'), 102 query=""" 103 INCLUDE PERFETTO MODULE slices.cpu_time; 104 105 SELECT * 106 FROM thread_slice_cpu_time 107 LIMIT 10; 108 """, 109 out=Csv(""" 110 "id","cpu_time" 111 0,178646 112 1,119740 113 2,58073 114 3,98698 115 4,121979 116 5,45000 117 6,35104 118 7,33333 119 8,46926 120 9,17865 121 """)) 122