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