DPDK 18 log日志系统使用
概述:
DPDK 日志系統分為1-8個等級,在lib/librte_eal/common/include/rte_log.h文件中定義,每個DPDK模塊都可以定義一個預設日志輸出等級,只有日志輸出語句的等級小于等于預設輸出等級才能被輸出。
以下為dpdk對日志的分級:
/* Can't use 0, as it gives compiler warnings */ #define RTE_LOG_EMERG 1U /**< System is unusable. */ #define RTE_LOG_ALERT 2U /**< Action must be taken immediately. */ #define RTE_LOG_CRIT 3U /**< Critical conditions. */ #define RTE_LOG_ERR 4U /**< Error conditions. */ #define RTE_LOG_WARNING 5U /**< Warning conditions. */ #define RTE_LOG_NOTICE 6U /**< Normal but significant condition. */ #define RTE_LOG_INFO 7U /**< Informational. */ #define RTE_LOG_DEBUG 8U /**< Debug-level messages. */Dpdk 使用int rte_log(uint32_t level, uint32_t logtype, const char *format, …); 函數打印日志,傳入參數為:
-
此條日志輸出等級,
-
日志type,
-
輸出log信息,
但在dpdk中并不會直接使用rte_log,而是不同模塊對它進行二次封裝后使用
日志輸出分析
例如在drivers/net/ixgbe/ixgbe_ethdev.c + 1038 ,此條log默認不會被輸出,分析見后文
PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released", hw->bus.func);PMD_DRV_LOG的宏定義在ixgbe_log.h (通過ixgbe_ethdev.c對頭文件的include可以看出,每個使用了LOG的地方,都會include一個xxx_log.h的文件),它的定義為:
extern int ixgbe_logtype_driver; #define PMD_DRV_LOG_RAW(level, fmt, args...) \rte_log(RTE_LOG_ ## level, ixgbe_logtype_driver, "%s(): " fmt, \__func__, ## args)傳入的DEBUG被拼接為了RTE_LOG_DEBUG
對于宏中的ixgbe_logtype_driver 變量的定義和初始化:
//drivers/net/ixgbe/ixgbe_ethdev.c +8916 RTE_INIT(ixgbe_init_log){ixgbe_logtype_init = rte_log_register("pmd.net.ixgbe.init");if (ixgbe_logtype_init >= 0)rte_log_set_level(ixgbe_logtype_init, RTE_LOG_NOTICE);ixgbe_logtype_driver = rte_log_register("pmd.net.ixgbe.driver");if (ixgbe_logtype_driver >= 0)rte_log_set_level(ixgbe_logtype_driver, RTE_LOG_NOTICE);}返回一個int作為此日志的type( ixgbe_logtype_driver是為了方便代碼編寫,”pmd.net.ixgbe.init”是為了方便用戶,他們是一一映射的)。
RTE_LOG_NOTICE<RTE_LOG_DEBUG,因此pmd.net.ixgbe.init日志 的DEBUG信息默認將不會輸出。
log的使用
想要看到上文中ixgbe_logtype_driver 的debug級別日志需要在啟動時傳入–log-level參數,指定ixgbe_logtype_driver的debug開啟。
以testpmd為例子:
./mips-loongson3a-linuxapp-gcc/app/testpmd --log-level=pmd.net.ixgbe.driver:8則可以看見很多的debug信息被輸出。這里的pmd.net.ixgbe.driver就是rte_log_register時傳入的名字。
因此,想要看到對應的log,只需要展開二次封裝的宏(如上文的PMD_DRV_LOG)找到此條log對應的type名字,在–log-level中傳入設置即可
總結
以上是生活随笔為你收集整理的DPDK 18 log日志系统使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 类的设计
- 下一篇: 大数据案例之OD线分析