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