1
1
/*
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 $
3
3
*
4
4
*
5
5
* test_fsync.c
34
34
35
35
#define LABEL_FORMAT "\t%-30s"
36
36
37
+ int loops = 10000 ;
38
+
37
39
void die (char * str );
38
40
void print_elapse (struct timeval start_t , struct timeval stop_t );
39
41
@@ -43,8 +45,7 @@ main(int argc, char *argv[])
43
45
struct timeval start_t ;
44
46
struct timeval stop_t ;
45
47
int tmpfile ,
46
- i ,
47
- loops = 5000 ;
48
+ i ;
48
49
char * full_buf = (char * ) malloc (XLOG_SEG_SIZE ),
49
50
* buf ;
50
51
char * filename = FSYNC_FILENAME ;
@@ -73,10 +74,12 @@ main(int argc, char *argv[])
73
74
74
75
buf = (char * ) TYPEALIGN (ALIGNOF_XLOG_BUFFER , full_buf );
75
76
77
+ printf ("Loops = %d\n\n" , loops );
78
+
76
79
/*
77
80
* Simple write
78
81
*/
79
- printf ("Simple 8k write timing:\n" );
82
+ printf ("Simple write timing:\n" );
80
83
/* write only */
81
84
gettimeofday (& start_t , NULL );
82
85
for (i = 0 ; i < loops ; i ++ )
@@ -88,13 +91,13 @@ main(int argc, char *argv[])
88
91
close (tmpfile );
89
92
}
90
93
gettimeofday (& stop_t , NULL );
91
- printf (LABEL_FORMAT , "write" );
94
+ printf (LABEL_FORMAT , "8k write" );
92
95
print_elapse (start_t , stop_t );
93
96
94
97
/*
95
98
* Compare file sync methods with one 8k write
96
99
*/
97
- printf ("\nCompare file sync methods using one 8k write:\n" );
100
+ printf ("\nCompare file sync methods using one write:\n" );
98
101
99
102
#ifdef OPEN_DATASYNC_FLAG
100
103
/* open_dsync, write */
@@ -110,7 +113,7 @@ main(int argc, char *argv[])
110
113
}
111
114
gettimeofday (& stop_t , NULL );
112
115
close (tmpfile );
113
- printf (LABEL_FORMAT , "open_datasync write" );
116
+ printf (LABEL_FORMAT , "open_datasync 8k write" );
114
117
print_elapse (start_t , stop_t );
115
118
#else
116
119
printf ("\t(open_datasync unavailable)\n" );
@@ -130,7 +133,7 @@ main(int argc, char *argv[])
130
133
}
131
134
gettimeofday (& stop_t , NULL );
132
135
close (tmpfile );
133
- printf (LABEL_FORMAT , "open_sync write" );
136
+ printf (LABEL_FORMAT , "open_sync 8k write" );
134
137
print_elapse (start_t , stop_t );
135
138
#else
136
139
printf ("\t(open_sync unavailable)\n" );
@@ -151,7 +154,7 @@ main(int argc, char *argv[])
151
154
}
152
155
gettimeofday (& stop_t , NULL );
153
156
close (tmpfile );
154
- printf (LABEL_FORMAT , "write, fdatasync" );
157
+ printf (LABEL_FORMAT , "8k write, fdatasync" );
155
158
print_elapse (start_t , stop_t );
156
159
#else
157
160
printf ("\t(fdatasync unavailable)\n" );
@@ -172,13 +175,13 @@ main(int argc, char *argv[])
172
175
}
173
176
gettimeofday (& stop_t , NULL );
174
177
close (tmpfile );
175
- printf (LABEL_FORMAT , "write, fsync" );
178
+ printf (LABEL_FORMAT , "8k write, fsync" );
176
179
print_elapse (start_t , stop_t );
177
180
178
181
/*
179
182
* Compare file sync methods with two 8k write
180
183
*/
181
- printf ("\nCompare file sync methods using two 8k writes:\n" );
184
+ printf ("\nCompare file sync methods using two writes:\n" );
182
185
183
186
#ifdef OPEN_DATASYNC_FLAG
184
187
/* open_dsync, write */
@@ -196,7 +199,7 @@ main(int argc, char *argv[])
196
199
}
197
200
gettimeofday (& stop_t , NULL );
198
201
close (tmpfile );
199
- printf (LABEL_FORMAT , "open_datasync write, write " );
202
+ printf (LABEL_FORMAT , "2 open_datasync 8k writes " );
200
203
print_elapse (start_t , stop_t );
201
204
#else
202
205
printf ("\t(open_datasync unavailable)\n" );
@@ -218,7 +221,7 @@ main(int argc, char *argv[])
218
221
}
219
222
gettimeofday (& stop_t , NULL );
220
223
close (tmpfile );
221
- printf (LABEL_FORMAT , "open_sync write, write " );
224
+ printf (LABEL_FORMAT , "2 open_sync 8k writes " );
222
225
print_elapse (start_t , stop_t );
223
226
#endif
224
227
@@ -239,7 +242,7 @@ main(int argc, char *argv[])
239
242
}
240
243
gettimeofday (& stop_t , NULL );
241
244
close (tmpfile );
242
- printf (LABEL_FORMAT , "write, write, fdatasync" );
245
+ printf (LABEL_FORMAT , "8k write, 8k write, fdatasync" );
243
246
print_elapse (start_t , stop_t );
244
247
#else
245
248
printf ("\t(fdatasync unavailable)\n" );
@@ -262,7 +265,7 @@ main(int argc, char *argv[])
262
265
}
263
266
gettimeofday (& stop_t , NULL );
264
267
close (tmpfile );
265
- printf (LABEL_FORMAT , "write, write, fsync" );
268
+ printf (LABEL_FORMAT , "8k write, 8k write, fsync" );
266
269
print_elapse (start_t , stop_t );
267
270
268
271
/*
@@ -284,7 +287,7 @@ main(int argc, char *argv[])
284
287
}
285
288
gettimeofday (& stop_t , NULL );
286
289
close (tmpfile );
287
- printf (LABEL_FORMAT , "16k open_sync write" );
290
+ printf (LABEL_FORMAT , "open_sync 16k write" );
288
291
print_elapse (start_t , stop_t );
289
292
290
293
/* Two 8k open_sync writes */
@@ -302,7 +305,7 @@ main(int argc, char *argv[])
302
305
}
303
306
gettimeofday (& stop_t , NULL );
304
307
close (tmpfile );
305
- printf (LABEL_FORMAT , "2 8k open_sync writes" );
308
+ printf (LABEL_FORMAT , "2 open_sync 8k writes" );
306
309
print_elapse (start_t , stop_t );
307
310
#else
308
311
printf ("\t(open_sync unavailable)\n" );
@@ -311,8 +314,9 @@ main(int argc, char *argv[])
311
314
/*
312
315
* Fsync another file descriptor?
313
316
*/
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" );
316
320
317
321
/* write, fsync, close */
318
322
gettimeofday (& start_t , NULL );
@@ -331,7 +335,7 @@ main(int argc, char *argv[])
331
335
close (tmpfile );
332
336
}
333
337
gettimeofday (& stop_t , NULL );
334
- printf (LABEL_FORMAT , "write, fsync, close" );
338
+ printf (LABEL_FORMAT , "8k write, fsync, close" );
335
339
print_elapse (start_t , stop_t );
336
340
337
341
/* write, close, fsync */
@@ -351,7 +355,7 @@ main(int argc, char *argv[])
351
355
close (tmpfile );
352
356
}
353
357
gettimeofday (& stop_t , NULL );
354
- printf (LABEL_FORMAT , "write, close, fsync" );
358
+ printf (LABEL_FORMAT , "8k write, close, fsync" );
355
359
print_elapse (start_t , stop_t );
356
360
357
361
/* cleanup */
@@ -364,14 +368,19 @@ main(int argc, char *argv[])
364
368
void
365
369
print_elapse (struct timeval start_t , struct timeval stop_t )
366
370
{
371
+ double total_time , per_second ;
372
+
367
373
if (stop_t .tv_usec < start_t .tv_usec )
368
374
{
369
375
stop_t .tv_sec -- ;
370
376
stop_t .tv_usec += 1000000 ;
371
377
}
372
378
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 );
375
384
}
376
385
377
386
void
0 commit comments