#include #include int main(int argc, char ** argv) { int x, y; FILE *fd; int HZ; unsigned long base_time, current_jiffies; unsigned long time; int RW; long read=0, write=0, total=0; if (argc == 1 || argc >=4) { printf("usage:\n"); printf("(1) ./statistic \n"); printf("(2) ./statistic \n"); return 0; } if (argc == 2 || argc ==3) { fd=fopen("/proc/jiffies", "r"); fscanf(fd, "HZ=%d\nbase_time=%lu\ncurrent_jiffies=%lu\n", &HZ, &base_time, ¤t_jiffies); fclose(fd); printf("HZ=%d\nbase_time=%lu\ncurrent_jiffies=%lu\n\n", HZ, base_time, current_jiffies); if (argc == 2) { x = atoi(argv[1]); fd=fopen("/proc/statistic", "r"); while (1) { if(fscanf(fd, "struct bio:\ntime: %lu\nRead or Write %d\n\n", &time, &RW)==EOF) { printf("To the End\n\n"); break; } if ((current_jiffies-base_time-time) < x*HZ) { printf("struct bio:\ntime=%lu\nRW=%d\n\n", time, RW); if (RW) write++; else read++; total++; } else break; } fclose(fd); printf("Read bio: %ld\nWrite bio: %ld\nTotal bio: %ld\n", read, write, total); } if (argc == 3) { x = atoi(argv[1]); y = atoi(argv[2]); //printf("x=%d, y=%d\n", x, y); fd=fopen("/proc/statistic", "r"); while (1) { if(fscanf(fd, "struct bio:\ntime: %lu\nRead or Write %d\n\n", &time, &RW)==EOF) { printf("To the End\n\n"); break; } if (time>x*HZ && time