mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-12 22:10:54 -04:00
feat(dwarfsck): show categories in metadata output
This commit is contained in:
parent
20f8ca51a3
commit
f4d918dd73
@ -24,7 +24,9 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "dwarfs/block_compressor.h" // TODO: or the other way round?
|
#include "dwarfs/block_compressor.h" // TODO: or the other way round?
|
||||||
#include "dwarfs/checksum.h"
|
#include "dwarfs/checksum.h"
|
||||||
@ -90,6 +92,8 @@ struct filesystem_info {
|
|||||||
uint64_t uncompressed_metadata_size{0};
|
uint64_t uncompressed_metadata_size{0};
|
||||||
bool uncompressed_block_size_is_estimate{false};
|
bool uncompressed_block_size_is_estimate{false};
|
||||||
bool uncompressed_metadata_size_is_estimate{false};
|
bool uncompressed_metadata_size_is_estimate{false};
|
||||||
|
std::vector<size_t> compressed_block_sizes;
|
||||||
|
std::vector<std::optional<size_t>> uncompressed_block_sizes;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool is_known_compression_type(compression_type type);
|
bool is_known_compression_type(compression_type type);
|
||||||
|
@ -443,19 +443,22 @@ filesystem_info const& filesystem_<LoggerPolicy>::get_info() const {
|
|||||||
if (s->type() == section_type::BLOCK) {
|
if (s->type() == section_type::BLOCK) {
|
||||||
++info.block_count;
|
++info.block_count;
|
||||||
info.compressed_block_size += s->length();
|
info.compressed_block_size += s->length();
|
||||||
|
info.compressed_block_sizes.push_back(s->length());
|
||||||
try {
|
try {
|
||||||
info.uncompressed_block_size +=
|
auto uncompressed_size = get_uncompressed_section_size(mm_, *s);
|
||||||
get_uncompressed_section_size(mm_, *s);
|
info.uncompressed_block_size += uncompressed_size;
|
||||||
} catch (std::exception const& e) {
|
info.uncompressed_block_sizes.push_back(uncompressed_size);
|
||||||
|
} catch (std::exception const&) {
|
||||||
info.uncompressed_block_size += s->length();
|
info.uncompressed_block_size += s->length();
|
||||||
info.uncompressed_block_size_is_estimate = true;
|
info.uncompressed_block_size_is_estimate = true;
|
||||||
|
info.uncompressed_block_sizes.push_back(std::nullopt);
|
||||||
}
|
}
|
||||||
} else if (s->type() == section_type::METADATA_V2) {
|
} else if (s->type() == section_type::METADATA_V2) {
|
||||||
info.compressed_metadata_size += s->length();
|
info.compressed_metadata_size += s->length();
|
||||||
try {
|
try {
|
||||||
info.uncompressed_metadata_size +=
|
info.uncompressed_metadata_size +=
|
||||||
get_uncompressed_section_size(mm_, *s);
|
get_uncompressed_section_size(mm_, *s);
|
||||||
} catch (std::exception const& e) {
|
} catch (std::exception const&) {
|
||||||
info.uncompressed_metadata_size += s->length();
|
info.uncompressed_metadata_size += s->length();
|
||||||
info.uncompressed_metadata_size_is_estimate = true;
|
info.uncompressed_metadata_size_is_estimate = true;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include <folly/container/Enumerate.h>
|
||||||
#include <folly/container/F14Set.h>
|
#include <folly/container/F14Set.h>
|
||||||
#include <folly/portability/Stdlib.h>
|
#include <folly/portability/Stdlib.h>
|
||||||
#include <folly/portability/Unistd.h>
|
#include <folly/portability/Unistd.h>
|
||||||
@ -990,6 +991,43 @@ void metadata_<LoggerPolicy>::dump(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (meta_.block_categories()) {
|
||||||
|
auto const& catnames = *meta_.category_names();
|
||||||
|
struct category_info {
|
||||||
|
size_t count{0};
|
||||||
|
size_t compressed_size{0};
|
||||||
|
size_t uncompressed_size{0};
|
||||||
|
bool uncompressed_size_is_estimate{false};
|
||||||
|
};
|
||||||
|
std::map<size_t, category_info> catinfo;
|
||||||
|
for (auto [block, category] : folly::enumerate(*meta_.block_categories())) {
|
||||||
|
auto& ci = catinfo[category];
|
||||||
|
++ci.count;
|
||||||
|
ci.compressed_size += fsinfo.compressed_block_sizes.at(block);
|
||||||
|
if (auto size = fsinfo.uncompressed_block_sizes.at(block)) {
|
||||||
|
ci.uncompressed_size += *size;
|
||||||
|
} else {
|
||||||
|
ci.uncompressed_size_is_estimate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os << "categories:\n";
|
||||||
|
for (auto const& [category, ci] : catinfo) {
|
||||||
|
os << " " << catnames[category] << ": " << ci.count << " blocks";
|
||||||
|
if (ci.uncompressed_size_is_estimate ||
|
||||||
|
ci.uncompressed_size != ci.compressed_size) {
|
||||||
|
os << ", " << size_with_unit(ci.compressed_size) << " compressed";
|
||||||
|
}
|
||||||
|
if (!ci.uncompressed_size_is_estimate) {
|
||||||
|
os << ", " << size_with_unit(ci.uncompressed_size) << " uncompressed";
|
||||||
|
if (ci.uncompressed_size != ci.compressed_size) {
|
||||||
|
os << fmt::format(" ({0:.2f}%)", (100.0 * ci.compressed_size) /
|
||||||
|
ci.uncompressed_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (detail_level > 1) {
|
if (detail_level > 1) {
|
||||||
analyze_frozen(os, meta_, data_.size(), detail_level);
|
analyze_frozen(os, meta_, data_.size(), detail_level);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user