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

Commit9e231ba

Browse files
committed
Have program default to 1000 loops, and add file name and loop option.
Make open/close loop testings the same. Add descriptions for certain tests.
1 parent9ae9ad1 commit9e231ba

File tree

2 files changed

+109
-58
lines changed

2 files changed

+109
-58
lines changed

‎src/tools/fsync/README

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
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.
1+
This program tests fsync. The tests are described as part of the program output.
42

5-
The program writes to /var/tmp because /tmp is sometimes a memory file
6-
system.
3+
Usage:test_fsync [-f filename] [loops]
74

5+
Loops defaults to 1000.

‎src/tools/fsync/test_fsync.c

Lines changed: 106 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include<sys/time.h>
1515
#include<unistd.h>
1616

17+
#defineFSYNC_FILENAME"/var/tmp/test_fsync.out"
18+
1719
/* O_SYNC and O_FSYNC are the same */
1820
#if defined(O_SYNC)
1921
#defineOPEN_SYNC_FLAGO_SYNC
@@ -36,12 +38,25 @@ main(int argc, char *argv[])
3638
structtimevalstart_t;
3739
structtimevalelapse_t;
3840
inttmpfile,
39-
i;
41+
i,
42+
loops=1000;
4043
char*strout= (char*)malloc(65536);
44+
char*filename=FSYNC_FILENAME;
4145

46+
if (argc>2&&strcmp(argv[1],"-f")==0)
47+
{
48+
filename=argv[2];
49+
argv+=2;
50+
argc-=2;
51+
}
52+
53+
if (argc>1)
54+
loops=atoi(argv[1]);
55+
4256
for (i=0;i<65536;i++)
4357
strout[i]='a';
44-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |O_CREAT,S_IRUSR |S_IWUSR))==-1)
58+
59+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR |O_CREAT,S_IRUSR |S_IWUSR))==-1)
4560
die("can't open /var/tmp/test_fsync.out");
4661
write(tmpfile,strout,65536);
4762
fsync(tmpfile);/* fsync so later fsync's don't have to do
@@ -51,40 +66,54 @@ main(int argc, char *argv[])
5166
printf("Simple write timing:\n");
5267
/* write only */
5368
gettimeofday(&start_t,NULL);
54-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR))==-1)
55-
die("can't open /var/tmp/test_fsync.out");
56-
write(tmpfile,strout,8192);
57-
close(tmpfile);
69+
for (i=0;i<loops;i++)
70+
{
71+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR))==-1)
72+
die("can't open /var/tmp/test_fsync.out");
73+
write(tmpfile,strout,8192);
74+
close(tmpfile);
75+
}
5876
gettimeofday(&elapse_t,NULL);
5977
printf("\twrite ");
6078
print_elapse(start_t,elapse_t);
61-
printf("\n\n");
79+
printf("\n");
6280

63-
printf("Compare fsync before and after write's close:\n");
81+
printf("\nCompare fsync times on write() and non-write() descriptor:\n");
82+
printf("(If the times are similar, fsync() can sync data written\n on a different descriptor.)\n");
6483

6584
/* write, fsync, close */
6685
gettimeofday(&start_t,NULL);
67-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR))==-1)
68-
die("can't open /var/tmp/test_fsync.out");
69-
write(tmpfile,strout,8192);
70-
fsync(tmpfile);
71-
close(tmpfile);
86+
for (i=0;i<loops;i++)
87+
{
88+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR))==-1)
89+
die("can't open /var/tmp/test_fsync.out");
90+
write(tmpfile,strout,8192);
91+
fsync(tmpfile);
92+
close(tmpfile);
93+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR))==-1)
94+
die("can't open /var/tmp/test_fsync.out");
95+
/* do nothing but the open/close the tests are consistent. */
96+
close(tmpfile);
97+
}
7298
gettimeofday(&elapse_t,NULL);
7399
printf("\twrite, fsync, close ");
74100
print_elapse(start_t,elapse_t);
75101
printf("\n");
76102

