Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08af45f

Browse files
committed
Add getopt() support to test_fsync; also fix printf() format problem.
1 parent4807509 commit08af45f

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

‎src/tools/fsync/README

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ test_fsync
33

44
This program tests fsync. The tests are described as part of the program output.
55

6-
Usage:test_fsync [-f filename] [ops_per_test]
6+
Usage: test_fsync [option...]
7+
8+
Options:
9+
-f, --filenamespecify filename for test
10+
-o, --ops-per-testoperations per test
711

812
test_fsync is intended to give you a reasonable idea of what the fastest
913
fsync_method is on your specific system, as well as supplying diagnostic
@@ -16,6 +20,6 @@ The output filename defaults to test_fsync.out in the current directory.
1620
test_fsync should be run in the same filesystem as your transaction log
1721
directory (pg_xlog).
1822

19-
Ops-per-test defaults to 2000. Increase this to get more accurate
23+
Operationspertest defaults to 2000. Increase this to get more accurate
2024
measurements.
2125

‎src/tools/fsync/test_fsync.c

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include"postgres.h"
1010

11+
#include"getopt_long.h"
1112
#include"access/xlog_internal.h"
1213
#include"access/xlog.h"
1314
#include"access/xlogdefs.h"
@@ -80,26 +81,52 @@ main(int argc, char *argv[])
8081
void
8182
handle_args(intargc,char*argv[])
8283
{
83-
if (argc>1&&strcmp(argv[1],"-h")==0)
84+
staticstructoptionlong_options[]= {
85+
{"filename",required_argument,NULL,'f'},
86+
{"ops-per-test",required_argument,NULL,'o'},
87+
{NULL,0,NULL,0}
88+
};
89+
intoption;/* Command line option */
90+
intoptindex=0;/* used by getopt_long */
91+
92+
if (argc>1)
8493
{
85-
fprintf(stderr,"test_fsync [-f filename] [ops-per-test]\n");
86-
exit(1);
94+
if (strcmp(argv[1],"--help")==0||strcmp(argv[1],"-h")==0||
95+
strcmp(argv[1],"-?")==0)
96+
{
97+
fprintf(stderr,"test_fsync [-f filename] [ops-per-test]\n");
98+
exit(0);
99+
}
100+
if (strcmp(argv[1],"--version")==0||strcmp(argv[1],"-V")==0)
101+
{
102+
fprintf(stderr,"test_fsync "PG_VERSION"\n");
103+
exit(0);
104+
}
87105
}
88-
89-
/*
90-
* arguments: ops_per_test and filename (optional)
91-
*/
92-
if (argc>2&&strcmp(argv[1],"-f")==0)
106+
107+
while ((option=getopt_long(argc,argv,"f:o:",
108+
long_options,&optindex))!=-1)
93109
{
94-
filename=argv[2];
95-
argv+=2;
96-
argc-=2;
110+
switch (option)
111+
{
112+
case'f':
113+
filename=strdup(optarg);
114+
break;
115+
116+
case'o':
117+
ops_per_test=atoi(optarg);
118+
break;
119+
120+
default:
121+
fprintf(stderr,
122+
"Try \"%s --help\" for more information.\n",
123+
"test_fsync");
124+
exit(1);
125+
break;
126+
}
97127
}
98128

99-
if (argc>1)
100-
ops_per_test=atoi(argv[1]);
101-
102-
printf("Ops-per-test = %d\n\n",ops_per_test);
129+
printf("%d operations per test\n\n",ops_per_test);
103130
}
104131

105132
void
@@ -448,7 +475,7 @@ test_open_syncs(void)
448475
}
449476

450477
if ((tmpfile=open(filename,O_RDWR |OPEN_SYNC_FLAG |PG_O_DIRECT,0))==-1)
451-
printf(NA_FORMAT,"n/a**\n");
478+
printf(NA_FORMAT,"o_direct","n/a**\n");
452479
else
453480
{
454481
printf(LABEL_FORMAT,"2 open_sync 8k writes");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp