2 * Test to see how quickly we can scan the inode table (not doing
19 #include <sys/ioctl.h>
24 #include <sys/resource.h>
26 #if EXT2_FLAT_INCLUDES
31 #include "ext2fs/ext2_fs.h"
32 #include "ext2fs/ext2fs.h"
33 #include "blkid/blkid.h"
36 #include "et/com_err.h"
37 #include "../version.h"
39 struct resource_track {
40 struct timeval time_start;
41 struct timeval user_start;
42 struct timeval system_start;
44 unsigned long long bytes_read;
45 unsigned long long bytes_written;
48 extern int isatty(int);
50 const char * program_name = "iscan";
51 const char * device_name = NULL;
56 int inode_buffer_blocks = 0;
57 int invalid_bitmaps = 0;
59 struct resource_track global_rtrack;
61 void init_resource_track(struct resource_track *track, io_channel channel)
66 io_stats io_start = 0;
68 track->brk_start = sbrk(0);
69 gettimeofday(&track->time_start, 0);
72 memset(&r, 0, sizeof(struct rusage));
74 getrusage(RUSAGE_SELF, &r);
75 track->user_start = r.ru_utime;
76 track->system_start = r.ru_stime;
78 track->user_start.tv_sec = track->user_start.tv_usec = 0;
79 track->system_start.tv_sec = track->system_start.tv_usec = 0;
81 track->bytes_read = 0;
82 track->bytes_written = 0;
83 if (channel && channel->manager && channel->manager->get_stats)
84 channel->manager->get_stats(channel, &io_start);
86 track->bytes_read = io_start->bytes_read;
87 track->bytes_written = io_start->bytes_written;
91 static float timeval_subtract(struct timeval *tv1,
94 return ((tv1->tv_sec - tv2->tv_sec) +
95 ((float) (tv1->tv_usec - tv2->tv_usec)) / 1000000);
98 void print_resource_track(const char *desc,
99 struct resource_track *track, io_channel channel)
101 #ifdef HAVE_GETRUSAGE
104 struct timeval time_end;
106 gettimeofday(&time_end, 0);
109 printf("%s: ", desc);
111 #define kbytes(x) (((unsigned long long)(x) + 1023) / 1024)
112 #ifdef HAVE_MALLINFO2
114 struct mallinfo2 malloc_info = mallinfo2();
116 printf("Memory used: %lluk/%lluk (%lluk/%lluk), ",
117 kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
118 kbytes(malloc_info.uordblks),
119 kbytes(malloc_info.fordblks));
121 #elif defined HAVE_MALLINFO
122 /* don't use mallinfo() if over 2GB used, since it returns "int" */
123 if ((char *)sbrk(0) - (char *)track->brk_start < 2LL << 30) {
124 struct mallinfo malloc_info = mallinfo();
126 printf("Memory used: %lluk/%lluk (%lluk/%lluk), ",
127 kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
128 kbytes(malloc_info.uordblks),
129 kbytes(malloc_info.fordblks));
132 printf("Memory used: %lluk, ",
133 kbytes(((char *)sbrk(0)) - ((char *)track->brk_start)));
135 #ifdef HAVE_GETRUSAGE
136 getrusage(RUSAGE_SELF, &r);
138 printf("time: %5.2f/%5.2f/%5.2f\n",
139 timeval_subtract(&time_end, &track->time_start),
140 timeval_subtract(&r.ru_utime, &track->user_start),
141 timeval_subtract(&r.ru_stime, &track->system_start));
143 printf("elapsed time: %6.3f\n",
144 timeval_subtract(&time_end, &track->time_start));
146 #define mbytes(x) (((x) + 1048575) / 1048576)
147 if (channel && channel->manager && channel->manager->get_stats) {
149 unsigned long long bytes_read = 0;
150 unsigned long long bytes_written = 0;
153 printf("%s: ", desc);
155 channel->manager->get_stats(channel, &delta);
157 bytes_read = delta->bytes_read - track->bytes_read;
158 bytes_written = delta->bytes_written -
159 track->bytes_written;
161 printf("I/O read: %lluMB, write: %lluMB, "
163 mbytes(bytes_read), mbytes(bytes_written),
164 (double)mbytes(bytes_read + bytes_written) /
165 timeval_subtract(&time_end, &track->time_start));
169 static void usage(void)
172 "Usage: %s [-F] [-I inode_buffer_blocks] device\n",
177 static void PRS(int argc, char *argv[])
182 extern void *mallwatch;
186 setbuf(stdout, NULL);
187 setbuf(stderr, NULL);
188 initialize_ext2_error_table();
191 program_name = *argv;
192 while ((c = getopt (argc, argv, "FI")) != EOF)
198 inode_buffer_blocks = atoi(optarg);
203 device_name = argv[optind];
205 int fd = open(device_name, O_RDONLY, 0);
208 com_err("open", errno,
209 "while opening %s for flushing", device_name);
212 if ((retval = ext2fs_sync_device(fd, 1))) {
213 com_err("ext2fs_sync_device", retval,
214 "while trying to flush %s", device_name);
221 int main (int argc, char *argv[])
223 errcode_t retval = 0;
227 __u32 num_inodes = 0;
228 struct ext2_inode inode;
229 ext2_inode_scan scan;
233 retval = ext2fs_open(device_name, 0,
234 0, 0, unix_io_manager, &fs);
236 com_err(program_name, retval, "while trying to open '%s'",
241 init_resource_track(&global_rtrack, fs->io);
243 retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan);
245 com_err(program_name, retval, "while opening inode scan");
250 retval = ext2fs_get_next_inode(scan, &ino, &inode);
252 com_err(program_name, retval,
253 "while getting next inode");
261 print_resource_track(NULL, &global_rtrack, fs->io);
262 printf("%u inodes scanned.\n", num_inodes);