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 Network(TestSuite): 23 # Network performance 24 def test_netif_receive_skb(self): 25 return DiffTestBlueprint( 26 trace=Path('netif_receive_skb.textproto'), 27 query=""" 28 SELECT 29 ts, 30 REPLACE(name, " Received KB", "") AS dev, 31 EXTRACT_ARG(arg_set_id, 'cpu') AS cpu, 32 EXTRACT_ARG(arg_set_id, 'len') AS len 33 FROM 34 counter AS c 35 LEFT JOIN 36 counter_track AS t 37 ON c.track_id = t.id 38 WHERE 39 name GLOB "* Received KB" 40 ORDER BY ts; 41 """, 42 out=Csv(""" 43 "ts","dev","cpu","len" 44 10000,"rmnet0",0,1000 45 10000,"rmnet0",1,1000 46 10010,"rmnet0",0,1000 47 10011,"rmnet0",1,1000 48 12000,"wlan",4,1300 49 """)) 50 51 def test_net_dev_xmit(self): 52 return DiffTestBlueprint( 53 trace=Path('net_dev_xmit.textproto'), 54 query=""" 55 SELECT 56 ts, 57 REPLACE(name, " Transmitted KB", "") AS dev, 58 EXTRACT_ARG(arg_set_id, 'cpu') AS cpu, 59 EXTRACT_ARG(arg_set_id, 'len') AS len 60 FROM 61 counter AS c 62 LEFT JOIN 63 counter_track AS t 64 ON c.track_id = t.id 65 WHERE 66 name GLOB "* Transmitted KB" 67 ORDER BY ts; 68 """, 69 out=Csv(""" 70 "ts","dev","cpu","len" 71 10000,"rmnet0",0,1000 72 10000,"rmnet0",1,1000 73 10010,"rmnet0",0,1000 74 12000,"wlan0",4,1300 75 """)) 76 77 def test_netperf_metric(self): 78 return DiffTestBlueprint( 79 trace=Path('netperf_metric.textproto'), 80 query=Metric('android_netperf'), 81 out=Path('netperf_metric.out')) 82 83 def test_inet_sock_set_state(self): 84 return DiffTestBlueprint( 85 trace=Path('inet_sock_set_state.textproto'), 86 query=""" 87 SELECT 88 ts, 89 s.name, 90 dur, 91 t.name 92 FROM 93 slice AS s 94 LEFT JOIN track AS t 95 ON s.track_id = t.id 96 WHERE 97 t.name GLOB "TCP stream#*" 98 ORDER BY ts; 99 """, 100 out=Csv(""" 101 "ts","name","dur","name" 102 10000000,"TCP_SYN_SENT(pid=123)",100000000,"TCP stream#1" 103 110000000,"TCP_ESTABLISHED(sport=56789,dport=5001)",500000000,"TCP stream#1" 104 610000000,"TCP_CLOSE_WAIT",-1,"TCP stream#1" 105 710000000,"TCP_SYN_SENT(pid=567)",10000000,"TCP stream#2" 106 720000000,"TCP_ESTABLISHED(sport=56790,dport=5002)",300000000,"TCP stream#2" 107 1020000000,"TCP_CLOSE_WAIT",-1,"TCP stream#2" 108 """)) 109 110 def test_tcp_retransmit_skb(self): 111 return DiffTestBlueprint( 112 trace=TextProto(r""" 113 packet { 114 ftrace_events { 115 cpu: 1 116 event { 117 timestamp: 110000000 118 pid: 234 119 tcp_retransmit_skb { 120 daddr: 19216801 121 saddr: 127001 122 dport: 5001 123 sport: 56789 124 state: 1 125 skaddr: 77889900 126 } 127 } 128 } 129 } 130 packet { 131 ftrace_events { 132 cpu: 1 133 event { 134 timestamp: 720000000 135 pid: 234 136 tcp_retransmit_skb { 137 daddr: 0 138 saddr: 0 139 dport: 5002 140 sport: 56790 141 state: 2 142 skaddr: 33445566 143 } 144 } 145 } 146 } 147 """), 148 query=""" 149 SELECT 150 ts, 151 s.name, 152 dur 153 FROM 154 slice AS s 155 LEFT JOIN track AS t 156 ON s.track_id = t.id 157 WHERE 158 t.name = "TCP Retransmit Skb" 159 ORDER BY ts; 160 """, 161 out=Csv(""" 162 "ts","name","dur" 163 110000000,"sport=56789,dport=5001",0 164 720000000,"sport=56790,dport=5002",0 165 """)) 166 167 def test_napi_gro_receive(self): 168 return DiffTestBlueprint( 169 trace=Path('napi_gro_receive.textproto'), 170 query=""" 171 SELECT 172 ts, 173 s.name, 174 dur, 175 cat, 176 t.name, 177 EXTRACT_ARG(arg_set_id, 'ret') AS ret, 178 EXTRACT_ARG(arg_set_id, 'len') AS len 179 FROM 180 slice AS s 181 LEFT JOIN 182 track AS t 183 ON s.track_id = t.id 184 WHERE 185 t.name GLOB "Napi Gro Cpu *" 186 ORDER BY ts; 187 """, 188 out=Csv(""" 189 "ts","name","dur","cat","name","ret","len" 190 10000,"rmnet0",20,"napi_gro","Napi Gro Cpu 2",2,1000 191 20000,"rmnet0",20,"napi_gro","Napi Gro Cpu 2",1,1000 192 30000,"wlan",20,"napi_gro","Napi Gro Cpu 4",3,500 193 """)) 194 195 def test_kfree_skb(self): 196 return DiffTestBlueprint( 197 trace=TextProto(r""" 198 packet { 199 ftrace_events { 200 cpu: 2 201 event { 202 timestamp: 10000 203 pid: 200 204 kfree_skb { 205 protocol: 2048 206 } 207 } 208 } 209 } 210 packet { 211 ftrace_events { 212 cpu: 2 213 event { 214 timestamp: 10020 215 pid: 300 216 kfree_skb { 217 protocol: 34525 218 } 219 } 220 } 221 } 222 packet { 223 ftrace_events { 224 cpu: 2 225 event { 226 timestamp: 20000 227 pid: 200 228 kfree_skb { 229 protocol: 1536 230 } 231 } 232 } 233 } 234 packet { 235 ftrace_events { 236 cpu: 2 237 event { 238 timestamp: 20020 239 pid: 300 240 kfree_skb { 241 protocol: 2048 242 } 243 } 244 } 245 } 246 """), 247 query=""" 248 SELECT 249 ts, 250 value, 251 EXTRACT_ARG(arg_set_id, 'protocol') AS prot 252 FROM 253 counter AS c 254 LEFT JOIN 255 counter_track AS t 256 ON c.track_id = t.id 257 WHERE 258 name GLOB "Kfree Skb IP Prot" 259 ORDER BY ts; 260 """, 261 out=Csv(""" 262 "ts","value","prot" 263 10000,1.000000,"IP" 264 10020,2.000000,"IPV6" 265 20020,3.000000,"IP" 266 """)) 267