2004-03-18 11:56:59 +08:00
|
|
|
/*
|
|
|
|
* test_fsync.c
|
2006-11-25 09:22:28 +08:00
|
|
|
* test various fsync() methods
|
2004-03-18 11:56:59 +08:00
|
|
|
*/
|
|
|
|
|
2006-11-25 09:22:28 +08:00
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "access/xlog_internal.h"
|
|
|
|
#include "access/xlog.h"
|
2007-02-14 13:00:40 +08:00
|
|
|
#include "access/xlogdefs.h"
|
2004-03-18 11:56:59 +08:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
2004-03-18 23:26:27 +08:00
|
|
|
#include <sys/stat.h>
|
2004-03-18 11:56:59 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
2004-03-18 12:04:36 +08:00
|
|
|
#include <sys/time.h>
|
2004-03-18 11:56:59 +08:00
|
|
|
#include <unistd.h>
|
2006-11-25 09:22:28 +08:00
|
|
|
#include <string.h>
|
2004-03-18 11:56:59 +08:00
|
|
|
|
2006-11-25 09:22:28 +08:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#define FSYNC_FILENAME "./test_fsync.out"
|
|
|
|
#else
|
|
|
|
/* /tmp might be a memory file system */
|
|
|
|
#define FSYNC_FILENAME "/var/tmp/test_fsync.out"
|
2004-03-18 11:56:59 +08:00
|
|
|
#endif
|
|
|
|
|
2006-11-25 09:22:28 +08:00
|
|
|
#define WRITE_SIZE (16 * 1024)
|
2004-03-19 04:09:33 +08:00
|
|
|
|
2004-03-18 23:26:27 +08:00
|
|
|
void die(char *str);
|
|
|
|
void print_elapse(struct timeval start_t, struct timeval elapse_t);
|
2004-03-18 11:56:59 +08:00
|
|
|
|
2004-03-18 23:26:27 +08:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
2004-03-18 11:56:59 +08:00
|
|
|
{
|
|
|
|
struct timeval start_t;
|
|
|
|
struct timeval elapse_t;
|
2004-03-18 23:26:27 +08:00
|
|
|
int tmpfile,
|
2004-03-19 03:54:00 +08:00
|
|
|
i,
|
2004-08-29 13:07:03 +08:00
|
|
|
loops = 1000;
|
2006-11-25 09:22:28 +08:00
|
|
|
char *full_buf = (char *) malloc(XLOG_SEG_SIZE), *buf;
|
2004-03-19 03:54:00 +08:00
|
|
|
char *filename = FSYNC_FILENAME;
|
2004-03-18 23:26:27 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
if (argc > 2 && strcmp(argv[1], "-f") == 0)
|
2004-03-19 03:54:00 +08:00
|
|
|
{
|
|
|
|
filename = argv[2];
|
|
|
|
argv += 2;
|
|
|
|
argc -= 2;
|
|
|
|
}
|
2004-08-29 13:07:03 +08:00
|
|
|
|
2004-03-19 03:54:00 +08:00
|
|
|
if (argc > 1)
|
2004-08-29 13:07:03 +08:00
|
|
|
loops = atoi(argv[1]);
|
|
|
|
|
2006-11-25 09:22:28 +08:00
|
|
|
for (i = 0; i < XLOG_SEG_SIZE; i++)
|
|
|
|
full_buf[i] = 'a';
|
2004-03-19 03:54:00 +08:00
|
|
|
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, full_buf, XLOG_SEG_SIZE) != XLOG_SEG_SIZE)
|
|
|
|
die("write failed");
|
|
|
|
/* fsync so later fsync's don't have to do it */
|
|
|
|
if (fsync(tmpfile) != 0)
|
|
|
|
die("fsync failed");
|
2004-03-18 23:26:27 +08:00
|
|
|
close(tmpfile);
|
2004-03-18 11:56:59 +08:00
|
|
|
|
2006-11-25 09:22:28 +08:00
|
|
|
buf = (char *)TYPEALIGN(ALIGNOF_XLOG_BUFFER, full_buf);
|
|
|
|
|
2004-03-18 11:56:59 +08:00
|
|
|
printf("Simple write timing:\n");
|
2004-03-18 23:26:27 +08:00
|
|
|
/* write only */
|
2004-03-18 11:56:59 +08:00
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
|
|
|
{
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
2004-03-19 03:54:00 +08:00
|
|
|
close(tmpfile);
|
|
|
|
}
|
2004-03-18 11:56:59 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
2004-03-18 23:26:27 +08:00
|
|
|
printf("\twrite ");
|
2004-03-18 11:56:59 +08:00
|
|
|
print_elapse(start_t, elapse_t);
|
2004-03-19 03:54:00 +08:00
|
|
|
printf("\n");
|
2004-03-18 11:56:59 +08:00
|
|
|
|
2004-03-19 03:54:00 +08:00
|
|
|
printf("\nCompare fsync times on write() and non-write() descriptor:\n");
|
|
|
|
printf("(If the times are similar, fsync() can sync data written\n on a different descriptor.)\n");
|
2004-03-18 23:26:27 +08:00
|
|
|
|
2004-03-18 11:56:59 +08:00
|
|
|
/* write, fsync, close */
|
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
|
|
|
{
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
|
|
|
if (fsync(tmpfile) != 0)
|
|
|
|
die("fsync failed");
|
2004-03-19 03:54:00 +08:00
|
|
|
close(tmpfile);
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2004-03-19 03:54:00 +08:00
|
|
|
/* do nothing but the open/close the tests are consistent. */
|
|
|
|
close(tmpfile);
|
|
|
|
}
|
2004-03-18 11:56:59 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
2004-03-18 23:26:27 +08:00
|
|
|
printf("\twrite, fsync, close ");
|
2004-03-18 11:56:59 +08:00
|
|
|
print_elapse(start_t, elapse_t);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* write, close, fsync */
|
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
|
|
|
{
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
2004-03-19 03:54:00 +08:00
|
|
|
close(tmpfile);
|
|
|
|
/* reopen file */
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2006-11-25 09:22:28 +08:00
|
|
|
if (fsync(tmpfile) != 0)
|
|
|
|
die("fsync failed");
|
2004-03-19 03:54:00 +08:00
|
|
|
close(tmpfile);
|
|
|
|
}
|
2004-03-18 11:56:59 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
2004-03-18 23:26:27 +08:00
|
|
|
printf("\twrite, close, fsync ");
|
2004-03-18 11:56:59 +08:00
|
|
|
print_elapse(start_t, elapse_t);
|
|
|
|
printf("\n");
|
|
|
|
|
2004-03-18 23:26:27 +08:00
|
|
|
printf("\nCompare one o_sync write to two:\n");
|
|
|
|
|
2006-10-13 22:19:29 +08:00
|
|
|
#ifdef OPEN_SYNC_FLAG
|
2004-03-18 23:26:27 +08:00
|
|
|
/* 16k o_sync write */
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
|
|
|
|
die("write failed");
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
|
|
|
close(tmpfile);
|
|
|
|
printf("\tone 16k o_sync write ");
|
|
|
|
print_elapse(start_t, elapse_t);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* 2*8k o_sync writes */
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
|
|
|
{
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
2004-03-19 03:54:00 +08:00
|
|
|
}
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
|
|
|
close(tmpfile);
|
|
|
|
printf("\ttwo 8k o_sync writes ");
|
|
|
|
print_elapse(start_t, elapse_t);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("\nCompare file sync methods with one 8k write:\n");
|
2006-10-13 22:19:29 +08:00
|
|
|
#else
|
|
|
|
printf("\t(o_sync unavailable) ");
|
|
|
|
#endif
|
|
|
|
printf("\n");
|
2004-03-18 11:56:59 +08:00
|
|
|
|
|
|
|
#ifdef OPEN_DATASYNC_FLAG
|
|
|
|
/* open_dsync, write */
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR | O_DSYNC)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2004-03-18 11:56:59 +08:00
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
|
|
|
close(tmpfile);
|
|
|
|
printf("\topen o_dsync, write ");
|
|
|
|
print_elapse(start_t, elapse_t);
|
|
|
|
printf("\n");
|
2006-10-13 22:19:29 +08:00
|
|
|
#ifdef OPEN_SYNC_FLAG
|
2004-03-18 23:26:27 +08:00
|
|
|
/* open_fsync, write */
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
2004-03-18 11:56:59 +08:00
|
|
|
close(tmpfile);
|
2004-03-18 23:26:27 +08:00
|
|
|
printf("\topen o_sync, write ");
|
|
|
|
print_elapse(start_t, elapse_t);
|
2006-10-13 22:19:29 +08:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
printf("\t(o_dsync unavailable) ");
|
|
|
|
#endif
|
2004-03-18 23:26:27 +08:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
#ifdef HAVE_FDATASYNC
|
|
|
|
/* write, fdatasync */
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
|
|
|
{
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
2004-03-19 03:54:00 +08:00
|
|
|
fdatasync(tmpfile);
|
|
|
|
}
|
2004-03-18 11:56:59 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
2004-03-18 23:26:27 +08:00
|
|
|
close(tmpfile);
|
|
|
|
printf("\twrite, fdatasync ");
|
2004-03-18 11:56:59 +08:00
|
|
|
print_elapse(start_t, elapse_t);
|
2004-03-18 22:02:58 +08:00
|
|
|
#else
|
2004-03-18 23:26:27 +08:00
|
|
|
printf("\t(fdatasync unavailable)");
|
2004-03-18 11:56:59 +08:00
|
|
|
#endif
|
2004-03-18 22:02:58 +08:00
|
|
|
printf("\n");
|
2004-03-18 11:56:59 +08:00
|
|
|
|
2004-03-18 23:26:27 +08:00
|
|
|
/* write, fsync, close */
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2004-03-18 11:56:59 +08:00
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
|
|
|
{
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
|
|
|
if (fsync(tmpfile) != 0)
|
|
|
|
die("fsync failed");
|
2004-03-19 03:54:00 +08:00
|
|
|
}
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
|
|
|
close(tmpfile);
|
|
|
|
printf("\twrite, fsync, ");
|
|
|
|
print_elapse(start_t, elapse_t);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("\nCompare file sync methods with 2 8k writes:\n");
|
|
|
|
|
|
|
|
#ifdef OPEN_DATASYNC_FLAG
|
|
|
|
/* open_dsync, write */
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR | O_DSYNC)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
|
|
|
{
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
2004-03-19 03:54:00 +08:00
|
|
|
}
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
2004-03-18 11:56:59 +08:00
|
|
|
close(tmpfile);
|
2004-03-18 23:26:27 +08:00
|
|
|
printf("\topen o_dsync, write ");
|
|
|
|
print_elapse(start_t, elapse_t);
|
|
|
|
#else
|
|
|
|
printf("\t(o_dsync unavailable) ");
|
|
|
|
#endif
|
|
|
|
printf("\n");
|
|
|
|
|
2006-10-13 22:19:29 +08:00
|
|
|
#ifdef OPEN_SYNC_FLAG
|
2004-03-18 23:26:27 +08:00
|
|
|
/* open_fsync, write */
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
|
|
|
{
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
2004-03-19 03:54:00 +08:00
|
|
|
}
|
2004-03-18 11:56:59 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
2004-03-18 23:26:27 +08:00
|
|
|
close(tmpfile);
|
|
|
|
printf("\topen o_sync, write ");
|
2004-03-18 11:56:59 +08:00
|
|
|
print_elapse(start_t, elapse_t);
|
|
|
|
printf("\n");
|
2006-10-13 22:19:29 +08:00
|
|
|
#endif
|
2004-03-18 11:56:59 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_FDATASYNC
|
|
|
|
/* write, fdatasync */
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
|
|
|
{
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
2004-03-19 03:54:00 +08:00
|
|
|
fdatasync(tmpfile);
|
|
|
|
}
|
2004-03-18 11:56:59 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
2004-03-18 23:26:27 +08:00
|
|
|
close(tmpfile);
|
|
|
|
printf("\twrite, fdatasync ");
|
2004-03-18 11:56:59 +08:00
|
|
|
print_elapse(start_t, elapse_t);
|
2004-03-18 22:02:58 +08:00
|
|
|
#else
|
2004-03-18 23:26:27 +08:00
|
|
|
printf("\t(fdatasync unavailable)");
|
2004-03-18 11:56:59 +08:00
|
|
|
#endif
|
2004-03-18 22:02:58 +08:00
|
|
|
printf("\n");
|
2004-03-18 11:56:59 +08:00
|
|
|
|
|
|
|
/* write, fsync, close */
|
2005-11-16 09:31:07 +08:00
|
|
|
if ((tmpfile = open(filename, O_RDWR)) == -1)
|
2005-11-16 11:32:04 +08:00
|
|
|
die("Cannot open output file.");
|
2004-03-18 23:26:27 +08:00
|
|
|
gettimeofday(&start_t, NULL);
|
2004-03-19 03:54:00 +08:00
|
|
|
for (i = 0; i < loops; i++)
|
|
|
|
{
|
2006-11-25 09:22:28 +08:00
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
|
|
|
if (write(tmpfile, buf, WRITE_SIZE/2) != WRITE_SIZE/2)
|
|
|
|
die("write failed");
|
|
|
|
if (fsync(tmpfile) != 0)
|
|
|
|
die("fsync failed");
|
2004-03-19 03:54:00 +08:00
|
|
|
}
|
2004-03-18 11:56:59 +08:00
|
|
|
gettimeofday(&elapse_t, NULL);
|
2004-03-18 23:26:27 +08:00
|
|
|
close(tmpfile);
|
|
|
|
printf("\twrite, fsync, ");
|
2004-03-18 11:56:59 +08:00
|
|
|
print_elapse(start_t, elapse_t);
|
|
|
|
printf("\n");
|
|
|
|
|
2006-11-25 09:22:28 +08:00
|
|
|
free(full_buf);
|
2005-11-16 09:31:07 +08:00
|
|
|
unlink(filename);
|
2004-03-18 23:26:27 +08:00
|
|
|
|
2004-03-18 11:56:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-03-18 23:26:27 +08:00
|
|
|
void
|
|
|
|
print_elapse(struct timeval start_t, struct timeval elapse_t)
|
2004-03-18 11:56:59 +08:00
|
|
|
{
|
|
|
|
if (elapse_t.tv_usec < start_t.tv_usec)
|
|
|
|
{
|
|
|
|
elapse_t.tv_sec--;
|
|
|
|
elapse_t.tv_usec += 1000000;
|
|
|
|
}
|
|
|
|
|
2004-03-19 03:54:00 +08:00
|
|
|
printf("%3ld.%06ld", (long) (elapse_t.tv_sec - start_t.tv_sec),
|
2004-03-18 23:26:27 +08:00
|
|
|
(long) (elapse_t.tv_usec - start_t.tv_usec));
|
2004-03-18 11:56:59 +08:00
|
|
|
}
|
|
|
|
|
2004-03-18 23:26:27 +08:00
|
|
|
void
|
|
|
|
die(char *str)
|
2004-03-18 11:56:59 +08:00
|
|
|
{
|
2005-11-16 11:32:04 +08:00
|
|
|
fprintf(stderr, "%s\n", str);
|
2004-03-18 11:56:59 +08:00
|
|
|
exit(1);
|
|
|
|
}
|