2020using namespace std ;
2121
2222void usage (const string &name) {
23- cerr << " Usage: " << name << " <log_to_replay> <raw_duplicates|duplicates|free_dump|try_alloc count want alloc_unit|replay_alloc alloc_list_file|export_binary out_file>" << std::endl;
23+ cerr << " Usage: " << name << " <log_to_replay|free-dump> "
24+ << " raw_duplicates|"
25+ " duplicates|"
26+ " free_dump|"
27+ " try_alloc <count> <want> <alloc_unit>|"
28+ " replay_alloc <alloc_list_file|"
29+ " export_binary <out_file>|"
30+ " free_histogram [<alloc_unit>] [<num_buckets>]"
31+ << std::endl;
2432}
2533
2634void usage_replay_alloc (const string &name) {
@@ -548,7 +556,7 @@ int main(int argc, char **argv)
548556 << std::endl;
549557 std::cout << " Fragmentation score:" << a->get_fragmentation_score ()
550558 << std::endl;
551- std::cout << " Free:" << std::hex << a->get_free () << std::dec
559+ std::cout << " Free: 0x " << std::hex << a->get_free () << std::dec
552560 << std::endl;
553561 {
554562 // stub to implement various testing stuff on properly initialized allocator
@@ -574,7 +582,7 @@ int main(int argc, char **argv)
574582 << std::endl;
575583 std::cout << " Fragmentation score:" << a->get_fragmentation_score ()
576584 << std::endl;
577- std::cout << " Free:" << std::hex << a->get_free () << std::dec
585+ std::cout << " Free: 0x " << std::hex << a->get_free () << std::dec
578586 << std::endl;
579587 {
580588 PExtentVector extents;
@@ -606,7 +614,7 @@ int main(int argc, char **argv)
606614 << std::endl;
607615 std::cout << " Fragmentation score:" << a->get_fragmentation_score ()
608616 << std::endl;
609- std::cout << " Free:" << std::hex << a->get_free () << std::dec
617+ std::cout << " Free: 0x " << std::hex << a->get_free () << std::dec
610618 << std::endl;
611619 {
612620 /* replay a set of allocation requests */
@@ -655,7 +663,7 @@ int main(int argc, char **argv)
655663 << std::endl;
656664 std::cerr << " Fragmentation score:" << a->get_fragmentation_score ()
657665 << std::endl;
658- std::cerr << " Free:" << std::hex << a->get_free () << std::dec
666+ std::cerr << " Free: 0x " << std::hex << a->get_free () << std::dec
659667 << std::endl;
660668 /* return 0 if the allocator ran out of space */
661669 if (r == -ENOSPC) {
@@ -681,11 +689,48 @@ int main(int argc, char **argv)
681689 << std::endl;
682690 std::cout << " Fragmentation score:" << a->get_fragmentation_score ()
683691 << std::endl;
684- std::cout << " Free:" << std::hex << a->get_free () << std::dec
692+ std::cout << " Free: 0x " << std::hex << a->get_free () << std::dec
685693 << std::endl;
686694 }
687695 return 0 ;
688696 });
697+ } else if (strcmp (argv[2 ], " free_histogram" ) == 0 ) {
698+ uint64_t alloc_unit = 4096 ;
699+ auto num_buckets = 8 ;
700+ if (argc >= 4 ) {
701+ alloc_unit = strtoul (argv[3 ], nullptr , 10 );
702+ }
703+ if (argc >= 5 ) {
704+ num_buckets = strtoul (argv[4 ], nullptr , 10 );
705+ }
706+ return replay_free_dump_and_apply (argv[1 ],
707+ [&](Allocator *a, const string &aname) {
708+ ceph_assert (a);
709+ std::cout << " Fragmentation:" << a->get_fragmentation ()
710+ << std::endl;
711+ std::cout << " Fragmentation score:" << a->get_fragmentation_score ()
712+ << std::endl;
713+ std::cout << " Free: 0x" << std::hex << a->get_free () << std::dec
714+ << std::endl;
715+ std::cout << " Allocation unit:" << alloc_unit
716+ << std::endl;
717+
718+ Allocator::FreeStateHistogram hist;
719+ hist.resize (num_buckets);
720+ a->build_free_state_histogram (alloc_unit, hist);
721+
722+ uint64_t s = 0 ;
723+ for (int i = 0 ; i < num_buckets; i++) {
724+ uint64_t e = hist[i].get_max (i, num_buckets);
725+ std::cout << " (" << s << " .." << e << " ]"
726+ << " -> " << hist[i].total
727+ << " chunks, " << hist[i].aligned << " aligned with "
728+ << hist[i].alloc_units << " alloc_units."
729+ << std::endl;
730+ s = e;
731+ }
732+ return 0 ;
733+ });
689734 } else if (strcmp (argv[2 ], " export_binary" ) == 0 ) {
690735 return export_as_binary (argv[1 ], argv[3 ]);
691736 } else if (strcmp (argv[2 ], " duplicates" ) == 0 ) {
0 commit comments