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

Commit9f2696f

Browse files
committed
Add fsync test program. It tests fsync to see if times for fsync are the
same when done on the write() ile descriptor and a new descriptor.it also times various fsync methods.
1 parent3700335 commit9f2696f

File tree

5 files changed

+186
-0
lines changed

5 files changed

+186
-0
lines changed

‎src/tools/fsync/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Makefile
3+
#
4+
#
5+
TARGET = test_fsync
6+
XFLAGS =
7+
CFLAGS = -g -Wall
8+
LIBS =
9+
10+
$(TARGET) : test_fsync.o
11+
$(CC) -o$(TARGET)$(XFLAGS)$(CFLAGS) test_fsync.o$(LIBS)
12+
13+
test_fsync.o: test_fsync.c
14+
$(CC) -c$(XFLAGS)$(CFLAGS) test_fsync.c
15+
16+
clean:
17+
rm -f*.o$(TARGET) log core
18+
19+
install:
20+
make clean
21+
make CFLAGS=-O
22+
install -s -o bin -g bin$(TARGET) /usr/local/bin

‎src/tools/fsync/README

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This program tests fsync. If first times a simple read. Then, it times
2+
an fsync that is part of a write, and one that is done on a newly opened
3+
file. Third, it tests various fsync methods.
4+
5+
The program writes to /var/tmp because /tmp is sometimes a memory file
6+
system.
7+

‎src/tools/fsync/test_fsync

13.8 KB
Binary file not shown.

‎src/tools/fsync/test_fsync.c

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
*test_fsync.c
3+
*tests if fsync can be done from another process than the original write
4+
*/
5+
6+
#include"../../include/pg_config.h"
7+
8+
#include<sys/types.h>
9+
#include<fcntl.h>
10+
#include<stdio.h>
11+
#include<stdlib.h>
12+
#include<time.h>
13+
#include<unistd.h>
14+
15+
/* O_SYNC and O_FSYNC are the same */
16+
#if defined(O_SYNC)
17+
#defineOPEN_SYNC_FLAGO_SYNC
18+
#elif defined(O_FSYNC)
19+
#defineOPEN_SYNC_FLAGO_FSYNC
20+
#endif
21+
22+
#if defined(OPEN_SYNC_FLAG)
23+
#if defined(O_DSYNC)&& (O_DSYNC!=OPEN_SYNC_FLAG)
24+
#defineOPEN_DATASYNC_FLAGO_DSYNC
25+
#endif
26+
#endif
27+
28+
voiddie(char*str);
29+
voidprint_elapse(structtimevalstart_t,structtimevalelapse_t);
30+
31+
intmain(intargc,char*argv[])
32+
{
33+
structtimevalstart_t;
34+
structtimevalelapse_t;
35+
inttmpfile;
36+
char*strout="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
37+
38+
printf("Simple write timing:\n");
39+
/* write only */
40+
gettimeofday(&start_t,NULL);
41+
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |O_CREAT))==-1)
42+
die("can't open /var/tmp/test_fsync.out");
43+
write(tmpfile,&strout,200);
44+
close(tmpfile);
45+
gettimeofday(&elapse_t,NULL);
46+
unlink("/var/tmp/test_fsync.out");
47+
printf("write ");
48+
print_elapse(start_t,elapse_t);
49+
printf("\n\n");
50+
51+
printf("Compare fsync before and after write's close:\n");
52+
/* write, fsync, close */
53+
gettimeofday(&start_t,NULL);
54+
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |O_CREAT))==-1)
55+
die("can't open /var/tmp/test_fsync.out");
56+
write(tmpfile,&strout,200);
57+
fsync(tmpfile);
58+
close(tmpfile);
59+
gettimeofday(&elapse_t,NULL);
60+
unlink("/var/tmp/test_fsync.out");
61+
printf("write, fsync, close ");
62+
print_elapse(start_t,elapse_t);
63+
printf("\n");
64+
65+
/* write, close, fsync */
66+
gettimeofday(&start_t,NULL);
67+
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |O_CREAT))==-1)
68+
die("can't open /var/tmp/test_fsync.out");
69+
write(tmpfile,&strout,200);
70+
close(tmpfile);
71+
/* reopen file */
72+
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |O_CREAT))==-1)
73+
die("can't open /var/tmp/test_fsync.out");
74+
fsync(tmpfile);
75+
close(tmpfile);
76+
gettimeofday(&elapse_t,NULL);
77+
unlink("/var/tmp/test_fsync.out");
78+
printf("write, close, fsync ");
79+
print_elapse(start_t,elapse_t);
80+
printf("\n");
81+
82+
printf("\nTest file sync methods\n");
83+
84+
#ifdefOPEN_DATASYNC_FLAG
85+
/* open_dsync, write */
86+
gettimeofday(&start_t,NULL);
87+
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |O_CREAT |O_DSYNC))==-1)
88+
die("can't open /var/tmp/test_fsync.out");
89+
write(tmpfile,&strout,200);
90+
close(tmpfile);
91+
gettimeofday(&elapse_t,NULL);
92+
unlink("/var/tmp/test_fsync.out");
93+
printf("open o_dsync, write ");
94+
print_elapse(start_t,elapse_t);
95+
printf("\n");
96+
#endif
97+
98+
/* open_fsync, write */
99+
gettimeofday(&start_t,NULL);
100+
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |O_CREAT |OPEN_SYNC_FLAG))==-1)
101+
die("can't open /var/tmp/test_fsync.out");
102+
write(tmpfile,&strout,200);
103+
close(tmpfile);
104+
gettimeofday(&elapse_t,NULL);
105+
unlink("/var/tmp/test_fsync.out");
106+
printf("open o_fsync, write ");
107+
print_elapse(start_t,elapse_t);
108+
printf("\n");
109+
110+
#ifdefHAVE_FDATASYNC
111+
/* write, fdatasync */
112+
gettimeofday(&start_t,NULL);
113+
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |O_CREAT))==-1)
114+
die("can't open /var/tmp/test_fsync.out");
115+
write(tmpfile,&strout,200);
116+
fdatasync(tmpfile);
117+
close(tmpfile);
118+
gettimeofday(&elapse_t,NULL);
119+
unlink("/var/tmp/test_fsync.out");
120+
printf("write, fdatasync ");
121+
print_elapse(start_t,elapse_t);
122+
printf("\n");
123+
#endif
124+
125+
/* write, fsync, close */
126+
gettimeofday(&start_t,NULL);
127+
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |O_CREAT))==-1)
128+
die("can't open /var/tmp/test_fsync.out");
129+
write(tmpfile,&strout,200);
130+
fsync(tmpfile);
131+
close(tmpfile);
132+
gettimeofday(&elapse_t,NULL);
133+
unlink("/var/tmp/test_fsync.out");
134+
printf("write, fsync, ");
135+
print_elapse(start_t,elapse_t);
136+
printf("\n");
137+
138+
return0;
139+
}
140+
141+
voidprint_elapse(structtimevalstart_t,structtimevalelapse_t)
142+
{
143+
if (elapse_t.tv_usec<start_t.tv_usec)
144+
{
145+
elapse_t.tv_sec--;
146+
elapse_t.tv_usec+=1000000;
147+
}
148+
149+
printf("%ld.%06ld", (long) (elapse_t.tv_sec-start_t.tv_sec),
150+
(long) (elapse_t.tv_usec-start_t.tv_usec));
151+
}
152+
153+
voiddie(char*str)
154+
{
155+
fprintf(stderr,"%s",str);
156+
exit(1);
157+
}

‎src/tools/fsync/test_fsync.o

10.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp