-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_disk_bw.cc
62 lines (47 loc) · 1.28 KB
/
test_disk_bw.cc
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
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/uio.h>
#include "common/Clock.h"
#include "common/safe_io.h"
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
void *buf;
int fd, count, loop = 0, ret;
if (argc != 4) {
fprintf(stderr, "Usage: %s device bsize count\n", argv[0]);
exit (0);
}
int bsize = atoi(argv[2]);
count = atoi(argv[3]);
posix_memalign(&buf, sysconf(_SC_PAGESIZE), bsize);
//if ((fd = open(argv[1], O_SYNC|O_RDWR)) < 0) {
if ((fd = open(argv[1], O_DIRECT|O_RDWR)) < 0) {
fprintf(stderr, "Can't open device %s\n", argv[1]);
exit (4);
}
utime_t start = ceph_clock_now(g_ceph_context);
while (loop++ < count) {
ret = safe_write(fd, buf, bsize);
if (ret)
ceph_abort();
//if ((loop % 100) == 0)
//fprintf(stderr, ".");
}
::fsync(fd);
::close(fd);
utime_t end = ceph_clock_now(g_ceph_context);
end -= start;
char hostname[80];
gethostname(hostname, 80);
double mb = bsize*count/1024/1024;
cout << hostname << "\t" << mb << " MB\t" << end << " seconds\t" << (mb / (double)end) << " MB/sec" << std::endl;
}