summaryrefslogtreecommitdiffstats
path: root/src/test/old/test_short_seek_read.c
blob: 9737025aa881b4780a923bae7c079413bbd284f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "include/types.h"
#include "common/Clock.h"

#include <linux/fs.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>

int main(int argc, char **argv)
{
  char *fn = argv[1];

  int fd = ::open(fn, O_RDWR|O_DIRECT);//|O_SYNC|O_DIRECT);
  if (fd < 0) return 1;

  uint64_t bytes = 0;
  int r = ioctl(fd, BLKGETSIZE64, &bytes);
  uint64_t numblocks = bytes / 4096;

  //uint64_t numblocks = atoll(argv[2]) * 4;// / 4096;
  int count = 1000;
  
  cout << "fn " << fn << endl;
  cout << "numblocks " << numblocks << endl;
  
  int blocks = 1;
  while (blocks <= 1024) {
    //cout << "fd is " << fd << endl;

    void *buf;
    ::posix_memalign(&buf, 4096, 4096*blocks);
    
    int s = blocks*4096;

    double timeper = 0.0;
    for (int i=0; i<count; i++) {
      off64_t so, o = (lrand48() % numblocks) * 4096;
      //cout << "s = " << s << " o = " << o << endl;
      //::lseek(fd, o, SEEK_SET);
      lseek64(fd, o, SEEK_SET);
      int r = ::read(fd, buf, 4096);
      //int r = ::read(fd, buf, s);
      if (r < 0) cout << "r = " << r << " " << strerror(errno) << endl;

      int range = 1000000/4096;
      so = o + 4096*((rand() % range) );//- range/2);
      //cout << o << " " << so << " " << (so-o) << endl;

      utime_t start = ceph_clock_now();
      lseek64(fd, so, SEEK_SET);
      r = ::read(fd, buf, blocks*4096);
      utime_t end = ceph_clock_now();
      timeper += (end-start);
    }
    
    timeper /= count;
    cout << blocks << "\t" << s << "\t" << (double)timeper << endl;

    blocks *= 2;
    free(buf);
  }

  close(fd);  

}