TIME_LOG_START &&TIME_LOG_END

来源:互联网 发布:数码兽传说 网络侦探pc 编辑:程序博客网 时间:2024/06/07 07:02

在linux内核中,如果想测试某个函数的执行花费多少时间,要以通过下面的两个宏来完成.

TIME_LOG_START();TIME_LOG_END();

使用demo如下:

TIME_LOG_START();ret = dev->bus->probe(dev); TIME_LOG_END("[probe] drv:%s dev:%s\n", drv->name, dev->init_name);

此宏定义在kernel/include/linux/time_log.h文件中,如下:

#define TIME_LOG_START() \    { \         unsigned long long _start_time = 0; \         unsigned long long _end_time = 0; \         unsigned long long _dur_time = 0; \        if(printk_disable_uart == 0){ \        _start_time = sched_clock(); \        } \        do { } while(0)#define TIME_LOG_END(X...) \                if(printk_disable_uart == 0){ \        _end_time = sched_clock(); \        _dur_time = _end_time - _start_time; \        printk(KERN_ERR X); \        printk(KERN_ERR"  s:%llu e:%llu d:%llu\n",  \            _start_time, _end_time, _dur_time ); \         if(_dur_time > 100000000){ \        printk(KERN_ERR"warning init time too long!\n");} \        } \    } \    do { } while(0)