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