/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 19:29:16 UTC
  • Revision ID: csa@dside.dyndns.org-20120413192916-zn0x5i17epujbj1t
Support RAW devices by seqreader

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define _GNU_SOURCE
 
2
 
1
3
#include <stdio.h>
2
4
#include <stdlib.h>
3
5
#include <sys/types.h>
5
7
#include <sys/time.h>
6
8
#include <unistd.h>
7
9
#include <dirent.h>
8
 
 
9
 
#define BUFSIZE 65536
 
10
#include <fcntl.h>
 
11
#include <string.h>
 
12
#include <errno.h>
 
13
 
 
14
#define BUFSIZE 1048576//65536
 
15
#define BLOCK_SIZE 16384//16384
 
16
#define WRITE_INTERVAL 1
 
17
 
10
18
 
11
19
int main(int argc, char *argv[]) {
12
20
    int err;
17
25
    size_t us;
18
26
    size_t files = 0;
19
27
    size_t total_size = 0;
 
28
    size_t last_write = 0;
20
29
    size_t skip;
21
30
    size_t run;
22
 
    char buffer[65536];
 
31
    char buffer[BUFSIZE];
23
32
    
24
33
    if (argc < 2) {
25
 
        printf("Usage: %s <directory> [skip]\n", argv[0]);
 
34
        printf("Usage: %s <directory|device> [skip]\n", argv[0]);
26
35
        exit(0);
27
36
    }
28
37
    
 
38
    if (!strstr(argv[0], "/dev/")) {
 
39
        int fd = open(argv[1], O_RDONLY|O_NOATIME|O_LARGEFILE/*|O_DIRECT*/, 0);
 
40
        if (fd < 0) {
 
41
            printf("Unable to open device %s\n", argv[1]);
 
42
            exit(1);
 
43
        }
 
44
        
 
45
        int size = BLOCK_SIZE;
 
46
        
 
47
        gettimeofday(&start, NULL);
 
48
        
 
49
        err = read(fd, buffer, size);
 
50
        while (err > 0) {
 
51
            total_size += err;
 
52
 
 
53
            gettimeofday(&tv, NULL);
 
54
            us = (tv.tv_sec - start.tv_sec) * 1000000 + (tv.tv_usec - start.tv_usec);
 
55
            if ((us - last_write) > WRITE_INTERVAL * 1000000) {
 
56
                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);
 
58
            }
 
59
            err = read(fd, buffer, size);
 
60
        }
 
61
        
 
62
        close(fd);
 
63
 
 
64
 
 
65
        return 0;
 
66
    }
 
67
 
29
68
    chdir(argv[1]);
30
69
 
31
70
    if (argc > 2) {
32
71
        SKIP = atoi(argv[2]);
33
72
        
34
 
        printf("Skip %i\n", SKIP);
 
73
        printf("Skip %zu\n", SKIP);
35
74
    }
36
75
 
37
76
    gettimeofday(&start, NULL);
38
77
    for (run = 0; run < SKIP; run++) {
39
78
      skip = 0;
40
79
      dir = opendir(".");
41
 
      while (ent = readdir(dir)) {
 
80
      while ((ent = readdir(dir))) {
42
81
        struct stat st;
43
82
        
44
83
        if (((skip++)%SKIP) != run) continue;