11/*
2- * $PostgreSQL: pgsql/src/tools/fsync/test_fsync.c,v 1.30 2010/07/06 19:19:02 momjian Exp $
2+ * $PostgreSQL: pgsql/src/tools/fsync/test_fsync.c,v 1.31 2010/07/13 17:00:50 momjian Exp $
33 *
44 *
55 *test_fsync.c
@@ -80,7 +80,8 @@ main(int argc, char *argv[])
8080 * Simple write
8181 */
8282printf ("Simple write:\n" );
83- /* write only */
83+ printf (LABEL_FORMAT ,"8k write" );
84+ fflush (stdout );
8485gettimeofday (& start_t ,NULL );
8586for (i = 0 ;i < loops ;i ++ )
8687{
@@ -91,7 +92,6 @@ main(int argc, char *argv[])
9192close (tmpfile );
9293}
9394gettimeofday (& stop_t ,NULL );
94- printf (LABEL_FORMAT ,"8k write" );
9595print_elapse (start_t ,stop_t );
9696
9797/*
@@ -100,7 +100,8 @@ main(int argc, char *argv[])
100100printf ("\nCompare file sync methods using one write:\n" );
101101
102102#ifdef OPEN_DATASYNC_FLAG
103- /* open_dsync, write */
103+ printf (LABEL_FORMAT ,"open_datasync 8k write" );
104+ fflush (stdout );
104105if ((tmpfile = open (filename ,O_RDWR |O_DSYNC ,0 ))== -1 )
105106die ("Cannot open output file." );
106107gettimeofday (& start_t ,NULL );
@@ -113,14 +114,14 @@ main(int argc, char *argv[])
113114}
114115gettimeofday (& stop_t ,NULL );
115116close (tmpfile );
116- printf (LABEL_FORMAT ,"open_datasync 8k write" );
117117print_elapse (start_t ,stop_t );
118118#else
119- printf ("\t(open_datasync unavailable)\n" );
119+ printf ("\t(unavailable: open_datasync )\n" );
120120#endif
121121
122122#ifdef OPEN_SYNC_FLAG
123- /* open_fsync, write */
123+ printf (LABEL_FORMAT ,"open_sync 8k write" );
124+ fflush (stdout );
124125if ((tmpfile = open (filename ,O_RDWR |OPEN_SYNC_FLAG ,0 ))== -1 )
125126die ("Cannot open output file." );
126127gettimeofday (& start_t ,NULL );
@@ -133,14 +134,14 @@ main(int argc, char *argv[])
133134}
134135gettimeofday (& stop_t ,NULL );
135136close (tmpfile );
136- printf (LABEL_FORMAT ,"open_sync 8k write" );
137137print_elapse (start_t ,stop_t );
138138#else
139- printf ("\t(open_sync unavailable)\n" );
139+ printf ("\t(unavailable: open_sync )\n" );
140140#endif
141141
142142#ifdef HAVE_FDATASYNC
143- /* write, fdatasync */
143+ printf (LABEL_FORMAT ,"8k write, fdatasync" );
144+ fflush (stdout );
144145if ((tmpfile = open (filename ,O_RDWR ,0 ))== -1 )
145146die ("Cannot open output file." );
146147gettimeofday (& start_t ,NULL );
@@ -154,13 +155,13 @@ main(int argc, char *argv[])
154155}
155156gettimeofday (& stop_t ,NULL );
156157close (tmpfile );
157- printf (LABEL_FORMAT ,"8k write, fdatasync" );
158158print_elapse (start_t ,stop_t );
159159#else
160- printf ("\t(fdatasync unavailable)\n" );
160+ printf ("\t(unavailable: fdatasync )\n" );
161161#endif
162162
163- /* write, fsync, close */
163+ printf (LABEL_FORMAT ,"8k write, fsync" );
164+ fflush (stdout );
164165if ((tmpfile = open (filename ,O_RDWR ,0 ))== -1 )
165166die ("Cannot open output file." );
166167gettimeofday (& start_t ,NULL );
@@ -175,7 +176,6 @@ main(int argc, char *argv[])
175176}
176177gettimeofday (& stop_t ,NULL );
177178close (tmpfile );
178- printf (LABEL_FORMAT ,"8k write, fsync" );
179179print_elapse (start_t ,stop_t );
180180
181181/*
@@ -184,7 +184,8 @@ main(int argc, char *argv[])
184184printf ("\nCompare file sync methods using two writes:\n" );
185185
186186#ifdef OPEN_DATASYNC_FLAG
187- /* open_dsync, write */
187+ printf (LABEL_FORMAT ,"2 open_datasync 8k writes" );
188+ fflush (stdout );
188189if ((tmpfile = open (filename ,O_RDWR |O_DSYNC ,0 ))== -1 )
189190die ("Cannot open output file." );
190191gettimeofday (& start_t ,NULL );
@@ -199,14 +200,14 @@ main(int argc, char *argv[])
199200}
200201gettimeofday (& stop_t ,NULL );
201202close (tmpfile );
202- printf (LABEL_FORMAT ,"2 open_datasync 8k writes" );
203203print_elapse (start_t ,stop_t );
204204#else
205- printf ("\t(open_datasync unavailable)\n" );
205+ printf ("\t(unavailable: open_datasync )\n" );
206206#endif
207207
208208#ifdef OPEN_SYNC_FLAG
209- /* open_fsync, write */
209+ printf (LABEL_FORMAT ,"2 open_sync 8k writes" );
210+ fflush (stdout );
210211if ((tmpfile = open (filename ,O_RDWR |OPEN_SYNC_FLAG ,0 ))== -1 )
211212die ("Cannot open output file." );
212213gettimeofday (& start_t ,NULL );
@@ -221,12 +222,12 @@ main(int argc, char *argv[])
221222}
222223gettimeofday (& stop_t ,NULL );
223224close (tmpfile );
224- printf (LABEL_FORMAT ,"2 open_sync 8k writes" );
225225print_elapse (start_t ,stop_t );
226226#endif
227227
228228#ifdef HAVE_FDATASYNC
229- /* write, fdatasync */
229+ printf (LABEL_FORMAT ,"8k write, 8k write, fdatasync" );
230+ fflush (stdout );
230231if ((tmpfile = open (filename ,O_RDWR ,0 ))== -1 )
231232die ("Cannot open output file." );
232233gettimeofday (& start_t ,NULL );
@@ -242,13 +243,13 @@ main(int argc, char *argv[])
242243}
243244gettimeofday (& stop_t ,NULL );
244245close (tmpfile );
245- printf (LABEL_FORMAT ,"8k write, 8k write, fdatasync" );
246246print_elapse (start_t ,stop_t );
247247#else
248- printf ("\t(fdatasync unavailable)\n" );
248+ printf ("\t(unavailable: fdatasync )\n" );
249249#endif
250250
251- /* write, fsync, close */
251+ printf (LABEL_FORMAT ,"8k write, 8k write, fsync" );
252+ fflush (stdout );
252253if ((tmpfile = open (filename ,O_RDWR ,0 ))== -1 )
253254die ("Cannot open output file." );
254255gettimeofday (& start_t ,NULL );
@@ -265,7 +266,6 @@ main(int argc, char *argv[])
265266}
266267gettimeofday (& stop_t ,NULL );
267268close (tmpfile );
268- printf (LABEL_FORMAT ,"8k write, 8k write, fsync" );
269269print_elapse (start_t ,stop_t );
270270
271271/*
@@ -274,7 +274,8 @@ main(int argc, char *argv[])
274274printf ("\nCompare open_sync with different sizes:\n" );
275275
276276#ifdef OPEN_SYNC_FLAG
277- /* 16k open_sync write */
277+ printf (LABEL_FORMAT ,"open_sync 16k write" );
278+ fflush (stdout );
278279if ((tmpfile = open (filename ,O_RDWR |OPEN_SYNC_FLAG ,0 ))== -1 )
279280die ("Cannot open output file." );
280281gettimeofday (& start_t ,NULL );
@@ -287,10 +288,10 @@ main(int argc, char *argv[])
287288}
288289gettimeofday (& stop_t ,NULL );
289290close (tmpfile );
290- printf (LABEL_FORMAT ,"open_sync 16k write" );
291291print_elapse (start_t ,stop_t );
292292
293- /* Two 8k open_sync writes */
293+ printf (LABEL_FORMAT ,"2 open_sync 8k writes" );
294+ fflush (stdout );
294295if ((tmpfile = open (filename ,O_RDWR |OPEN_SYNC_FLAG ,0 ))== -1 )
295296die ("Cannot open output file." );
296297gettimeofday (& start_t ,NULL );
@@ -305,10 +306,9 @@ main(int argc, char *argv[])
305306}
306307gettimeofday (& stop_t ,NULL );
307308close (tmpfile );
308- printf (LABEL_FORMAT ,"2 open_sync 8k writes" );
309309print_elapse (start_t ,stop_t );
310310#else
311- printf ("\t(open_sync unavailable)\n" );
311+ printf ("\t(unavailable: open_sync )\n" );
312312#endif
313313
314314/*
@@ -318,7 +318,8 @@ main(int argc, char *argv[])
318318printf ("(If the times are similar, fsync() can sync data written\n" );
319319printf ("on a different descriptor.)\n" );
320320
321- /* write, fsync, close */
321+ printf (LABEL_FORMAT ,"8k write, fsync, close" );
322+ fflush (stdout );
322323gettimeofday (& start_t ,NULL );
323324for (i = 0 ;i < loops ;i ++ )
324325{
@@ -335,10 +336,10 @@ main(int argc, char *argv[])
335336close (tmpfile );
336337}
337338gettimeofday (& stop_t ,NULL );
338- printf (LABEL_FORMAT ,"8k write, fsync, close" );
339339print_elapse (start_t ,stop_t );
340340
341- /* write, close, fsync */
341+ printf (LABEL_FORMAT ,"8k write, close, fsync" );
342+ fflush (stdout );
342343gettimeofday (& start_t ,NULL );
343344for (i = 0 ;i < loops ;i ++ )
344345{
@@ -355,7 +356,6 @@ main(int argc, char *argv[])
355356close (tmpfile );
356357}
357358gettimeofday (& stop_t ,NULL );
358- printf (LABEL_FORMAT ,"8k write, close, fsync" );
359359print_elapse (start_t ,stop_t );
360360
361361/* cleanup */