参考内核打印限频功能
#include <stdio.h>
#include <time.h>
#define FALSE 0
#define TRUE 1
/*
* 日志限频:打印第一条,之后间隔intervalMs打印一条
*/
#define PRINT_LIMIT(intervalMs) \
static long int lastTime = 0; \
long int currTime = clock(); \
int printFlag = FALSE; \
if ((currTime > lastTime + intervalMs) || (lastTime == 0)) { \
lastTime = currTime; \
printFlag = TRUE; \
} \
if (printFlag)
int main()
{
int i;
for (i = 0; i < 100; i++) {
PRINT_LIMIT(10) {
printf("i: %d time: %lld ms\n", i, clock());
}
}
return 0;
}