]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/old/test_seek_read.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / old / test_seek_read.c
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 utime_t start = ceph_clock_now();
40 for (int i=0; i<count; i++) {
41 off64_t o = (lrand48() % numblocks) * 4096;
42 //cout << "s = " << s << " o = " << o << endl;
43 //::lseek(fd, o, SEEK_SET);
44 lseek64(fd, o, SEEK_SET);
45
46 int r = ::read(fd, buf, blocks*4096);
47 //int r = ::read(fd, buf, s);
48 if (r < 0) cout << "r = " << r << " " << strerror(errno) << endl;
49 }
50 utime_t end = ceph_clock_now();
51
52 double timeper = end - start;
53 timeper /= count;
54 cout << blocks << "\t" << s << "\t" << (double)timeper << endl;
55
56 blocks *= 2;
57 free(buf);
58 }
59
60 close(fd);
61
62 }
63