13 sys.path.append(os.environ[
'PERF_EXEC_PATH'] + \
14 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
16 from perf_trace_context
import *
25 receive_hunk_list = [];
29 buffer_budget = 65536;
31 of_count_rx_skb_list = 0;
34 of_count_tx_queue_list = 0;
37 of_count_tx_xmit_list = 0;
57 return (dst - src) / 1000000.0
61 if dev != 0
and hunk[
'dev'].find(dev) < 0:
63 print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \
64 (hunk[
'dev'], hunk[
'len'],
67 diff_msec(hunk[
'queue_t'], hunk[
'xmit_t']),
68 diff_msec(hunk[
'xmit_t'], hunk[
'free_t']))
71 PF_IRQ_ENTRY=
" irq_entry(+%.3fmsec irq=%d:%s)"
72 PF_SOFT_ENTRY=
" softirq_entry(+%.3fmsec)"
73 PF_NAPI_POLL=
" napi_poll_exit(+%.3fmsec %s)"
76 PF_NET_RECV=
" |---netif_receive_skb(+%.3fmsec skb=%x len=%d)"
77 PF_NET_RX=
" |---netif_rx(+%.3fmsec skb=%x)"
78 PF_CPY_DGRAM=
" | skb_copy_datagram_iovec(+%.3fmsec %d:%s)"
79 PF_KFREE_SKB=
" | kfree_skb(+%.3fmsec location=%x)"
80 PF_CONS_SKB=
" | consume_skb(+%.3fmsec)"
86 irq_list = hunk[
'irq_list']
87 cpu = irq_list[0][
'cpu']
88 base_t = irq_list[0][
'irq_ent_t']
91 for i
in range(len(irq_list)):
92 if irq_list[i][
'name'].find(dev) >= 0:
100 print "%d.%06dsec cpu=%d" % \
102 for i
in range(len(irq_list)):
103 print PF_IRQ_ENTRY % \
104 (
diff_msec(base_t, irq_list[i][
'irq_ent_t']),
105 irq_list[i][
'irq'], irq_list[i][
'name'])
107 irq_event_list = irq_list[i][
'event_list']
108 for j
in range(len(irq_event_list)):
109 irq_event = irq_event_list[j]
110 if irq_event[
'event'] ==
'netif_rx':
113 irq_event[
'skbaddr'])
115 print PF_SOFT_ENTRY % \
118 event_list = hunk[
'event_list']
119 for i
in range(len(event_list)):
120 event = event_list[i]
121 if event[
'event_name'] ==
'napi_poll':
122 print PF_NAPI_POLL % \
123 (
diff_msec(base_t, event[
'event_t']), event[
'dev'])
124 if i == len(event_list) - 1:
129 print PF_NET_RECV % \
130 (
diff_msec(base_t, event[
'event_t']), event[
'skbaddr'],
132 if 'comm' in event.keys():
134 print PF_CPY_DGRAM % \
136 event[
'pid'], event[
'comm'])
137 elif 'handle' in event.keys():
139 if event[
'handle'] ==
"kfree_skb":
140 print PF_KFREE_SKB % \
144 elif event[
'handle'] ==
"consume_skb":
145 print PF_CONS_SKB % \
156 for i
in range(len(sys.argv)):
164 elif arg.find(
'dev=',0, 4) >= 0:
168 if show_tx == 0
and show_rx == 0:
174 all_event_list.sort(
lambda a,b :cmp(a[EINFO_IDX_TIME],
177 for i
in range(len(all_event_list)):
178 event_info = all_event_list[i]
179 name = event_info[EINFO_IDX_NAME]
180 if name ==
'irq__softirq_exit':
182 elif name ==
'irq__softirq_entry':
184 elif name ==
'irq__softirq_raise':
186 elif name ==
'irq__irq_handler_entry':
188 elif name ==
'irq__irq_handler_exit':
190 elif name ==
'napi__napi_poll':
192 elif name ==
'net__netif_receive_skb':
194 elif name ==
'net__netif_rx':
196 elif name ==
'skb__skb_copy_datagram_iovec':
198 elif name ==
'net__net_dev_queue':
200 elif name ==
'net__net_dev_xmit':
202 elif name ==
'skb__kfree_skb':
204 elif name ==
'skb__consume_skb':
208 for i
in range(len(receive_hunk_list)):
212 print " dev len Qdisc " \
214 for i
in range(len(tx_free_list)):
217 print "debug buffer status"
218 print "----------------------------"
219 print "xmit Qdisc:remain:%d overflow:%d" % \
220 (len(tx_queue_list), of_count_tx_queue_list)
221 print "xmit netdevice:remain:%d overflow:%d" % \
222 (len(tx_xmit_list), of_count_tx_xmit_list)
223 print "receive:remain:%d overflow:%d" % \
224 (len(rx_skb_list), of_count_rx_skb_list)
228 if symbol_str(
"irq__softirq_entry",
"vec", vec) !=
"NET_RX":
230 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm, vec)
231 all_event_list.append(event_info)
234 if symbol_str(
"irq__softirq_entry",
"vec", vec) !=
"NET_RX":
236 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm, vec)
237 all_event_list.append(event_info)
240 if symbol_str(
"irq__softirq_entry",
"vec", vec) !=
"NET_RX":
242 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm, vec)
243 all_event_list.append(event_info)
247 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm,
249 all_event_list.append(event_info)
252 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm, irq, ret)
253 all_event_list.append(event_info)
256 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm,
258 all_event_list.append(event_info)
262 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm,
263 skbaddr, skblen, dev_name)
264 all_event_list.append(event_info)
266 def net__netif_rx(name, context, cpu, sec, nsec, pid, comm, skbaddr,
268 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm,
269 skbaddr, skblen, dev_name)
270 all_event_list.append(event_info)
273 skbaddr, skblen, dev_name):
274 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm,
275 skbaddr, skblen, dev_name)
276 all_event_list.append(event_info)
279 skbaddr, skblen, rc, dev_name):
280 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm,
281 skbaddr, skblen, rc ,dev_name)
282 all_event_list.append(event_info)
285 skbaddr, protocol, location):
286 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm,
287 skbaddr, protocol, location)
288 all_event_list.append(event_info)
291 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm,
293 all_event_list.append(event_info)
297 event_info = (name, context, cpu,
nsecs(sec, nsec), pid, comm,
299 all_event_list.append(event_info)
302 (name, context, cpu, time, pid, comm, irq, irq_name) = event_info
303 if cpu
not in irq_dic.keys():
305 irq_record = {
'irq':irq,
'name':irq_name,
'cpu':cpu,
'irq_ent_t':time}
306 irq_dic[cpu].append(irq_record)
309 (name, context, cpu, time, pid, comm, irq, ret) = event_info
310 if cpu
not in irq_dic.keys():
312 irq_record = irq_dic[cpu].
pop()
313 if irq != irq_record[
'irq']:
315 irq_record.update({
'irq_ext_t':time})
317 if 'event_list' in irq_record.keys():
318 irq_dic[cpu].append(irq_record)
321 (name, context, cpu, time, pid, comm, vec) = event_info
322 if cpu
not in irq_dic.keys() \
323 or len(irq_dic[cpu]) == 0:
325 irq_record = irq_dic[cpu].
pop()
326 if 'event_list' in irq_record.keys():
327 irq_event_list = irq_record[
'event_list']
330 irq_event_list.append({
'time':time,
'event':
'sirq_raise'})
331 irq_record.update({
'event_list':irq_event_list})
332 irq_dic[cpu].append(irq_record)
335 (name, context, cpu, time, pid, comm, vec) = event_info
336 net_rx_dic[cpu] = {
'sirq_ent_t':time,
'event_list':[]}
339 (name, context, cpu, time, pid, comm, vec) = event_info
342 if cpu
in irq_dic.keys():
343 irq_list = irq_dic[cpu]
345 if cpu
in net_rx_dic.keys():
346 sirq_ent_t = net_rx_dic[cpu][
'sirq_ent_t']
347 event_list = net_rx_dic[cpu][
'event_list']
349 if irq_list == []
or event_list == 0:
351 rec_data = {
'sirq_ent_t':sirq_ent_t,
'sirq_ext_t':time,
352 'irq_list':irq_list,
'event_list':event_list}
354 receive_hunk_list.append(rec_data)
357 (name, context, cpu, time, pid, comm, napi, dev_name) = event_info
358 if cpu
in net_rx_dic.keys():
359 event_list = net_rx_dic[cpu][
'event_list']
360 rec_data = {
'event_name':
'napi_poll',
361 'dev':dev_name,
'event_t':time}
362 event_list.append(rec_data)
365 (name, context, cpu, time, pid, comm,
366 skbaddr, skblen, dev_name) = event_info
367 if cpu
not in irq_dic.keys() \
368 or len(irq_dic[cpu]) == 0:
370 irq_record = irq_dic[cpu].
pop()
371 if 'event_list' in irq_record.keys():
372 irq_event_list = irq_record[
'event_list']
375 irq_event_list.append({
'time':time,
'event':
'netif_rx',
376 'skbaddr':skbaddr,
'skblen':skblen,
'dev_name':dev_name})
377 irq_record.update({
'event_list':irq_event_list})
378 irq_dic[cpu].append(irq_record)
381 global of_count_rx_skb_list
383 (name, context, cpu, time, pid, comm,
384 skbaddr, skblen, dev_name) = event_info
385 if cpu
in net_rx_dic.keys():
386 rec_data = {
'event_name':
'netif_receive_skb',
387 'event_t':time,
'skbaddr':skbaddr,
'len':skblen}
388 event_list = net_rx_dic[cpu][
'event_list']
389 event_list.append(rec_data)
390 rx_skb_list.insert(0, rec_data)
391 if len(rx_skb_list) > buffer_budget:
393 of_count_rx_skb_list += 1
396 global of_count_tx_queue_list
398 (name, context, cpu, time, pid, comm,
399 skbaddr, skblen, dev_name) = event_info
400 skb = {
'dev':dev_name,
'skbaddr':skbaddr,
'len':skblen,
'queue_t':time}
401 tx_queue_list.insert(0, skb)
402 if len(tx_queue_list) > buffer_budget:
404 of_count_tx_queue_list += 1
407 global of_count_tx_xmit_list
409 (name, context, cpu, time, pid, comm,
410 skbaddr, skblen, rc, dev_name) = event_info
412 for i
in range(len(tx_queue_list)):
413 skb = tx_queue_list[i]
414 if skb[
'skbaddr'] == skbaddr:
416 tx_xmit_list.insert(0, skb)
418 if len(tx_xmit_list) > buffer_budget:
420 of_count_tx_xmit_list += 1
424 (name, context, cpu, time, pid, comm,
425 skbaddr, protocol, location) = event_info
426 for i
in range(len(tx_queue_list)):
427 skb = tx_queue_list[i]
428 if skb[
'skbaddr'] == skbaddr:
431 for i
in range(len(tx_xmit_list)):
432 skb = tx_xmit_list[i]
433 if skb[
'skbaddr'] == skbaddr:
435 tx_free_list.append(skb)
438 for i
in range(len(rx_skb_list)):
439 rec_data = rx_skb_list[i]
440 if rec_data[
'skbaddr'] == skbaddr:
441 rec_data.update({
'handle':
"kfree_skb",
442 'comm':comm,
'pid':pid,
'comm_t':time})
447 (name, context, cpu, time, pid, comm, skbaddr) = event_info
448 for i
in range(len(tx_xmit_list)):
449 skb = tx_xmit_list[i]
450 if skb[
'skbaddr'] == skbaddr:
452 tx_free_list.append(skb)
457 (name, context, cpu, time, pid, comm, skbaddr, skblen) = event_info
458 for i
in range(len(rx_skb_list)):
459 rec_data = rx_skb_list[i]
460 if skbaddr == rec_data[
'skbaddr']:
461 rec_data.update({
'handle':
"skb_copy_datagram_iovec",
462 'comm':comm,
'pid':pid,
'comm_t':time})