77103
/* write, close, fsync */
78104
gettimeofday(&start_t,NULL);
79-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR))==-1)
80-
die("can't open /var/tmp/test_fsync.out");
81-
write(tmpfile,strout,8192);
82-
close(tmpfile);
83-
/* reopen file */
84-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR))==-1)
85-
die("can't open /var/tmp/test_fsync.out");
86-
fsync(tmpfile);
87-
close(tmpfile);
105+
for (i=0;i<loops;i++)
106+
{
107+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR))==-1)
108+
die("can't open /var/tmp/test_fsync.out");
109+
write(tmpfile,strout,8192);
110+
close(tmpfile);
111+
/* reopen file */
112+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR))==-1)
113+
die("can't open /var/tmp/test_fsync.out");
114+
fsync(tmpfile);
115+
close(tmpfile);
116+
}
88117
gettimeofday(&elapse_t,NULL);
89118
printf("\twrite, close, fsync ");
90119
print_elapse(start_t,elapse_t);
@@ -93,22 +122,26 @@ main(int argc, char *argv[])
93122
printf("\nCompare one o_sync write to two:\n");
94123

95124
/* 16k o_sync write */
96-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |OPEN_SYNC_FLAG))==-1)
125+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR |OPEN_SYNC_FLAG))==-1)
97126
die("can't open /var/tmp/test_fsync.out");
98127
gettimeofday(&start_t,NULL);
99-
write(tmpfile,strout,16384);
128+
for (i=0;i<loops;i++)
129+
write(tmpfile,strout,16384);
100130
gettimeofday(&elapse_t,NULL);
101131
close(tmpfile);
102132
printf("\tone 16k o_sync write ");
103133
print_elapse(start_t,elapse_t);
104134
printf("\n");
105135

106136
/* 2*8k o_sync writes */
107-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |OPEN_SYNC_FLAG))==-1)
137+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR |OPEN_SYNC_FLAG))==-1)
108138
die("can't open /var/tmp/test_fsync.out");
109139
gettimeofday(&start_t,NULL);
110-
write(tmpfile,strout,8192);
111-
write(tmpfile,strout,8192);
140+
for (i=0;i<loops;i++)
141+
{
142+
write(tmpfile,strout,8192);
143+
write(tmpfile,strout,8192);
144+
}
112145
gettimeofday(&elapse_t,NULL);
113146
close(tmpfile);
114147
printf("\ttwo 8k o_sync writes ");
@@ -119,10 +152,11 @@ main(int argc, char *argv[])
119152

120153
#ifdefOPEN_DATASYNC_FLAG
121154
/* open_dsync, write */
122-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |O_DSYNC))==-1)
155+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR |O_DSYNC))==-1)
123156
die("can't open /var/tmp/test_fsync.out");
124157
gettimeofday(&start_t,NULL);
125-
write(tmpfile,strout,8192);
158+
for (i=0;i<loops;i++)
159+
write(tmpfile,strout,8192);
126160
gettimeofday(&elapse_t,NULL);
127161
close(tmpfile);
128162
printf("\topen o_dsync, write ");
@@ -133,10 +167,11 @@ main(int argc, char *argv[])
133167
printf("\n");
134168

135169
/* open_fsync, write */
136-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |OPEN_SYNC_FLAG))==-1)
170+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR |OPEN_SYNC_FLAG))==-1)
137171
die("can't open /var/tmp/test_fsync.out");
138172
gettimeofday(&start_t,NULL);
139-
write(tmpfile,strout,8192);
173+
for (i=0;i<loops;i++)
174+
write(tmpfile,strout,8192);
140175
gettimeofday(&elapse_t,NULL);
141176
close(tmpfile);
142177
printf("\topen o_sync, write ");
@@ -145,11 +180,14 @@ main(int argc, char *argv[])
145180

146181
#ifdefHAVE_FDATASYNC
147182
/* write, fdatasync */
148-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR))==-1)
183+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR))==-1)
149184
die("can't open /var/tmp/test_fsync.out");
150185
gettimeofday(&start_t,NULL);
151-
write(tmpfile,strout,8192);
152-
fdatasync(tmpfile);
186+
for (i=0;i<loops;i++)
187+
{
188+
write(tmpfile,strout,8192);
189+
fdatasync(tmpfile);
190+
}
153191
gettimeofday(&elapse_t,NULL);
154192
close(tmpfile);
155193
printf("\twrite, fdatasync ");
@@ -160,11 +198,14 @@ main(int argc, char *argv[])
160198
printf("\n");
161199

