2 * scantest.c - test the speed of the inode scan routine
15 #include <sys/ioctl.h>
19 #include <sys/resource.h>
21 #include "et/com_err.h"
22 #include "../version.h"
29 #include <sys/types.h>
32 #include "ext2fs/ext2_fs.h"
33 #include "ext2fs/ext2fs.h"
36 extern int isatty(int);
38 const char * device_name = NULL;
41 * This structure is used for keeping track of how much resources have
42 * been used for a particular pass of e2fsck.
44 struct resource_track {
45 struct timeval time_start;
46 struct timeval user_start;
47 struct timeval system_start;
51 struct resource_track global_rtrack;
53 void init_resource_track(struct resource_track *track)
57 track->brk_start = sbrk(0);
58 gettimeofday(&track->time_start, 0);
59 getrusage(RUSAGE_SELF, &r);
60 track->user_start = r.ru_utime;
61 track->system_start = r.ru_stime;
64 static __inline__ float timeval_subtract(struct timeval *tv1,
67 return ((tv1->tv_sec - tv2->tv_sec) +
68 ((float) (tv1->tv_usec - tv2->tv_usec)) / 1000000);
71 static void print_resource_track(struct resource_track *track)
74 struct timeval time_end;
76 gettimeofday(&time_end, 0);
77 getrusage(RUSAGE_SELF, &r);
79 printf(_("Memory used: %d, elapsed time: %6.3f/%6.3f/%6.3f\n"),
80 (int) (((char *) sbrk(0)) - ((char *) track->brk_start)),
81 timeval_subtract(&time_end, &track->time_start),
82 timeval_subtract(&r.ru_utime, &track->user_start),
83 timeval_subtract(&r.ru_stime, &track->system_start));
88 int main (int argc, char *argv[])
96 struct ext2_inode inode;
98 printf(_("size of inode=%d\n"), sizeof(inode));
100 device_name = "/dev/hda3";
102 init_resource_track(&global_rtrack);
104 retval = ext2fs_open(device_name, 0,
105 0, 0, unix_io_manager, &fs);
107 com_err(argv[0], retval, _("while trying to open %s"),
112 retval = ext2fs_open_inode_scan(fs, 0, &scan);
114 com_err(argv[0], retval, _("while opening inode scan"));
117 retval = ext2fs_get_next_inode(scan, &ino, &inode);
119 com_err(argv[0], retval, _("while starting inode scan"));
123 if (!inode.i_links_count)
125 printf("%lu\n", inode.i_blocks);
127 retval = ext2fs_get_next_inode(scan, &ino, &inode);
129 com_err(argv[0], retval,
130 _("while doing inode scan"));
136 ext2fs_close_free(&fs);
138 print_resource_track(&global_rtrack);