在kernel中有时候需要code总插一些函数来看某段code执行的时间,可以参考下面的code
#ifdef DEBUG_TIMING
void debug_timestamp(char *msg)
{
struct timespec64 t;
getnstimeofday64(&t);
pr_debug("**%s: %lld.%9.9ld\n", msg, (long long) t.tv_sec, t.tv_nsec);
}
#else
#define debug_timestamp(x)
#endif
具体用法 debug_timestamp("Start2");
可以很方便的在kernel打印的log 中grep 关键字Start2 来找到自己关心内容执行的时间。如果在正式release 版本中只要关掉DEBUG_TIMING即可,不用修改原有的code逻辑。
#ifdef DEBUG_TIMING
void debug_timestamp(char *msg)
{
struct timespec64 t;
getnstimeofday64(&t);
pr_debug("**%s: %lld.%9.9ld\n", msg, (long long) t.tv_sec, t.tv_nsec);
}
#else
#define debug_timestamp(x)
#endif
具体用法 debug_timestamp("Start2");
可以很方便的在kernel打印的log 中grep 关键字Start2 来找到自己关心内容执行的时间。如果在正式release 版本中只要关掉DEBUG_TIMING即可,不用修改原有的code逻辑。