162200
/* write, fsync, close */
163-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR))==-1)
201+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR))==-1)
164202
die("can't open /var/tmp/test_fsync.out");
165203
gettimeofday(&start_t,NULL);
166-
write(tmpfile,strout,8192);
167-
fsync(tmpfile);
204+
for (i=0;i<loops;i++)
205+
{
206+
write(tmpfile,strout,8192);
207+
fsync(tmpfile);
208+
}
168209
gettimeofday(&elapse_t,NULL);
169210
close(tmpfile);
170211
printf("\twrite, fsync, ");
@@ -176,11 +217,14 @@ main(int argc, char *argv[])
176217

177218
#ifdefOPEN_DATASYNC_FLAG
178219
/* open_dsync, write */
179-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |O_DSYNC))==-1)
220+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR |O_DSYNC))==-1)
180221
die("can't open /var/tmp/test_fsync.out");
181222
gettimeofday(&start_t,NULL);
182-
write(tmpfile,strout,8192);
183-
write(tmpfile,strout,8192);
223+
for (i=0;i<loops;i++)
224+
{
225+
write(tmpfile,strout,8192);
226+
write(tmpfile,strout,8192);
227+
}
184228
gettimeofday(&elapse_t,NULL);
185229
close(tmpfile);
186230
printf("\topen o_dsync, write ");
@@ -191,11 +235,14 @@ main(int argc, char *argv[])
191235
printf("\n");
192236

193237
/* open_fsync, write */
194-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR |OPEN_SYNC_FLAG))==-1)
238+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR |OPEN_SYNC_FLAG))==-1)
195239
die("can't open /var/tmp/test_fsync.out");
196240
gettimeofday(&start_t,NULL);
197-
write(tmpfile,strout,8192);
198-
write(tmpfile,strout,8192);
241+
for (i=0;i<loops;i++)
242+
{
243+
write(tmpfile,strout,8192);
244+
write(tmpfile,strout,8192);
245+
}
199246
gettimeofday(&elapse_t,NULL);
200247
close(tmpfile);
201248
printf("\topen o_sync, write ");
@@ -204,12 +251,15 @@ main(int argc, char *argv[])
204251

205252
#ifdefHAVE_FDATASYNC
206253
/* write, fdatasync */
207-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR))==-1)
254+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR))==-1)
208255
die("can't open /var/tmp/test_fsync.out");
209256
gettimeofday(&start_t,NULL);
210-
write(tmpfile,strout,8192);
211-
write(tmpfile,strout,8192);
212-
fdatasync(tmpfile);
257+
for (i=0;i<loops;i++)
258+
{
259+
write(tmpfile,strout,8192);
260+
write(tmpfile,strout,8192);
261+
fdatasync(tmpfile);
262+
}
213263
gettimeofday(&elapse_t,NULL);
214264
close(tmpfile);
215265
printf("\twrite, fdatasync ");
@@ -220,19 +270,22 @@ main(int argc, char *argv[])
220270
printf("\n");
221271

222272
/* write, fsync, close */
223-
if ((tmpfile=open("/var/tmp/test_fsync.out",O_RDWR))==-1)
273+
if ((tmpfile=open(FSYNC_FILENAME,O_RDWR))==-1)
224274
die("can't open /var/tmp/test_fsync.out");
225275
gettimeofday(&start_t,NULL);
226-
write(tmpfile,strout,8192);
227-
write(tmpfile,strout,8192);
228-
fsync(tmpfile);
276+
for (i=0;i<loops;i++)
277+
{
278+
write(tmpfile,strout,8192);
279+
write(tmpfile,strout,8192);
280+
fsync(tmpfile);
281+
}
229282
gettimeofday(&elapse_t,NULL);
230283
close(tmpfile);
231284
printf("\twrite, fsync, ");
232285
print_elapse(start_t,elapse_t);
233286
printf("\n");
234287

235-
unlink("/var/tmp/test_fsync.out");
288+
unlink(FSYNC_FILENAME);
236289

237290
return0;
238291
}
@@ -246,7 +299,7 @@ print_elapse(struct timeval start_t, struct timeval elapse_t)
246299
elapse_t.tv_usec+=1000000;
247300
}
248301

249-
printf("%ld.%06ld", (long) (elapse_t.tv_sec-start_t.tv_sec),
302+
printf("%3ld.%06ld", (long) (elapse_t.tv_sec-start_t.tv_sec),
250303
(long) (elapse_t.tv_usec-start_t.tv_usec));
251304
}
252305

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp