Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / old / test_disk_bw.cc
1
2 #include <sys/time.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <errno.h>
11 #include <sys/uio.h>
12
13 #include "common/Clock.h"
14 #include "common/safe_io.h"
15
16 #include <iostream>
17 using namespace std;
18
19 int main(int argc, char **argv)
20 {
21   void   *buf;
22   int     fd, count, loop = 0;
23   
24   if (argc != 4) {
25     fprintf(stderr, "Usage: %s device bsize count\n", argv[0]);
26     exit (0);
27   }
28   
29   int bsize = atoi(argv[2]);
30   count = atoi(argv[3]);
31   
32   posix_memalign(&buf, sysconf(_SC_PAGESIZE), bsize);
33   
34   //if ((fd = open(argv[1], O_SYNC|O_RDWR)) < 0) {  
35   if ((fd = open(argv[1], O_DIRECT|O_RDWR)) < 0) {
36
37     fprintf(stderr, "Can't open device %s\n", argv[1]);
38     exit (4);
39   }
40   
41  
42   utime_t start = ceph_clock_now();
43   while (loop++ < count) {
44     int ret = safe_write(fd, buf, bsize);
45     if (ret)
46       ceph_abort();
47     //if ((loop % 100) == 0) 
48     //fprintf(stderr, ".");
49   }
50   ::fsync(fd);
51   ::close(fd);
52   utime_t end = ceph_clock_now();
53   end -= start;
54
55
56   char hostname[80];
57   gethostname(hostname, 80);
58   
59   double mb = bsize*count/1024/1024;
60
61   cout << hostname << "\t" << mb << " MB\t" << end << " seconds\t" << (mb / (double)end) << " MB/sec" << std::endl;
62 }