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

« back to all changes in this revision

Viewing changes to src/test/old/test_disk_bw.cc

  • 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
 
 
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, ret;
 
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(g_ceph_context);
 
43
  while (loop++ < count) {
 
44
    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(g_ceph_context);
 
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
}