Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * scantest.c - test the speed of the inode scan routine |
| 3 | */ |
| 4 | |
Theodore Ts'o | d1154eb | 2011-09-18 17:34:37 -0400 | [diff] [blame] | 5 | #include "config.h" |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 6 | #include <string.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <ctype.h> |
| 9 | #include <termios.h> |
| 10 | #include <time.h> |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 11 | #ifdef HAVE_GETOPT_H |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 12 | #include <getopt.h> |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 13 | #endif |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 14 | #include <unistd.h> |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 15 | #include <sys/ioctl.h> |
Theodore Ts'o | e71d873 | 2003-03-14 02:13:48 -0500 | [diff] [blame] | 16 | #ifdef HAVE_MALLOC_H |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 17 | #include <malloc.h> |
Theodore Ts'o | e71d873 | 2003-03-14 02:13:48 -0500 | [diff] [blame] | 18 | #endif |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 19 | #include <sys/resource.h> |
| 20 | |
| 21 | #include "et/com_err.h" |
| 22 | #include "../version.h" |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <string.h> |
| 26 | #include <unistd.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <sys/stat.h> |
| 29 | #include <sys/types.h> |
| 30 | #include <sys/time.h> |
| 31 | |
Theodore Ts'o | 54c637d | 2001-05-14 11:45:38 +0000 | [diff] [blame] | 32 | #include "ext2fs/ext2_fs.h" |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 33 | #include "ext2fs/ext2fs.h" |
| 34 | |
| 35 | |
| 36 | extern int isatty(int); |
| 37 | |
| 38 | const char * device_name = NULL; |
| 39 | |
| 40 | /* |
| 41 | * This structure is used for keeping track of how much resources have |
| 42 | * been used for a particular pass of e2fsck. |
| 43 | */ |
| 44 | struct resource_track { |
| 45 | struct timeval time_start; |
| 46 | struct timeval user_start; |
| 47 | struct timeval system_start; |
| 48 | void *brk_start; |
| 49 | }; |
| 50 | |
| 51 | struct resource_track global_rtrack; |
| 52 | |
| 53 | void init_resource_track(struct resource_track *track) |
| 54 | { |
| 55 | struct rusage r; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 56 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 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; |
| 62 | } |
| 63 | |
| 64 | static __inline__ float timeval_subtract(struct timeval *tv1, |
| 65 | struct timeval *tv2) |
| 66 | { |
| 67 | return ((tv1->tv_sec - tv2->tv_sec) + |
| 68 | ((float) (tv1->tv_usec - tv2->tv_usec)) / 1000000); |
| 69 | } |
| 70 | |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 71 | static void print_resource_track(struct resource_track *track) |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 72 | { |
| 73 | struct rusage r; |
| 74 | struct timeval time_end; |
| 75 | |
| 76 | gettimeofday(&time_end, 0); |
| 77 | getrusage(RUSAGE_SELF, &r); |
| 78 | |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 79 | printf(_("Memory used: %d, elapsed time: %6.3f/%6.3f/%6.3f\n"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 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)); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | |
| 88 | int main (int argc, char *argv[]) |
| 89 | { |
| 90 | errcode_t retval = 0; |
| 91 | int exit_value = 0; |
| 92 | int i; |
| 93 | ext2_filsys fs; |
| 94 | ext2_inode_scan scan; |
Theodore Ts'o | 86c627e | 2001-01-11 15:12:14 +0000 | [diff] [blame] | 95 | ext2_ino_t ino; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 96 | struct ext2_inode inode; |
| 97 | |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 98 | printf(_("size of inode=%d\n"), sizeof(inode)); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 99 | |
| 100 | device_name = "/dev/hda3"; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 101 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 102 | init_resource_track(&global_rtrack); |
| 103 | |
| 104 | retval = ext2fs_open(device_name, 0, |
| 105 | 0, 0, unix_io_manager, &fs); |
| 106 | if (retval) { |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 107 | com_err(argv[0], retval, _("while trying to open %s"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 108 | device_name); |
| 109 | exit(1); |
| 110 | } |
| 111 | |
| 112 | retval = ext2fs_open_inode_scan(fs, 0, &scan); |
| 113 | if (retval) { |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 114 | com_err(argv[0], retval, _("while opening inode scan")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 115 | exit(1); |
| 116 | } |
| 117 | retval = ext2fs_get_next_inode(scan, &ino, &inode); |
| 118 | if (retval) { |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 119 | com_err(argv[0], retval, _("while starting inode scan")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 120 | exit(1); |
| 121 | } |
| 122 | while (ino) { |
| 123 | if (!inode.i_links_count) |
| 124 | goto next; |
| 125 | printf("%lu\n", inode.i_blocks); |
| 126 | next: |
| 127 | retval = ext2fs_get_next_inode(scan, &ino, &inode); |
| 128 | if (retval) { |
| 129 | com_err(argv[0], retval, |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 130 | _("while doing inode scan")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 131 | exit(1); |
| 132 | } |
| 133 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 134 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 135 | |
| 136 | ext2fs_close(fs); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 137 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 138 | print_resource_track(&global_rtrack); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 139 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 140 | return exit_value; |
| 141 | } |