Add all stores in File to CollectMemUsage (#8050)

A number of stores have been added to File without updating
CollectMemUsage. Add all the stores that were missed, ordering
everything by the order the fields appear in the class. Also include the
filename_ string, which requires a new overload of Collect, since
strings are like vectors of chars.
This commit is contained in:
Dana Jansens authored and GitHub committed 2026-10-27 22:16:05 +00:00
1 parent c008bec1a5
commit e6fddcf975
2 files changed
+39 -6

No files matched your search

+7 -2
View File
@@ -33,9 +33,9 @@ namespace Carbon {
// data_.reserved_bytes());
// // Common library types like `Map` and `llvm::SmallVector` have
// // type-specific support.
// mem_usage.Add(MemUsage::Concat(label, "array_"), array_);
// mem_usage.Add(MemUsage::ConcatLabel(label, "array_"), array_);
// // Implementing `CollectMemUsage` allows use with the same interface.
// mem_usage.Collect(MemUsage::Concat(label, "obj_"), obj_);
// mem_usage.Collect(MemUsage::ConcatLabel(label, "obj_"), obj_);
// }
class MemUsage {
public:
@@ -104,6 +104,11 @@ class MemUsage {
Add(std::move(label), array.size_in_bytes(), array.capacity_in_bytes());
}
// Adds memory usage of a string's data.
auto Collect(std::string label, const std::string& string) -> void {
Add(std::move(label), string.size(), string.capacity());
}
// Adds memory usage for an object that provides `CollectMemUsage`.
//
// The expected signature of `CollectMemUsage` is above, in MemUsage class
+32 -4
View File
@@ -210,15 +210,32 @@ auto File::OutputYaml(bool include_singletons) const -> Yaml::OutputMapping {
auto File::CollectMemUsage(MemUsage& mem_usage, llvm::StringRef label) const
-> void {
mem_usage.Collect(MemUsage::ConcatLabel(label, "allocator_"), allocator_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "clang_source_locs_"),
clang_source_locs_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "filename_"), filename_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "entity_names_"),
entity_names_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "functions_"), functions_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "generated_functions_"),
generated_functions_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "cpp_overload_sets_"),
cpp_overload_sets_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "thunks_"), thunks_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "classes_"), classes_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "fields_"), fields_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "interfaces_"), interfaces_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "named_constraints_"),
named_constraints_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "require_impls_"),
require_impls_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "observes_"), observes_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "observe_blocks_"),
observe_blocks_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "associated_constants_"),
associated_constants_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "declared_facet_types_"),
declared_facet_types_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "impls_"), impls_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "specific_interfaces_"),
specific_interfaces_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "generics_"), generics_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "specifics_"), specifics_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "import_irs_"), import_irs_);
@@ -227,15 +244,26 @@ auto File::CollectMemUsage(MemUsage& mem_usage, llvm::StringRef label) const
mem_usage.Collect(MemUsage::ConcatLabel(label, "clang_decls_"), clang_decls_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "clang_decl_signatures_"),
clang_decl_signatures_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "struct_type_fields_"),
struct_type_fields_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "insts_"), insts_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "vtables_"), vtables_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "name_scopes_"), name_scopes_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "constant_values_"),
constant_values_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "inst_blocks_"), inst_blocks_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "constants_"), constants_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "struct_type_fields_"),
struct_type_fields_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "custom_layouts_"),
custom_layouts_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "types_"), types_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "expr_regions_"),
expr_regions_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "clang_source_locs_"),
clang_source_locs_);
mem_usage.Collect(MemUsage::ConcatLabel(label, "bundles_"), bundles_);
mem_usage.Collect(
MemUsage::ConcatLabel(label, "clang_function_pointer_types_"),
clang_function_pointer_types_);
}
auto File::set_cpp_file(std::unique_ptr<SemIR::CppFile> cpp_file) -> void {