@@ -111,6 +111,8 @@ using std::set;
111
111
using std::string;
112
112
using std::vector;
113
113
114
+ static bool verbose = false ;
115
+
114
116
static void ba_replay_assert (bool pred, const char *msg, const char *line, int line_num) {
115
117
if (!pred) {
116
118
fprintf (stderr, " %s, line (#%d): %s\n " , msg, line_num, line);
@@ -259,7 +261,10 @@ static void replay_canonicalized_trace(const vector<string> &canonicalized_trace
259
261
260
262
char *line = toku_strdup (it->c_str ());
261
263
262
- printf (" playing canonical trace line #%d: %s" , line_num, line);
264
+ if (verbose) {
265
+ printf (" playing canonical trace line #%d: %s" , line_num, line);
266
+ }
267
+
263
268
char *ptr = tidy_line (line);
264
269
265
270
// canonical allocator id is in base 10, not 16
@@ -335,30 +340,43 @@ static void print_result(uint64_t allocator_id,
335
340
uint64_t total_bytes = report->data_bytes + report->unused_bytes ;
336
341
uint64_t total_blocks = report->data_blocks + report->unused_blocks ;
337
342
if (total_bytes < 32UL * 1024 * 1024 ) {
338
- printf (" skipping allocator_id %" PRId64 " (total bytes < 32mb)\n " , allocator_id);
343
+ printf (" ...skipping allocator_id %" PRId64 " (total bytes < 32mb)\n " , allocator_id);
344
+ printf (" \n " );
339
345
return ;
340
346
}
341
347
342
- printf (" \n " );
343
- printf (" allocator_id: %20" PRId64 " \n " , allocator_id);
344
- printf (" strategy: %20s\n " , strategy_str (strategy));
348
+ printf (" allocator_id: %20" PRId64 " \n " , allocator_id);
349
+ printf (" strategy: %20s\n " , strategy_str (strategy));
345
350
346
351
// byte statistics
347
- printf (" total bytes: %20" PRId64 " \n " , total_bytes);
348
- printf (" used bytes: %20" PRId64 " (%.3lf)\n " , report->data_bytes ,
352
+ printf (" total bytes: %20" PRId64 " \n " , total_bytes);
353
+ printf (" used bytes: %20" PRId64 " (%.3lf)\n " , report->data_bytes ,
349
354
static_cast <double >(report->data_bytes ) / total_bytes);
350
- printf (" unused bytes: %20" PRId64 " (%.3lf)\n " , report->unused_bytes ,
355
+ printf (" unused bytes: %20" PRId64 " (%.3lf)\n " , report->unused_bytes ,
351
356
static_cast <double >(report->unused_bytes ) / total_bytes);
352
357
353
358
// block statistics
354
- printf (" total blocks: %20" PRId64 " \n " , total_blocks);
355
- printf (" used blocks: %20" PRId64 " (%.3lf)\n " , report->data_blocks ,
359
+ printf (" total blocks: %20" PRId64 " \n " , total_blocks);
360
+ printf (" used blocks: %20" PRId64 " (%.3lf)\n " , report->data_blocks ,
356
361
static_cast <double >(report->data_blocks ) / total_blocks);
357
- printf (" unused blocks: %20" PRId64 " (%.3lf)\n " , report->unused_blocks ,
362
+ printf (" unused blocks: %20" PRId64 " (%.3lf)\n " , report->unused_blocks ,
358
363
static_cast <double >(report->unused_blocks ) / total_blocks);
359
364
360
365
// misc
361
- printf (" largest unused: %20" PRId64 " \n " , report->largest_unused_block );
366
+ printf (" largest unused: %20" PRId64 " \n " , report->largest_unused_block );
367
+ printf (" \n " );
368
+ }
369
+
370
+ static void merge_fragmentation_reports (TOKU_DB_FRAGMENTATION dst,
371
+ TOKU_DB_FRAGMENTATION src) {
372
+ dst->file_size_bytes += src->file_size_bytes ;
373
+ dst->data_bytes += src->data_bytes ;
374
+ dst->data_blocks += src->data_blocks ;
375
+ dst->checkpoint_bytes_additional += src->checkpoint_bytes_additional ;
376
+ dst->checkpoint_blocks_additional += src->checkpoint_blocks_additional ;
377
+ dst->unused_bytes += src->unused_bytes ;
378
+ dst->unused_blocks += src->unused_blocks ;
379
+ dst->largest_unused_block += src->largest_unused_block ;
362
380
}
363
381
364
382
int main (void ) {
@@ -371,6 +389,11 @@ int main(void) {
371
389
candidate_strategies.push_back (block_allocator::allocation_strategy::BA_STRATEGY_PADDED_FIT);
372
390
candidate_strategies.push_back (block_allocator::allocation_strategy::BA_STRATEGY_HEAT_ZONE);
373
391
392
+ printf (" \n " );
393
+ printf (" Individual reports, by allocator:\n " );
394
+ printf (" \n " );
395
+
396
+ map<block_allocator::allocation_strategy, TOKU_DB_FRAGMENTATION_S> reports_by_strategy;
374
397
for (vector<enum block_allocator::allocation_strategy>::const_iterator it = candidate_strategies.begin ();
375
398
it != candidate_strategies.end (); it++) {
376
399
const block_allocator::allocation_strategy strategy (*it);
@@ -381,16 +404,31 @@ int main(void) {
381
404
map<uint64_t , block_allocator *> allocator_map;
382
405
replay_canonicalized_trace (canonicalized_trace, strategy, &allocator_map);
383
406
407
+ TOKU_DB_FRAGMENTATION_S aggregate_report;
408
+ memset (&aggregate_report, 0 , sizeof (aggregate_report));
384
409
for (map<uint64_t , block_allocator *>::iterator al = allocator_map.begin ();
385
410
al != allocator_map.end (); al++) {
386
411
block_allocator *ba = al->second ;
387
412
388
413
TOKU_DB_FRAGMENTATION_S report;
414
+ memset (&report, 0 , sizeof (report));
389
415
ba->get_statistics (&report);
390
416
ba->destroy ();
391
417
392
- print_result (al->first , strategy,&report);
418
+ merge_fragmentation_reports (&aggregate_report, &report);
419
+ print_result (al->first , strategy, &report);
393
420
}
421
+ reports_by_strategy[strategy] = aggregate_report;
422
+ }
423
+
424
+ printf (" \n " );
425
+ printf (" Aggregate reports, by strategy:\n " );
426
+ printf (" \n " );
427
+
428
+ for (map<block_allocator::allocation_strategy, TOKU_DB_FRAGMENTATION_S>::iterator it = reports_by_strategy.begin ();
429
+ it != reports_by_strategy.end (); it++) {
430
+ TOKU_DB_FRAGMENTATION report = &it->second ;
431
+ print_result (0 , it->first , report);
394
432
}
395
433
396
434
return 0 ;
0 commit comments