~ubuntu-branches/ubuntu/quantal/ceph/quantal

« back to all changes in this revision

Viewing changes to src/test/old/test_short_seek_read.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-07-16 09:56:24 UTC
  • mfrom: (0.3.11)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: package-import@ubuntu.com-20120716095624-azr2w4hbhei1rxmx
Tags: upstream-0.48
ImportĀ upstreamĀ versionĀ 0.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "include/types.h"
 
2
#include "common/Clock.h"
 
3
 
 
4
#include <linux/fs.h>
 
5
#include <unistd.h>
 
6
#include <sys/ioctl.h>
 
7
#include <sys/types.h>
 
8
#include <sys/stat.h>
 
9
#include <fcntl.h>
 
10
#include <string.h>
 
11
#include <errno.h>
 
12
 
 
13
int main(int argc, char **argv)
 
14
{
 
15
  char *fn = argv[1];
 
16
 
 
17
  int fd = ::open(fn, O_RDWR|O_DIRECT);//|O_SYNC|O_DIRECT);
 
18
  if (fd < 0) return 1;
 
19
 
 
20
  uint64_t bytes = 0;
 
21
  int r = ioctl(fd, BLKGETSIZE64, &bytes);
 
22
  uint64_t numblocks = bytes / 4096;
 
23
 
 
24
  //uint64_t numblocks = atoll(argv[2]) * 4;// / 4096;
 
25
  int count = 1000;
 
26
  
 
27
  cout << "fn " << fn << endl;
 
28
  cout << "numblocks " << numblocks << endl;
 
29
  
 
30
  int blocks = 1;
 
31
  while (blocks <= 1024) {
 
32
    //cout << "fd is " << fd << endl;
 
33
 
 
34
    void *buf;
 
35
    ::posix_memalign(&buf, 4096, 4096*blocks);
 
36
    
 
37
    int s = blocks*4096;
 
38
 
 
39
    double timeper = 0.0;
 
40
    for (int i=0; i<count; i++) {
 
41
      off64_t so, o = (lrand48() % numblocks) * 4096;
 
42
      //cout << "s = " << s << " o = " << o << endl;
 
43
      //::lseek(fd, o, SEEK_SET);
 
44
      lseek64(fd, o, SEEK_SET);
 
45
      int r = ::read(fd, buf, 4096);
 
46
      //int r = ::read(fd, buf, s);
 
47
      if (r < 0) cout << "r = " << r << " " << strerror(errno) << endl;
 
48
 
 
49
      int range = 1000000/4096;
 
50
      so = o + 4096*((rand() % range) );//- range/2);
 
51
      //cout << o << " " << so << " " << (so-o) << endl;
 
52
 
 
53
      utime_t start = ceph_clock_now(g_ceph_context);
 
54
      lseek64(fd, so, SEEK_SET);
 
55
      r = ::read(fd, buf, blocks*4096);
 
56
      utime_t end = ceph_clock_now(g_ceph_context);
 
57
      timeper += (end-start);
 
58
    }
 
59
    
 
60
    timeper /= count;
 
61
    cout << blocks << "\t" << s << "\t" << (double)timeper << endl;
 
62
 
 
63
    blocks *= 2;
 
64
    free(buf);
 
65
  }
 
66
 
 
67
  close(fd);  
 
68
 
 
69
}
 
70