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

Commit 32e8f76

Browse files
Ex 14-1 completed.
1 parent 8fcb598 commit 32e8f76

File tree

2 files changed

+99
-3
lines changed

2 files changed

+99
-3
lines changed

‎14_File_Systems/README.md‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@ To build the solution, run `make ex14_1`.
77

88
The command options are:
99
1. __-n__ number of files to create
10-
1. __-r__ delete files in descending order of creation
10+
1. __-s__ create files in sequential order
1111
1. __-v__ - shows more detailed output
12-
1. mount point of target file system
12+
1. target directory
13+
14+
Statistics collected:
15+
1. File system type
16+
1. Create files in random (r) or sequential (s) order
17+
1. Number of files created
18+
1. Wall clock time in seconds
19+
1. User time in seconds
20+
1. System time in seconds
21+
22+
Sample run with random order of creation:
23+
```bash
24+
time ./ex14_1 -n 1000 test
25+
0x03E706FF r 1000 2.859000 0.109000 2.750000
26+
real 0m 5.12s
27+
user 0m 0.25s
28+
sys 0m 4.45s
29+
```
30+
31+
Sample run with sequential order of creation:
32+
```bash
33+
time ./ex14_1 -sn 1000 test
34+
0x03E706FF s 1000 2.547000 0.078000 2.469000
35+
real 0m 4.35s
36+
user 0m 0.21s
37+
sys 0m 3.96s
38+
```

‎14_File_Systems/ex14_1.c‎

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
#include <error.h>
1313
#include <fcntl.h>
14-
#include <stdlib.h>
1514
#include <stdio.h>
15+
#include <stdlib.h>
1616
#include <sys/statfs.h>
17+
#include <sys/times.h>
1718
#include <sys/types.h>
19+
#include <time.h>
1820
#include <unistd.h>
1921

2022
/* --------------------------------------------------------------------------
@@ -149,11 +151,79 @@ int main(int argc, char *argv[])
149151
fprintf(stderr, "FS free i-nodes : %ld\n", (long)fs_info.f_ffree);
150152
}
151153

154+
/* ----------------------------------------------------------------------
155+
| Start collecting timing information
156+
* ---------------------------------------------------------------------- */
157+
158+
long clockTicks = sysconf(_SC_CLK_TCK); /* Clocks per tick for conversion */
159+
struct tms start_t;
160+
clock_t start_clockTime = clock();
161+
162+
if (clockTicks == -1)
163+
{
164+
fprintf(stderr, "sysconf(_SC_CLK_TCK) failed: %m\n");
165+
exit(EXIT_FAILURE);
166+
}
167+
if (start_clockTime == -1)
168+
{
169+
fprintf(stderr, "clock() failed: %m\n");
170+
exit(EXIT_FAILURE);
171+
}
172+
if (times(&start_t) == -1)
173+
{
174+
fprintf(stderr, "times() failed: %m\n");
175+
exit(EXIT_FAILURE);
176+
}
177+
178+
/* ----------------------------------------------------------------------
179+
| Create the requested number of files
180+
* ---------------------------------------------------------------------- */
181+
182+
if (random_creation) {
183+
srandom(start_clockTime);
184+
}
185+
152186
for (int i = 0; i < num_files_required; i++)
153187
{
154188
long file_num = random_creation ? random() % 1000000 : i;
155189
create_file(output_dir_name, file_num, verbosity);
156190
}
191+
192+
/*------------------------------------------------------------------------*\
193+
| Print statistics for later analysis |
194+
| 1. File system type |
195+
| 2. Create files in random order? |
196+
| 3. Number of files created |
197+
| 4. Wall clock time in seconds |
198+
| 5. User time in seconds |
199+
| 6. System time in seconds |
200+
\*------------------------------------------------------------------------*/
201+
202+
struct tms end_t;
203+
clock_t end_clockTime = clock();
204+
205+
if (end_clockTime == -1)
206+
{
207+
fprintf(stderr, "clock() failed: %m\n");
208+
exit(EXIT_FAILURE);
209+
}
210+
if (times(&end_t) == -1)
211+
{
212+
fprintf(stderr, "times() failed: %m\n");
213+
exit(EXIT_FAILURE);
214+
}
215+
printf("0x%08lX\t%c\t%ld\t%.6f\t%.6f\t%.6f\n",
216+
(long)fs_info.f_type,
217+
(random_creation) ? 'r' : 's',
218+
num_files_required,
219+
(double) (end_clockTime - start_clockTime) / CLOCKS_PER_SEC,
220+
(double) (end_t.tms_utime - start_t.tms_utime) / clockTicks,
221+
(double) (end_t.tms_stime - start_t.tms_stime) / clockTicks
222+
);
223+
224+
/* ----------------------------------------------------------------------
225+
| Delete all files in the directory
226+
* ---------------------------------------------------------------------- */
157227

158228
char cmd[1024];
159229
sprintf(cmd, "find %s -type f -delete", output_dir_name);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /