From bb1fd6c7da166dcc0ac6a3fe48e8f330743df077 Mon Sep 17 00:00:00 2001 From: guest Date: Fri, 8 Mar 2024 10:05:59 +0800 Subject: [PATCH] The compiler outputs size statistics for each data structure Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I95JE4 Signed-off-by: liujia178 Change-Id: c580a5491be8116bfb239750b47dc9af30c3a190 --- libpandafile/file_item_container.cpp | 20 ++++++++++++++++++-- libpandafile/file_item_container.h | 10 ++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/libpandafile/file_item_container.cpp b/libpandafile/file_item_container.cpp index 6ba535c1f4..edd0a60a2f 100644 --- a/libpandafile/file_item_container.cpp +++ b/libpandafile/file_item_container.cpp @@ -420,10 +420,13 @@ void ItemContainer::DeduplicateItems(bool computeLayout) uint32_t ItemContainer::ComputeLayout() { + uint32_t original_offset = 0; uint32_t num_classes = class_map_.size(); uint32_t num_literalarrays = literalarray_map_.size(); uint32_t class_idx_offset = sizeof(File::Header); uint32_t cur_offset = class_idx_offset + (num_classes + num_literalarrays) * ID_SIZE; + items_round_up_size_.clear(); + foreign_item_roundup_size_ = 0; UpdateOrderIndexes(); @@ -435,25 +438,33 @@ uint32_t ItemContainer::ComputeLayout() cur_offset += index_section_item_.GetSize(); for (auto &item : foreign_items_) { + original_offset = cur_offset; cur_offset = RoundUp(cur_offset, item->Alignment()); + foreign_item_roundup_size_ += caculateRoundUpSize(original_offset, cur_offset); item->SetOffset(cur_offset); item->ComputeLayout(); cur_offset += item->GetSize(); } for (auto &item : items_) { + const auto &name = item->GetName(); + if (!item->NeedsEmit()) { continue; } + original_offset = cur_offset; cur_offset = RoundUp(cur_offset, item->Alignment()); + items_round_up_size_[name] += caculateRoundUpSize(original_offset, cur_offset); item->SetOffset(cur_offset); item->ComputeLayout(); cur_offset += item->GetSize(); } // Line number program should be last because it's size is known only after deduplication + original_offset = cur_offset; cur_offset = RoundUp(cur_offset, line_number_program_index_item_.Alignment()); + line_number_item_roundup_size_ = caculateRoundUpSize(original_offset, cur_offset); line_number_program_index_item_.SetOffset(cur_offset); line_number_program_index_item_.ComputeLayout(); cur_offset += line_number_program_index_item_.GetSize(); @@ -714,11 +725,12 @@ std::map ItemContainer::GetStat() stat["header_item"] = sizeof(File::Header); stat["class_idx_item"] = class_map_.size() * ID_SIZE; - stat["line_number_program_idx_item"] = line_number_program_index_item_.GetNumItems() * ID_SIZE; + stat["line_number_program_idx_item"] = line_number_program_index_item_.GetNumItems() * ID_SIZE + + line_number_item_roundup_size_; stat["literalarray_idx"] = literalarray_map_.size() * ID_SIZE; stat["index_section_item"] = index_section_item_.GetSize(); - stat["foreign_item"] = GetForeignSize(); + stat["foreign_item"] = GetForeignSize() + foreign_item_roundup_size_; size_t num_ins = 0; size_t codesize = 0; @@ -740,6 +752,10 @@ std::map ItemContainer::GetStat() codesize += static_cast(item.get())->GetCodeSize(); } } + + for (const auto &[name, round_up_size] : items_round_up_size_) { + stat[name] += round_up_size; + } stat["instructions_number"] = num_ins; stat["codesize"] = codesize; diff --git a/libpandafile/file_item_container.h b/libpandafile/file_item_container.h index 87b301080f..063a6a342c 100644 --- a/libpandafile/file_item_container.h +++ b/libpandafile/file_item_container.h @@ -111,6 +111,11 @@ public: void DumpItemsStat(std::ostream &os) const; + uint32_t caculateRoundUpSize(uint32_t before, uint32_t after) + { + return after - before; + } + std::unordered_map *GetStringMap() { return &string_map_; @@ -565,6 +570,11 @@ private: std::list>::iterator code_items_end_; std::list>::iterator debug_items_end_; + // Get Roundup Alignment Size + std::unordered_map items_round_up_size_; + uint32_t foreign_item_roundup_size_ {0}; + uint32_t line_number_item_roundup_size_ {0}; + BaseItem *end_; size_t indexed_item_count_ {0}; const uint8_t api_{0};