/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-13 23:59:11 UTC
  • Revision ID: csa@dside.dyndns.org-20120413235911-mcow2tahxkoe2urg
Report speed in seqreader using proper MB/s

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#include <string.h>
12
12
#include <errno.h>
13
13
 
14
 
#define BUFSIZE 1048576//65536
15
 
#define BLOCK_SIZE 16384//16384
 
14
#define BUFSIZE 65536
 
15
#define BLOCK_SIZE 16384
16
16
#define WRITE_INTERVAL 1
17
17
 
18
18
 
28
28
    size_t last_write = 0;
29
29
    size_t skip;
30
30
    size_t run;
 
31
    ssize_t res;
31
32
    char buffer[BUFSIZE];
 
33
    long double mcoef = 1000000. / (1024 * 1024);
32
34
    
33
35
    if (argc < 2) {
34
36
        printf("Usage: %s <directory|device> [skip]\n", argv[0]);
42
44
            exit(1);
43
45
        }
44
46
        
45
 
        int size = BLOCK_SIZE;
 
47
        size_t size = BLOCK_SIZE;
46
48
        
47
49
        gettimeofday(&start, NULL);
48
50
        
49
 
        err = read(fd, buffer, size);
50
 
        while (err > 0) {
51
 
            total_size += err;
 
51
        res = read(fd, buffer, size);
 
52
        while (res > 0) {
 
53
            if (res != size) {
 
54
                printf("Incomplete read: %zu bytes read instead of %zu\n", res, size);
 
55
                exit(-1);
 
56
            }
 
57
            total_size += res;
52
58
 
53
59
            gettimeofday(&tv, NULL);
54
60
            us = (tv.tv_sec - start.tv_sec) * 1000000 + (tv.tv_usec - start.tv_usec);
55
61
            if ((us - last_write) > WRITE_INTERVAL * 1000000) {
56
62
                last_write = us;
57
 
                printf("Reading: %s (%lu GB),  Measured speed: %lu mB/s\n", argv[0], total_size / 1024 / 1024 / 1024, total_size / us);
 
63
                printf("Reading: %s (%lu GB),  Measured speed: %zu MB/s\n", argv[0], total_size / 1024 / 1024 / 1024, (size_t)(mcoef * total_size / us));
58
64
            }
59
 
            err = read(fd, buffer, size);
 
65
            res = read(fd, buffer, size);
60
66
        }
61
67
        
62
68
        close(fd);
63
69
 
 
70
        if (res < 0) {
 
71
            printf("Read failed with errno %i\n", errno);
 
72
            exit(-1);
 
73
        }
64
74
 
65
75
        return 0;
66
76
    }
110
120
        
111
121
        gettimeofday(&tv, NULL);
112
122
        us = (tv.tv_sec - start.tv_sec) * 1000000 + (tv.tv_usec - start.tv_usec);
113
 
        printf("Reading: %s (%lu MB), Read: %lu files (%lu GB),  Measured speed: %lu mB/s\n", ent->d_name, st.st_size/1024/1024, files, total_size / 1024 / 1024 / 1024, total_size / us);
 
123
        printf("Reading: %s (%lu MB), Read: %lu files (%lu GB),  Measured speed: %zu MB/s\n", ent->d_name, st.st_size/1024/1024, files, total_size / 1024 / 1024 / 1024, (size_t)(mcoef * total_size / us));
114
124
      }
115
125
      closedir(dir);
116
126
    }