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, Metric 17from python.generators.diff_tests.testing import Csv, TextProto 18from python.generators.diff_tests.testing import DiffTestBlueprint 19from python.generators.diff_tests.testing import TestSuite 20 21 22class NetworkParser(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_inet_sock_set_state(self): 78 return DiffTestBlueprint( 79 trace=Path('inet_sock_set_state.textproto'), 80 query=""" 81 SELECT 82 ts, 83 s.name, 84 dur, 85 t.name 86 FROM 87 slice AS s 88 LEFT JOIN track AS t 89 ON s.track_id = t.id 90 WHERE 91 t.name GLOB "TCP stream#*" 92 ORDER BY ts; 93 """, 94 out=Csv(""" 95 "ts","name","dur","name" 96 10000000,"TCP_SYN_SENT(pid=123)",100000000,"TCP stream#1" 97 110000000,"TCP_ESTABLISHED(sport=56789,dport=5001)",500000000,"TCP stream#1" 98 610000000,"TCP_CLOSE_WAIT",-1,"TCP stream#1" 99 710000000,"TCP_SYN_SENT(pid=567)",10000000,"TCP stream#2" 100 720000000,"TCP_ESTABLISHED(sport=56790,dport=5002)",300000000,"TCP stream#2" 101 1020000000,"TCP_CLOSE_WAIT",-1,"TCP stream#2" 102 """)) 103 104 def test_tcp_retransmit_skb(self): 105 return DiffTestBlueprint( 106 trace=TextProto(r""" 107 packet { 108 ftrace_events { 109 cpu: 1 110 event { 111 timestamp: 110000000 112 pid: 234 113 tcp_retransmit_skb { 114 daddr: 19216801 115 saddr: 127001 116 dport: 5001 117 sport: 56789 118 state: 1 119 skaddr: 77889900 120 } 121 } 122 } 123 } 124 packet { 125 ftrace_events { 126 cpu: 1 127 event { 128 timestamp: 720000000 129 pid: 234 130 tcp_retransmit_skb { 131 daddr: 0 132 saddr: 0 133 dport: 5002 134 sport: 56790 135 state: 2 136 skaddr: 33445566 137 } 138 } 139 } 140 } 141 """), 142 query=""" 143 SELECT 144 ts, 145 s.name, 146 dur 147 FROM 148 slice AS s 149 LEFT JOIN track AS t 150 ON s.track_id = t.id 151 WHERE 152 t.name = "TCP Retransmit Skb" 153 ORDER BY ts; 154 """, 155 out=Csv(""" 156 "ts","name","dur" 157 110000000,"sport=56789,dport=5001",0 158 720000000,"sport=56790,dport=5002",0 159 """)) 160 161 def test_napi_gro_receive(self): 162 return DiffTestBlueprint( 163 trace=Path('napi_gro_receive.textproto'), 164 query=""" 165 SELECT 166 ts, 167 s.name, 168 dur, 169 cat, 170 t.name, 171 EXTRACT_ARG(arg_set_id, 'ret') AS ret, 172 EXTRACT_ARG(arg_set_id, 'len') AS len 173 FROM 174 slice AS s 175 LEFT JOIN 176 track AS t 177 ON s.track_id = t.id 178 WHERE 179 t.name GLOB "Napi Gro Cpu *" 180 ORDER BY ts; 181 """, 182 out=Csv(""" 183 "ts","name","dur","cat","name","ret","len" 184 10000,"rmnet0",20,"napi_gro","Napi Gro Cpu 2",2,1000 185 20000,"rmnet0",20,"napi_gro","Napi Gro Cpu 2",1,1000 186 30000,"wlan",20,"napi_gro","Napi Gro Cpu 4",3,500 187 """)) 188 189 def test_kfree_skb(self): 190 return DiffTestBlueprint( 191 trace=TextProto(r""" 192 packet { 193 ftrace_events { 194 cpu: 2 195 event { 196 timestamp: 10000 197 pid: 200 198 kfree_skb { 199 protocol: 2048 200 } 201 } 202 } 203 } 204 packet { 205 ftrace_events { 206 cpu: 2 207 event { 208 timestamp: 10020 209 pid: 300 210 kfree_skb { 211 protocol: 34525 212 } 213 } 214 } 215 } 216 packet { 217 ftrace_events { 218 cpu: 2 219 event { 220 timestamp: 20000 221 pid: 200 222 kfree_skb { 223 protocol: 1536 224 } 225 } 226 } 227 } 228 packet { 229 ftrace_events { 230 cpu: 2 231 event { 232 timestamp: 20020 233 pid: 300 234 kfree_skb { 235 protocol: 2048 236 } 237 } 238 } 239 } 240 """), 241 query=""" 242 SELECT 243 ts, 244 value, 245 EXTRACT_ARG(arg_set_id, 'protocol') AS prot 246 FROM 247 counter AS c 248 LEFT JOIN 249 counter_track AS t 250 ON c.track_id = t.id 251 WHERE 252 name GLOB "Kfree Skb IP Prot" 253 ORDER BY ts; 254 """, 255 out=Csv(""" 256 "ts","value","prot" 257 10000,1.000000,"IP" 258 10020,2.000000,"IPV6" 259 20020,3.000000,"IP" 260 """)) 261