The attached, applied patch adds getopt() support to test_fsync.

-- 
  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +
diff --git a/src/tools/fsync/README b/src/tools/fsync/README
index 5bf6f1f..fee9c62 100644
*** /tmp/pgdiff.11631/0CF5hb_README	Mon Jan 17 09:34:35 2011
--- src/tools/fsync/README	Mon Jan 17 09:28:15 2011
*************** test_fsync
*** 3,9 ****
  
  This program tests fsync.  The tests are described as part of the program output.
  
! 	Usage:	test_fsync [-f filename] [ops_per_test]
  	
  test_fsync is intended to give you a reasonable idea of what the fastest
  fsync_method is on your specific system, as well as supplying diagnostic
--- 3,13 ----
  
  This program tests fsync.  The tests are described as part of the program output.
  
! 	Usage: test_fsync [option...]
! 
! Options:
! 	-f, --filename		specify filename for test
! 	-o, --ops-per-test	operations per test
  	
  test_fsync is intended to give you a reasonable idea of what the fastest
  fsync_method is on your specific system, as well as supplying diagnostic
*************** The output filename defaults to test_fsy
*** 16,21 ****
  test_fsync should be run in the same filesystem as your transaction log
  directory (pg_xlog).
  
! Ops-per-test defaults to 2000.  Increase this to get more accurate
  measurements.
  
--- 20,25 ----
  test_fsync should be run in the same filesystem as your transaction log
  directory (pg_xlog).
  
! Operations per test defaults to 2000.  Increase this to get more accurate
  measurements.
  
diff --git a/src/tools/fsync/test_fsync.c b/src/tools/fsync/test_fsync.c
index c0c58f6..b1cec74 100644
*** /tmp/pgdiff.11631/YRJFLe_test_fsync.c	Mon Jan 17 09:34:35 2011
--- src/tools/fsync/test_fsync.c	Mon Jan 17 09:27:44 2011
***************
*** 8,13 ****
--- 8,14 ----
  
  #include "postgres.h"
  
+ #include "getopt_long.h"
  #include "access/xlog_internal.h"
  #include "access/xlog.h"
  #include "access/xlogdefs.h"
*************** main(int argc, char *argv[])
*** 80,105 ****
  void
  handle_args(int argc, char *argv[])
  {
! 	if (argc > 1 && strcmp(argv[1], "-h") == 0)
  	{
! 		fprintf(stderr, "test_fsync [-f filename] [ops-per-test]\n");
! 		exit(1);
  	}
! 	
! 	/* 
! 	 * arguments: ops_per_test and filename (optional) 
! 	 */
! 	if (argc > 2 && strcmp(argv[1], "-f") == 0)
  	{
! 		filename = argv[2];
! 		argv += 2;
! 		argc -= 2;
! 	}
  
! 	if (argc > 1) 
! 		ops_per_test = atoi(argv[1]);
  
! 	printf("Ops-per-test = %d\n\n", ops_per_test);
  }
  
  void
--- 81,132 ----
  void
  handle_args(int argc, char *argv[])
  {
! 	static struct option long_options[] = {
! 		{"filename", required_argument, NULL, 'f'},
! 		{"ops-per-test", required_argument, NULL, 'o'},
! 		{NULL, 0, NULL, 0}
! 	};
! 	int			option;			/* Command line option */
! 	int			optindex = 0;	/* used by getopt_long */
! 
! 	if (argc > 1)
  	{
! 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ||
! 			strcmp(argv[1], "-?") == 0)
! 		{
! 			fprintf(stderr, "test_fsync [-f filename] [ops-per-test]\n");
! 			exit(0);
! 		}
! 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
! 		{
! 			fprintf(stderr,"test_fsync " PG_VERSION "\n");
! 			exit(0);
! 		}
  	}
! 
! 	while ((option = getopt_long(argc, argv, "f:o:",
! 								 long_options, &optindex)) != -1)
  	{
! 		switch (option)
! 		{
! 			case 'f':
! 				filename = strdup(optarg);
! 				break;
  
! 			case 'o':
! 				ops_per_test = atoi(optarg);
! 				break;
! 				
! 			default:
! 				fprintf(stderr,
! 					   "Try \"%s --help\" for more information.\n",
! 					   "test_fsync");
! 				exit(1);
! 				break;
! 		}
! 	}
  
! 	printf("%d operations per test\n\n", ops_per_test);
  }
  
  void
*************** test_open_syncs(void)
*** 448,454 ****
  	}
  	
  	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
! 		printf(NA_FORMAT, "n/a**\n");
  	else
  	{
  		printf(LABEL_FORMAT, "2 open_sync 8k writes");
--- 475,481 ----
  	}
  	
  	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
! 		printf(NA_FORMAT, "o_direct", "n/a**\n");
  	else
  	{
  		printf(LABEL_FORMAT, "2 open_sync 8k writes");
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to