/alps/fwbench

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/fwbench

« back to all changes in this revision

Viewing changes to seqreader.c

  • Committer: Suren A. Chilingaryan
  • Date: 2012-04-15 14:32:49 UTC
  • Revision ID: csa@dside.dyndns.org-20120415143249-0i0cch4t0hfpuvqa
fsbench

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
#define FASTWRITER_SYNCIO_ALIGN 512
15
15
 
 
16
#define SYNC_MODE
16
17
#define BUFSIZE 2097152
17
 
#define BLOCK_SIZE 2097152
 
18
#ifdef SYNC_MODE
 
19
# define BLOCK_SIZE 2097152
 
20
#else /* SYNC_MODE */
 
21
# define BLOCK_SIZE 16384
 
22
#endif /* SYNC_MODE */
18
23
#define WRITE_INTERVAL 1
19
24
 
20
25
 
31
36
    size_t skip;
32
37
    size_t run;
33
38
    ssize_t res;
 
39
    size_t max_size = (size_t)-1;
34
40
    char *buffer;//[BUFSIZE];
35
41
    long double mcoef = 1000000. / (1024 * 1024);
 
42
    int flags = O_RDONLY|O_NOATIME|O_LARGEFILE;
 
43
 
 
44
#ifdef SYNC_MODE
 
45
    flags |= O_DIRECT;
 
46
#endif
36
47
    
37
48
    posix_memalign((void**)&buffer, FASTWRITER_SYNCIO_ALIGN, BUFSIZE);
38
49
    
39
50
    if (argc < 2) {
40
 
        printf("Usage: %s <directory|device> [skip]\n", argv[0]);
 
51
        printf("Usage: %s <directory|device> [skip|size]\n", argv[0]);
41
52
        exit(0);
42
53
    }
43
54
    
44
55
    if (strstr(argv[1], "/dev/")) {
45
 
        int fd = open(argv[1], O_RDONLY|O_NOATIME|O_LARGEFILE|O_DIRECT, 0);
 
56
        if (argc > 2) {
 
57
            max_size = atol(argv[2]);
 
58
            max_size *= 1024 * 1024 * 1024;
 
59
        }
 
60
 
 
61
        int fd = open(argv[1], flags, 0);
46
62
        if (fd < 0) {
47
63
            printf("Unable to open device %s\n", argv[1]);
48
64
            exit(1);
66
82
                last_write = us;
67
83
                printf("Reading: %s (%lu GB),  Measured speed: %zu MB/s\n", argv[0], total_size / 1024 / 1024 / 1024, (size_t)(mcoef * total_size / us));
68
84
            }
 
85
            
 
86
            if (total_size > max_size) {
 
87
                printf("Reading: %s (%lu GB),  Measured speed: %zu MB/s\n", argv[0], total_size / 1024 / 1024 / 1024, (size_t)(mcoef * total_size / us));
 
88
                break;
 
89
            }
 
90
        
69
91
            res = read(fd, buffer, size);
70
92
        }
71
93
        
100
122
 
101
123
        if (stat(ent->d_name, &st)) continue;
102
124
        if (!S_ISREG(st.st_mode)) continue;
103
 
        
 
125
 
 
126
#ifdef F_MODE
104
127
        FILE *f = fopen(ent->d_name, "r");
105
128
        if (!f) continue;
 
129
#else   
 
130
        int fd = open(ent->d_name, flags, 0);
 
131
        if (fd < 0) continue;
 
132
#endif  
106
133
        
107
134
        int size = st.st_blksize;
108
135
        
110
137
            printf("Buffer too small\n");
111
138
            exit(1);
112
139
        }
113
 
        
 
140
 
 
141
 
 
142
#ifdef F_MODE
114
143
        while (!feof(f)) {
115
144
            err = fread(buffer, 1, size, f);
116
 
            if (err < 0) {
117
 
                printf("Read failed\n");
118
 
                exit(1);
119
 
            }
120
 
        }
121
 
        
 
145
            if (err < 0) break;
 
146
        }
 
147
#else
 
148
# ifdef SYNC_MODE
 
149
        if (size < BLOCK_SIZE) size = BLOCK_SIZE;
 
150
# endif
 
151
        err = read(fd, buffer, size);
 
152
        while (err > 0) {
 
153
            err = read(fd, buffer, size);
 
154
        }
 
155
#endif
 
156
 
 
157
        if (err < 0) {
 
158
            printf("Read failed\n");
 
159
            exit(1);
 
160
        }
 
161
 
 
162
#ifdef F_MODE
122
163
        fclose(f);
 
164
#else
 
165
        close(fd);
 
166
#endif
123
167
 
124
168
        total_size += st.st_size;
125
169
        files++;