1.. _net_pkt_processing_stats: 2 3Network Packet Processing Statistics 4#################################### 5 6.. contents:: 7 :local: 8 :depth: 2 9 10This page describes how to get information about network packet processing 11statistics inside network stack. 12 13Network stack contains infrastructure to figure out how long the network packet 14processing takes either in sending or receiving path. There are two Kconfig 15options that control this. For transmit (TX) path the option is called 16:kconfig:`CONFIG_NET_PKT_TXTIME_STATS` and for receive (RX) path the options is 17called :kconfig:`CONFIG_NET_PKT_RXTIME_STATS`. Note that for TX, all kind of 18network packet statistics is collected. For RX, only UDP, TCP or raw packet 19type network packet statistics is collected. 20 21After enabling these options, the :ref:`net stats <net_shell>` network shell 22command will show this information: 23 24.. code-block:: console 25 26 Avg TX net_pkt (11484) time 67 us 27 Avg RX net_pkt (11474) time 43 us 28 29.. note:: 30 31 The values above and below are from emulated qemu_x86 board and UDP traffic 32 33The TX time tells how long it took for network packet from its creation to 34when it was sent to the network. The RX time tells the time from its creation 35to when it was passed to the application. The values are in microseconds. The 36statistics will be collected per traffic class if there are more than one 37transmit or receive queues defined in the system. These are controlled by 38:kconfig:`CONFIG_NET_TC_TX_COUNT` and :kconfig:`CONFIG_NET_TC_RX_COUNT` options. 39 40If you enable :kconfig:`CONFIG_NET_PKT_TXTIME_STATS_DETAIL` or 41:kconfig:`CONFIG_NET_PKT_RXTIME_STATS_DETAIL` options, then additional 42information for TX or RX network packets are collected when the network packet 43traverses the IP stack. 44 45After enabling these options, the :ref:`net stats <net_shell>` will show 46this information: 47 48.. code-block:: console 49 50 Avg TX net_pkt (18902) time 63 us [0->22->15->23=60 us] 51 Avg RX net_pkt (18892) time 42 us [0->9->6->11->13=39 us] 52 53The numbers inside the brackets contain information how many microseconds it 54took for a network packet to go from previous state to next. 55 56In the TX example above, the values are averages over **18902** packets and 57contain this information: 58 59* Packet was created by application so the time is **0**. 60* Packet is about to be placed to transmit queue. The time it took from network 61 packet creation to this state, is **22** microseconds in this example. 62* The correct TX thread is invoked, and the packet is read from the transmit 63 queue. It took **15** microseconds from previous state. 64* The network packet was just sent and the network stack is about to free the 65 network packet. It took **23** microseconds from previous state. 66* In total it took on average **60** microseconds to get the network packet 67 sent. The value **63** tells also the same information, but is calculated 68 differently so there is slight difference because of rounding errors. 69 70In the RX example above, the values are averages over **18892** packets and 71contain this information: 72 73* Packet was created network device driver so the time is **0**. 74* Packet is about to be placed to receive queue. The time it took from network 75 packet creation to this state, is **9** microseconds in this example. 76* The correct RX thread is invoked, and the packet is read from the receive 77 queue. It took **6** microseconds from previous state. 78* The network packet is then processed and placed to correct socket queue. 79 It took **11** microseconds from previous state. 80* The last value tells how long it took from there to the application. Here 81 the value is **13** microseconds. 82* In total it took on average **39** microseconds to get the network packet 83 sent. The value **42** tells also the same information, but is calculated 84 differently so there is slight difference because of rounding errors. 85