11/*
2- * $PostgreSQL: pgsql/src/tools/fsync/test_fsync.c,v 1.27 2010/02/26 02: 01:39 momjian Exp $
2+ * $PostgreSQL: pgsql/src/tools/fsync/test_fsync.c,v 1.28 2010/07/04 01:50:29 momjian Exp $
33 *
44 *
55 *test_fsync.c
3434
3535#define LABEL_FORMAT "\t%-30s"
3636
37+ int loops = 10000 ;
38+
3739void die (char * str );
3840void print_elapse (struct timeval start_t ,struct timeval stop_t );
3941
@@ -43,8 +45,7 @@ main(int argc, char *argv[])
4345struct timeval start_t ;
4446struct timeval stop_t ;
4547int tmpfile ,
46- i ,
47- loops = 5000 ;
48+ i ;
4849char * full_buf = (char * )malloc (XLOG_SEG_SIZE ),
4950* buf ;
5051char * filename = FSYNC_FILENAME ;
@@ -73,10 +74,12 @@ main(int argc, char *argv[])
7374
7475buf = (char * )TYPEALIGN (ALIGNOF_XLOG_BUFFER ,full_buf );
7576
77+ printf ("Loops = %d\n\n" ,loops );
78+
7679/*
7780 * Simple write
7881 */
79- printf ("Simple8k write timing:\n" );
82+ printf ("Simple write timing:\n" );
8083/* write only */
8184gettimeofday (& start_t ,NULL );
8285for (i = 0 ;i < loops ;i ++ )
@@ -88,13 +91,13 @@ main(int argc, char *argv[])
8891close (tmpfile );
8992}
9093gettimeofday (& stop_t ,NULL );
91- printf (LABEL_FORMAT ,"write" );
94+ printf (LABEL_FORMAT ,"8k write" );
9295print_elapse (start_t ,stop_t );
9396
9497/*
9598 * Compare file sync methods with one 8k write
9699 */
97- printf ("\nCompare file sync methods using one8k write:\n" );
100+ printf ("\nCompare file sync methods using one write:\n" );
98101
99102#ifdef OPEN_DATASYNC_FLAG
100103/* open_dsync, write */
@@ -110,7 +113,7 @@ main(int argc, char *argv[])
110113}
111114gettimeofday (& stop_t ,NULL );
112115close (tmpfile );
113- printf (LABEL_FORMAT ,"open_datasync write" );
116+ printf (LABEL_FORMAT ,"open_datasync8k write" );
114117print_elapse (start_t ,stop_t );
115118#else
116119printf ("\t(open_datasync unavailable)\n" );
@@ -130,7 +133,7 @@ main(int argc, char *argv[])
130133}
131134gettimeofday (& stop_t ,NULL );
132135close (tmpfile );
133- printf (LABEL_FORMAT ,"open_sync write" );
136+ printf (LABEL_FORMAT ,"open_sync8k write" );
134137print_elapse (start_t ,stop_t );
135138#else
136139printf ("\t(open_sync unavailable)\n" );
@@ -151,7 +154,7 @@ main(int argc, char *argv[])
151154}
152155gettimeofday (& stop_t ,NULL );
153156close (tmpfile );
154- printf (LABEL_FORMAT ,"write, fdatasync" );
157+ printf (LABEL_FORMAT ,"8k write, fdatasync" );
155158print_elapse (start_t ,stop_t );
156159#else
157160printf ("\t(fdatasync unavailable)\n" );
@@ -172,13 +175,13 @@ main(int argc, char *argv[])
172175}
173176gettimeofday (& stop_t ,NULL );
174177close (tmpfile );
175- printf (LABEL_FORMAT ,"write, fsync" );
178+ printf (LABEL_FORMAT ,"8k write, fsync" );
176179print_elapse (start_t ,stop_t );
177180
178181/*
179182 * Compare file sync methods with two 8k write
180183 */
181- printf ("\nCompare file sync methods using two8k writes:\n" );
184+ printf ("\nCompare file sync methods using two writes:\n" );
182185
183186#ifdef OPEN_DATASYNC_FLAG
184187/* open_dsync, write */
@@ -196,7 +199,7 @@ main(int argc, char *argv[])
196199}
197200gettimeofday (& stop_t ,NULL );
198201close (tmpfile );
199- printf (LABEL_FORMAT ,"open_datasyncwrite, write " );
202+ printf (LABEL_FORMAT ,"2 open_datasync8k writes " );
200203print_elapse (start_t ,stop_t );
201204#else
202205printf ("\t(open_datasync unavailable)\n" );
@@ -218,7 +221,7 @@ main(int argc, char *argv[])
218221}
219222gettimeofday (& stop_t ,NULL );
220223close (tmpfile );
221- printf (LABEL_FORMAT ,"open_syncwrite, write " );
224+ printf (LABEL_FORMAT ,"2 open_sync8k writes " );
222225print_elapse (start_t ,stop_t );
223226#endif
224227
@@ -239,7 +242,7 @@ main(int argc, char *argv[])
239242}
240243gettimeofday (& stop_t ,NULL );
241244close (tmpfile );
242- printf (LABEL_FORMAT ,"write, write, fdatasync" );
245+ printf (LABEL_FORMAT ,"8k write, 8k write, fdatasync" );
243246print_elapse (start_t ,stop_t );
244247#else
245248printf ("\t(fdatasync unavailable)\n" );
@@ -262,7 +265,7 @@ main(int argc, char *argv[])
262265}
263266gettimeofday (& stop_t ,NULL );
264267close (tmpfile );
265- printf (LABEL_FORMAT ,"write, write, fsync" );
268+ printf (LABEL_FORMAT ,"8k write, 8k write, fsync" );
266269print_elapse (start_t ,stop_t );
267270
268271/*
@@ -284,7 +287,7 @@ main(int argc, char *argv[])
284287}
285288gettimeofday (& stop_t ,NULL );
286289close (tmpfile );
287- printf (LABEL_FORMAT ,"16k open_sync write" );
290+ printf (LABEL_FORMAT ,"open_sync 16k write" );
288291print_elapse (start_t ,stop_t );
289292
290293/* Two 8k open_sync writes */
@@ -302,7 +305,7 @@ main(int argc, char *argv[])
302305}
303306gettimeofday (& stop_t ,NULL );
304307close (tmpfile );
305- printf (LABEL_FORMAT ,"28k open_sync writes" );
308+ printf (LABEL_FORMAT ,"2 open_sync 8k writes" );
306309print_elapse (start_t ,stop_t );
307310#else
308311printf ("\t(open_sync unavailable)\n" );
@@ -311,8 +314,9 @@ main(int argc, char *argv[])
311314/*
312315 * Fsync another file descriptor?
313316 */
314- printf ("\nCompare fsync times on write() and new file descriptors (if the times\n" );
315- printf ("are similar, fsync() can sync data written on a different descriptor):\n" );
317+ printf ("\nTest if fsync on non-write file descriptor is honored:\n" );
318+ printf ("(If the times are similar, fsync() can sync data written\n" );
319+ printf ("on a different descriptor.)\n" );
316320
317321/* write, fsync, close */
318322gettimeofday (& start_t ,NULL );
@@ -331,7 +335,7 @@ main(int argc, char *argv[])
331335close (tmpfile );
332336}
333337gettimeofday (& stop_t ,NULL );
334- printf (LABEL_FORMAT ,"write, fsync, close" );
338+ printf (LABEL_FORMAT ,"8k write, fsync, close" );
335339print_elapse (start_t ,stop_t );
336340
337341/* write, close, fsync */
@@ -351,7 +355,7 @@ main(int argc, char *argv[])
351355close (tmpfile );
352356}
353357gettimeofday (& stop_t ,NULL );
354- printf (LABEL_FORMAT ,"write, close, fsync" );
358+ printf (LABEL_FORMAT ,"8k write, close, fsync" );
355359print_elapse (start_t ,stop_t );
356360
357361/* cleanup */
@@ -364,14 +368,19 @@ main(int argc, char *argv[])
364368void
365369print_elapse (struct timeval start_t ,struct timeval stop_t )
366370{
371+ double total_time ,per_second ;
372+
367373if (stop_t .tv_usec < start_t .tv_usec )
368374{
369375stop_t .tv_sec -- ;
370376stop_t .tv_usec += 1000000 ;
371377}
372378
373- printf ("%3ld.%06ld\n" , (long ) (stop_t .tv_sec - start_t .tv_sec ),
374- (long ) (stop_t .tv_usec - start_t .tv_usec ));
379+ total_time = (stop_t .tv_sec - start_t .tv_sec )+
380+ (stop_t .tv_usec - start_t .tv_usec )* 0.000001 ;
381+ per_second = loops /total_time ;
382+
383+ printf ("%9.3f/second\n" ,per_second );
375384}
376385
377386void