|
5 | 5 | #include "core/page_usage_stats.h"
|
6 | 6 |
|
7 | 7 | #include <absl/container/flat_hash_set.h>
|
8 |
| -#include <cmake-build-debug/third_party/libs/hdr_histogram/include/hdr/hdr_histogram.h> |
| 8 | +#include <absl/strings/str_join.h> |
9 | 9 | #include <glog/logging.h>
|
10 | 10 | #include <hdr/hdr_histogram.h>
|
11 | 11 |
|
@@ -54,13 +54,43 @@ void CollectedPageStats::Merge(CollectedPageStats&& other, ShardId shard_id) {
|
54 | 54 | shard_wide_summary.emplace(std::make_pair(shard_id, std::move(other.page_usage_hist)));
|
55 | 55 | }
|
56 | 56 |
|
57 |
| -UniquePages::UniquePages(float threshold) |
58 |
| - : pages_scanned{MakeBloomFilter()}, |
59 |
| - pages_marked_for_realloc{MakeBloomFilter()}, |
60 |
| - pages_full{MakeBloomFilter()}, |
61 |
| - pages_reserved_for_malloc{MakeBloomFilter()}, |
62 |
| - pages_with_heap_mismatch{MakeBloomFilter()}, |
63 |
| - pages_above_threshold{MakeBloomFilter()} { |
| 57 | +CollectedPageStats CollectedPageStats::Merge(CollectedPageStats* stats, const size_t size, |
| 58 | + const float threshold) { |
| 59 | + CollectedPageStats result; |
| 60 | + result.threshold = threshold; |
| 61 | + for (size_t i = 0; i < size; ++i) { |
| 62 | + result.Merge(std::move(*stats), i); |
| 63 | + stats++; |
| 64 | + } |
| 65 | + return result; |
| 66 | +} |
| 67 | + |
| 68 | +std::string CollectedPageStats::ToString() const { |
| 69 | + std::vector<std::string> rows; |
| 70 | + rows.push_back(absl::StrFormat("Page usage threshold: %f", threshold * 100)); |
| 71 | + rows.push_back(absl::StrFormat("Pages scanned: %d", pages_scanned)); |
| 72 | + rows.push_back(absl::StrFormat("Pages marked for reallocation: %d", pages_marked_for_realloc)); |
| 73 | + rows.push_back(absl::StrFormat("Pages full: %d", pages_full)); |
| 74 | + rows.push_back(absl::StrFormat("Pages reserved for malloc: %d", pages_reserved_for_malloc)); |
| 75 | + rows.push_back( |
| 76 | + absl::StrFormat("Pages skipped due to heap mismatch: %d", pages_with_heap_mismatch)); |
| 77 | + rows.push_back(absl::StrFormat("Pages with usage above threshold: %d", pages_above_threshold)); |
| 78 | + for (const auto& [shard_id, usage] : shard_wide_summary) { |
| 79 | + rows.push_back(absl::StrFormat("[Shard %d]", shard_id)); |
| 80 | + for (const auto& [percentage, count] : usage) { |
| 81 | + rows.push_back(absl::StrFormat(" %d%% pages are below %d%% block usage", percentage, count)); |
| 82 | + } |
| 83 | + } |
| 84 | + return absl::StrJoin(rows, "\n"); |
| 85 | +} |
| 86 | + |
| 87 | +UniquePages::UniquePages() |
| 88 | + : pages_scanned{MakeSBF()}, |
| 89 | + pages_marked_for_realloc{MakeSBF()}, |
| 90 | + pages_full{MakeSBF()}, |
| 91 | + pages_reserved_for_malloc{MakeSBF()}, |
| 92 | + pages_with_heap_mismatch{MakeSBF()}, |
| 93 | + pages_above_threshold{MakeSBF()} { |
64 | 94 | hdr_histogram* h = nullptr;
|
65 | 95 | const auto init_result = hdr_init(1, 100, kHistSignificantFigures, &h);
|
66 | 96 | CHECK_EQ(0, init_result) << "failed to initialize histogram";
|
|
0 commit comments