|  | 
| 11 | 11 | 
 | 
| 12 | 12 | #include <error.h> | 
| 13 | 13 | #include <fcntl.h> | 
| 14 |  | -#include <stdlib.h> | 
| 15 | 14 | #include <stdio.h> | 
|  | 15 | +#include <stdlib.h> | 
| 16 | 16 | #include <sys/statfs.h> | 
|  | 17 | +#include <sys/times.h> | 
| 17 | 18 | #include <sys/types.h> | 
|  | 19 | +#include <time.h> | 
| 18 | 20 | #include <unistd.h> | 
| 19 | 21 | 
 | 
| 20 | 22 | /* -------------------------------------------------------------------------- | 
| @@ -149,11 +151,79 @@ int main(int argc, char *argv[]) | 
| 149 | 151 |  fprintf(stderr, "FS free i-nodes : %ld\n", (long)fs_info.f_ffree); | 
| 150 | 152 |  } | 
| 151 | 153 | 
 | 
|  | 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 | + | 
| 152 | 186 |  for (int i = 0; i < num_files_required; i++) | 
| 153 | 187 |  { | 
| 154 | 188 |  long file_num = random_creation ? random() % 1000000 : i; | 
| 155 | 189 |  create_file(output_dir_name, file_num, verbosity); | 
| 156 | 190 |  } | 
|  | 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 | + * ---------------------------------------------------------------------- */ | 
| 157 | 227 | 
 | 
| 158 | 228 |  char cmd[1024]; | 
| 159 | 229 |  sprintf(cmd, "find %s -type f -delete", output_dir_name); | 
|  | 
0 commit comments