-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimd_exporter.c
More file actions
637 lines (530 loc) · 14.4 KB
/
Copy pathsimd_exporter.c
File metadata and controls
637 lines (530 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <inttypes.h>
#include <getopt.h>
#include <errno.h>
#include <glib.h>
#include <fcntl.h>
#include "libhashfile.h"
#include "store.h"
static gboolean hash20_equal(gpointer a, gpointer b){
return !memcmp(a, b, 20);
}
/* The number of lines relies on chunksize;
* Only chunk-level trace requires this */
static void print_a_chunk(int chunksize, int64_t content){
int lines_no = (chunksize+1023)/1024;
assert(lines_no >= 1);
assert(lines_no <= 16);
int i = 0;
for(; i<lines_no; i++)
printf("%"PRId64"\n", content);
}
/* there is no trace for chunk-level with dedup */
/* Fixed-sized file system block of 8 KB if weighted */
void chunk_nodedup_simd_trace(char **path, int count, int weighted){
if (weighted) {
fprintf(stderr, "CHUNK:NO DEDUP:WEIGHTED\n");
printf("CHUNK:NO DEDUP:WEIGHTED\n");
init_iterator("CHUNK");
struct chunk_rec chunk;
memset(&chunk, 0, sizeof(chunk));
int64_t sum = 0;
int64_t count = 0;
/* USE part */
while(iterate_chunk(&chunk, 0) == 0){
int i = 0;
int64_t size = chunk.csize;
for(; i<chunk.rcount; i++){
int lines_no = (chunk.csize+1023)/1024;
sum += size*lines_no;
count += lines_no;
}
}
fprintf(stderr, "%.6f\n", 1.0*sum/count);
close_iterator();
}else{
fprintf(stderr, "CHUNK:NO DEDUP:NOT WEIGHTED\n");
printf("CHUNK:NO DEDUP:NOT WEIGHTED\n");
}
fprintf(stderr, "No trace for this model; only for test\n");
}
/*
* Chunk level, without file semantics
* Dedup
* (no trace for chunk-level no-dedup model)
*/
void chunk_dedup_simd_trace(char **path, int count, int weighted, char *pophashfile)
{
if (weighted) {
fprintf(stderr, "CHUNK:DEDUP:WEIGHTED\n");
printf("CHUNK:DEDUP:WEIGHTED\n");
} else {
fprintf(stderr, "CHUNK:DEDUP:NOT WEIGHTED\n");
printf("CHUNK:DEDUP:NOT WEIGHTED\n");
}
init_iterator("CHUNK");
struct chunk_rec chunk;
memset(&chunk, 0, sizeof(chunk));
int64_t psize = 0;
int64_t lsize = 0;
int64_t total_chunks = 0;
/* USE part */
int64_t sum4mean = 0;
int64_t count4mean = 0;
while (iterate_chunk(&chunk, 0) == 0) {
int64_t sum = chunk.csize;
sum *= chunk.rcount;
lsize += sum;
psize += chunk.csize;
total_chunks += chunk.rcount;
if (weighted) {
sum4mean += sum * chunk.csize;
count4mean += chunk.csize;
print_a_chunk(chunk.csize, sum);
} else {
sum4mean += sum;
count4mean += chunk.csize;
print_a_chunk(chunk.csize, chunk.rcount);
}
}
printf("%.6f\n", 1.0*lsize/psize);
fprintf(stderr, "D/F = %.4f, total_chunks = %"PRId64"\n", 1.0*lsize/psize,
total_chunks);
fprintf(stderr, "mean = %.4f, per DF = %.6f\n", 1.0*sum4mean/count4mean,
1.0*sum4mean*psize/count4mean/lsize);
close_iterator();
char buf[4096];
struct hashfile_handle *handle;
const struct chunk_info *ci;
int64_t restore_logical_bytes = 0;
int64_t restore_physical_bytes = 0;
int64_t restore_chunks = 0;
GHashTable* chunks = g_hash_table_new_full(g_int_hash, hash20_equal, free,
NULL);
/* RAID Failure part */
/* 1 - 99 */
int step = 1;
/* All chunks lost */
puts("0");
if (pophashfile) {
int popfd = open(pophashfile, O_RDONLY);
char pophashbuf[20];
while (read(popfd, pophashbuf, 20) == 20) {
char *pophash = malloc(20);
memcpy(pophash, pophashbuf, 20);
/* restoring a pop chunk */
memcpy(chunk.hash, pophash, 20);
assert(search_chunk(&chunk));
int64_t sum = chunk.csize;
sum *= chunk.rcount;
restore_chunks += chunk.rcount;
restore_physical_bytes += chunk.csize;
restore_logical_bytes += sum;
int progress = restore_physical_bytes * 100/psize;
while (progress >= step && step <= 99) {
if (weighted) {
printf("%.6f\n", 1.0*restore_logical_bytes/lsize);
fprintf(stderr, "%.6f\n", 1.0*restore_logical_bytes/lsize);
} else {
printf("%.6f\n", 1.0*restore_chunks/total_chunks);
fprintf(stderr, "%.6f\n", 1.0*restore_chunks/total_chunks);
}
step++;
}
assert(!g_hash_table_contains(chunks, pophash));
g_hash_table_insert(chunks, pophash, NULL);
}
close(popfd);
}
int pc = 0;
for (; pc < count; pc++) {
handle = hashfile_open(path[pc]);
if (!handle) {
fprintf(stderr, "Error opening hash file: %d!", errno);
exit(-1);
}
while (1) {
int ret = hashfile_next_file(handle);
if (ret < 0) {
fprintf(stderr,
"Cannot get next file from a hashfile: %d!\n",
errno);
exit(-1);
}
if (ret == 0)
break;
while (1) {
ci = hashfile_next_chunk(handle);
if (!ci) /* exit the loop if it was the last chunk */
break;
int hashsize = hashfile_hash_size(handle)/8;
int chunksize = ci->size;
memcpy(chunk.hash, ci->hash, hashsize);
memcpy(&chunk.hash[hashsize], &chunksize, sizeof(chunksize));
chunk.hashlen = hashfile_hash_size(handle)/8 + sizeof(chunksize);
if (!g_hash_table_contains(chunks, chunk.hash)) {
assert(search_chunk(&chunk));
int64_t sum = chunk.csize;
sum *= chunk.rcount;
restore_chunks += chunk.rcount;
restore_physical_bytes += chunk.csize;
restore_logical_bytes += sum;
int progress = restore_physical_bytes * 100/psize;
while (progress >= step && step <= 99) {
if (weighted) {
printf("%.6f\n", 1.0*restore_logical_bytes/lsize);
fprintf(stderr, "%.6f\n", 1.0*restore_logical_bytes/lsize);
} else {
printf("%.6f\n", 1.0*restore_chunks/total_chunks);
fprintf(stderr, "%.6f\n", 1.0*restore_chunks/total_chunks);
}
step++;
}
char* hash = malloc(20);
memcpy(hash, chunk.hash, 20);
g_hash_table_insert(chunks, hash, NULL);
}
}
}
hashfile_close(handle);
}
g_hash_table_destroy(chunks);
puts("1.0");
}
/*
* File level, no dedup
* weighted by size?
*/
void file_nodedup_simd_trace(char **path, int count, int weighted)
{
if (weighted) {
printf("FILE:NO DEDUP:WEIGHTED\n");
fprintf(stderr, "FILE:NO DEDUP:WEIGHTED\n");
} else {
printf("FILE:NO DEDUP:NOT WEIGHTED\n");
fprintf(stderr, "FILE:NO DEDUP:NOT WEIGHTED\n");
}
int64_t sys_capacity = 0;
int64_t sys_file_number = 0;
init_iterator("CHUNK");
struct chunk_rec chunk;
memset(&chunk, 0, sizeof(chunk));
struct file_rec fr;
memset(&fr, 0, sizeof(fr));
/* USE part */
while (iterate_chunk(&chunk, 0) == 0) {
int64_t sum = chunk.csize;
sum *= chunk.rcount;
sys_capacity += sum;
int i = 0;
int prev = -1;
for (; i<chunk.rcount; i++) {
int fid = chunk.list[chunk.rcount+i];
fr.fid = fid;
search_file(&fr);
prev = fid;
if(weighted)
printf("%"PRId64"\n", fr.fsize);
else{
/* A single file is lost */
/* no need to output */
}
}
}
close_iterator();
sys_file_number = get_file_number();
fprintf(stderr, "capacity = %.4f GB, Files = %"PRId64"\n",
1.0*sys_capacity/1024/1024/1024, sys_file_number);
char buf[4096];
struct hashfile_handle *handle;
const struct chunk_info *ci;
/* RAID Failure part */
/* All files lost */
puts("0");
int64_t restore_bytes = 0;
int64_t restore_files = 0;
int64_t restore_file_bytes = 0;
/* 1 - 99 */
int step = 1;
int pc = 0;
for (; pc < count; pc++) {
handle = hashfile_open(path[pc]);
if (!handle) {
fprintf(stderr, "Error opening hash file: %d!", errno);
exit(-1);
}
while (1) {
int ret = hashfile_next_file(handle);
if (ret < 0) {
fprintf(stderr,
"Cannot get next file from a hashfile: %d!\n",
errno);
exit(-1);
}
if (ret == 0)
break;
int64_t filesize = 0;
while (1) {
ci = hashfile_next_chunk(handle);
if (!ci) /* exit the loop if it was the last chunk */
break;
int progress = restore_bytes * 100 / sys_capacity;
while(progress >= step && step <= 99){
if(!weighted)
printf("%.6f\n", 1.0*restore_files/sys_file_number);
else
printf("%.6f\n", 1.0*restore_file_bytes/sys_capacity);
step++;
}
/* It will overflow */
/*restore_bytes += ci->size;*/
int size = ci->size;
restore_bytes += size;
filesize += size;
}
/*if(filesize != hashfile_curfile_size(handle))*/
/*printf("%"PRId64" is not %"PRIu64"\n", filesize, hashfile_curfile_size(handle));*/
/*else*/
/*printf("%"PRId64" == %"PRIu64"\n", filesize, hashfile_curfile_size(handle));*/
if(filesize == 0)
continue;
restore_files++;
restore_file_bytes += filesize;
}
hashfile_close(handle);
}
puts("1.0");
}
struct restoring_file{
int id;
int chunk_num;
int64_t size;
};
void file_dedup_simd_trace(char** path, int count, int weighted, char *pophashfile)
{
if (weighted) {
printf("FILE:DEDUP:WEIGHTED\n");
fprintf(stderr, "FILE:DEDUP:WEIGHTED\n");
} else {
printf("FILE:DEDUP:NOT WEIGHTED\n");
fprintf(stderr, "FILE:DEDUP:NOT WEIGHTED\n");
}
init_iterator("CHUNK");
struct chunk_rec chunk;
memset(&chunk, 0, sizeof(chunk));
struct file_rec fr;
memset(&fr, 0, sizeof(fr));
/* USE part */
int64_t psize = 0;
int64_t lsize = 0;
while (iterate_chunk(&chunk, 0) == 0) {
int64_t sum = chunk.csize;
sum *= chunk.rcount;
lsize += sum;
psize += chunk.csize;
if (!weighted) {
printf("%d\n", chunk.fcount);
} else {
int i = 0;
int prev = -1;
int64_t sum = 0;
for (; i<chunk.rcount; i++) {
int fid = chunk.list[chunk.rcount+i];
if (fid == prev)
continue;
fr.fid = fid;
search_file(&fr);
sum+=fr.fsize;
prev = fid;
}
printf("%"PRId64"\n", sum);
}
}
printf("%.6f\n", 1.0*lsize/psize);
fprintf(stderr, "LS = %.4f GB, PS = %.4f GB, D/F = %.4f\n",
1.0*lsize/1024/1024/1024,
1.0*psize/1024/1024/1024, 1.0*lsize/psize);
close_iterator();
char buf[4096];
struct hashfile_handle *handle;
const struct chunk_info *ci;
int64_t sys_file_number = get_file_number();
/* All files lost */
puts("0");
int64_t restore_bytes = 0;
int64_t restore_files = 0;
int64_t restore_file_bytes = 0;
/* RAID Failure part */
/* 1 - 99 */
int step = 1;
GHashTable* files = g_hash_table_new_full(g_int_hash, g_int_equal,
NULL, free);
GHashTable* chunks = g_hash_table_new_full(g_int_hash, hash20_equal,
free, NULL);
if (pophashfile) {
int popfd = open(pophashfile, O_RDONLY);
char pophashbuf[20];
while (read(popfd, pophashbuf, 20) == 20) {
char *pophash = malloc(20);
memcpy(pophash, pophashbuf, 20);
/* restoring a pop chunk */
memcpy(chunk.hash, pophash, 20);
assert(search_chunk(&chunk));
int i = 0;
for (;i < chunk.rcount; i++) {
int fid = chunk.list[chunk.rcount + i];
struct restoring_file* rfile = g_hash_table_lookup(files, &fid);
if (!rfile) {
fr.fid = fid;
search_file(&fr);
rfile = malloc(sizeof(*rfile));
rfile->id = fid;
rfile->chunk_num = fr.cnum;
rfile->size = fr.fsize;
g_hash_table_insert(files, &rfile->id, rfile);
}
rfile->chunk_num--;
if (rfile->chunk_num == 0) {
/* a file is restored */
/*fprintf(stderr, "complete file %d\n", fid);*/
restore_files++;
restore_file_bytes += rfile->size;
}
assert(rfile->chunk_num >= 0);
}
restore_bytes += chunk.csize;
int progress = restore_bytes * 100 / psize;
while (progress >= step && step <= 99) {
if (!weighted)
printf("%.6f\n", 1.0*restore_files/sys_file_number);
else
printf("%.6f\n", 1.0*restore_file_bytes/lsize);
step++;
}
assert(!g_hash_table_contains(chunks, pophash));
g_hash_table_insert(chunks, pophash, NULL);
}
close(popfd);
}
int pc = 0;
for (; pc < count; pc++) {
handle = hashfile_open(path[pc]);
if (!handle) {
fprintf(stderr, "Error opening hash file: %d!", errno);
exit(-1);
}
while (1) {
int ret = hashfile_next_file(handle);
if (ret < 0) {
fprintf(stderr,
"Cannot get next file from a hashfile: %d!\n",
errno);
exit(-1);
}
if (ret == 0)
break;
while (1) {
ci = hashfile_next_chunk(handle);
if (!ci) /* exit the loop if it was the last chunk */
break;
int hashsize = hashfile_hash_size(handle)/8;
int chunksize = ci->size;
memcpy(chunk.hash, ci->hash, hashsize);
memcpy(&chunk.hash[hashsize], &chunksize, sizeof(chunksize));
chunk.hashlen = hashfile_hash_size(handle)/8 + sizeof(chunksize);
if (!g_hash_table_contains(chunks, chunk.hash)) {
/* restore a chunk */
assert(search_chunk(&chunk));
int i = 0;
for (; i < chunk.rcount; i++) {
int fid = chunk.list[chunk.rcount + i];
struct restoring_file* rfile =
g_hash_table_lookup(files, &fid);
if (!rfile) {
fr.fid = fid;
search_file(&fr);
rfile = malloc(sizeof(*rfile));
rfile->id = fid;
rfile->chunk_num = fr.cnum;
rfile->size = fr.fsize;
g_hash_table_insert(files, &rfile->id, rfile);
}
rfile->chunk_num--;
if(rfile->chunk_num == 0){
/* a file is restored */
/*fprintf(stderr, "complete file %d\n", fid);*/
restore_files++;
restore_file_bytes += rfile->size;
}
assert(rfile->chunk_num >= 0);
}
restore_bytes += chunk.csize;
int progress = restore_bytes * 100/psize;
while (progress >= step && step <= 99) {
if (!weighted)
printf("%.6f\n", 1.0*restore_files/sys_file_number);
else
printf("%.6f\n", 1.0*restore_file_bytes/lsize);
step++;
}
char* hash = malloc(20);
memcpy(hash, chunk.hash, 20);
g_hash_table_insert(chunks, hash, hash);
}
}
}
hashfile_close(handle);
}
puts("1.0");
g_hash_table_destroy(files);
g_hash_table_destroy(chunks);
fprintf(stderr, "restore %.4f GB\n", 1.0*restore_file_bytes/1024/1024/1024);
}
int main(int argc, char *argv[])
{
/* dedup? */
int dedup = 0;
/* weighted by file/chunk size? */
int weighted = 0;
/* chunk level or file level */
int file_level = 0;
char *pophash = NULL;
int opt = 0;
while ((opt = getopt_long(argc, argv, "fwdp:", NULL, NULL))
!= -1) {
switch (opt) {
case'f':
file_level = 1;
break;
case 'd':
dedup = 1;
break;
case 'w':
weighted = 1;
break;
case 'p':
pophash = optarg;
break;
default:
fprintf(stderr, "invalid option\n");
return -1;
}
}
open_database();
if (!file_level) {
if (!dedup)
chunk_nodedup_simd_trace(&argv[optind], argc - optind, weighted);
else
chunk_dedup_simd_trace(&argv[optind], argc - optind, weighted, pophash);
} else {
if (!dedup)
file_nodedup_simd_trace(&argv[optind], argc - optind, weighted);
else
file_dedup_simd_trace(&argv[optind], argc - optind, weighted, pophash);
}
close_database();
return 0;
}