Use O_DIRECT in O_SYNC test of different size. Restructure O_DIRECT
authorBruce Momjian <bruce@momjian.us>
Sun, 16 Jan 2011 00:40:49 +0000 (19:40 -0500)
committerBruce Momjian <bruce@momjian.us>
Sun, 16 Jan 2011 00:40:49 +0000 (19:40 -0500)
error reporting to be more consistent.

src/tools/fsync/test_fsync.c

index 562da66907f2d2857d21a9e20e65a052d4fe0580..5a7c0d5c3c1ac4e125da805e1ea1d6b231f77bb9 100644 (file)
@@ -31,8 +31,8 @@
 
 #define WRITE_SIZE (8 * 1024)  /* 8k */
 
-#define LABEL_FORMAT   "        %-32s"
-#define NA_FORMAT      LABEL_FORMAT "%18s"
+#define LABEL_FORMAT       "        %-32s"
+#define NA_FORMAT          LABEL_FORMAT "%18s"
 
 
 int            ops_per_test = 2000;
@@ -365,12 +365,6 @@ test_sync(int writes_per_op)
     * If O_DIRECT is enabled, test that with open_sync
     */
 #if PG_O_DIRECT != 0
-   if (writes_per_op == 1)
-       printf(LABEL_FORMAT, "open_sync 8k direct I/O write");
-   else
-       printf(LABEL_FORMAT, "2 open_sync 8k direct I/O writes");
-   fflush(stdout);
-
    if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
    {
        printf(NA_FORMAT, "o_direct", "n/a**\n");
@@ -378,6 +372,12 @@ test_sync(int writes_per_op)
    }
    else
    {
+       if (writes_per_op == 1)
+           printf(LABEL_FORMAT, "open_sync 8k direct I/O write");
+       else
+           printf(LABEL_FORMAT, "2 open_sync 8k direct I/O writes");
+       fflush(stdout);
+
        gettimeofday(&start_t, NULL);
        for (ops = 0; ops < ops_per_test; ops++)
        {
@@ -423,47 +423,51 @@ test_open_syncs(void)
    printf("(This is designed to compare the cost of one large\n");
    printf("sync'ed write and two smaller sync'ed writes.)\n");
 
-   /* XXX no PG_O_DIRECT */
-
 /*
  * Test open_sync with different size files
  */
 #ifdef OPEN_SYNC_FLAG
-   printf(LABEL_FORMAT, "open_sync 16k write");
-   fflush(stdout);
-
-   if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1)
-       die("Cannot open output file.");
-   gettimeofday(&start_t, NULL);
-   for (ops = 0; ops < ops_per_test; ops++)
+   if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
+       printf(NA_FORMAT, "o_direct", "n/a**\n");
+   else
    {
-       if (write(tmpfile, buf, WRITE_SIZE * 2) != WRITE_SIZE * 2)
-           die("write failed");
-       if (lseek(tmpfile, 0, SEEK_SET) == -1)
-           die("seek failed");
-   }
-   gettimeofday(&stop_t, NULL);
-   close(tmpfile);
-   print_elapse(start_t, stop_t);
-
-   printf(LABEL_FORMAT, "2 open_sync 8k writes");
-   fflush(stdout);
+       printf(LABEL_FORMAT, "open_sync 16k write");
+       fflush(stdout);
 
-   if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1)
-       die("Cannot open output file.");
-   gettimeofday(&start_t, NULL);
-   for (ops = 0; ops < ops_per_test; ops++)
+       gettimeofday(&start_t, NULL);
+       for (ops = 0; ops < ops_per_test; ops++)
+       {
+           if (write(tmpfile, buf, WRITE_SIZE * 2) != WRITE_SIZE * 2)
+               die("write failed");
+           if (lseek(tmpfile, 0, SEEK_SET) == -1)
+               die("seek failed");
+       }
+       gettimeofday(&stop_t, NULL);
+       close(tmpfile);
+       print_elapse(start_t, stop_t);
+   }
+   
+   if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
+       printf(NA_FORMAT, "n/a**\n");
+   else
    {
-       if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
-           die("write failed");
-       if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
-           die("write failed");
-       if (lseek(tmpfile, 0, SEEK_SET) == -1)
-           die("seek failed");
+       printf(LABEL_FORMAT, "2 open_sync 8k writes");
+       fflush(stdout);
+
+       gettimeofday(&start_t, NULL);
+       for (ops = 0; ops < ops_per_test; ops++)
+       {
+           if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
+               die("write failed");
+           if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
+               die("write failed");
+           if (lseek(tmpfile, 0, SEEK_SET) == -1)
+               die("seek failed");
+       }
+       gettimeofday(&stop_t, NULL);
+       close(tmpfile);
+       print_elapse(start_t, stop_t);
    }
-   gettimeofday(&stop_t, NULL);
-   close(tmpfile);
-   print_elapse(start_t, stop_t);
 #else
    printf(NA_FORMAT, "open_sync", "n/a\n");
 #endif