每间隔一段时间读取/proc/sys/kernel/sched_elastic_debug
文件里面的值,C语言例子
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
struct timespec reg, rem;
FILE *fd;
int debug;
size_t st;
int sec = 1;
int nsec = 0;
unsigned long long sleeptime = 0;
reg.tv_sec = sec;
reg.tv_nsec = nsec;
while(1){
fd = fopen("/proc/sys/kernel/sched_elastic_debug", "r");
if(!fd){
printf("open file failed\n");
exit(1);
}
fscanf(fd, "%d", &debug);
printf("sleeptime:%llu(ns), debug is: %d\n", sleeptime, debug);
fclose(fd);
if( -1 == nanosleep(®, &rem)){
printf("error\n");
exit(1);
}
else {
sleeptime += (sec*1000000000 + nsec);
}
}
return 0;
}