Skip to content

Commit

Permalink
add num_tries
Browse files Browse the repository at this point in the history
Summary: To assess how many bytes we spend on encoding try-regions.

Differential Revision: D51054721

fbshipit-source-id: 8f8304f09e98d07d3a29813eb72686997988cc96
  • Loading branch information
Nikolai Tillmann authored and facebook-github-bot committed Nov 7, 2023
1 parent d3e151e commit c5f6dfb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
21 changes: 10 additions & 11 deletions libredex/DexLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,17 @@ void DexLoader::gather_input_stats(dex_stats_t* stats, const dex_header* dh) {
stats->num_fields += clz->get_ifields().size() + clz->get_sfields().size();
stats->num_methods +=
clz->get_vmethods().size() + clz->get_dmethods().size();
for (auto* meth : clz->get_vmethods()) {
DexCode* code = meth->get_dex_code();
if (code) {
stats->num_instructions += code->get_instructions().size();
}
}
for (auto* meth : clz->get_dmethods()) {
DexCode* code = meth->get_dex_code();
if (code) {
stats->num_instructions += code->get_instructions().size();
auto process_methods = [&](const auto& methods) {
for (auto* meth : methods) {
DexCode* code = meth->get_dex_code();
if (code) {
stats->num_instructions += code->get_instructions().size();
stats->num_tries += code->get_tries().size();
}
}
}
};
process_methods(clz->get_vmethods());
process_methods(clz->get_dmethods());
}
for (uint32_t meth_idx = 0; meth_idx < dh->method_ids_size; ++meth_idx) {
auto* meth = m_idx->get_methodidx(meth_idx);
Expand Down
1 change: 1 addition & 0 deletions libredex/DexOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ void DexOutput::generate_code_items(const std::vector<SortMode>& mode) {
((const dex_code_item*)(m_output.get() + m_offset))->insns_size;
inc_offset(size);
m_stats.num_instructions += code->get_instructions().size();
m_stats.num_tries += code->get_tries().size();
m_stats.instruction_bytes += insns_size * 2;
}
/// insert_map_item returns early if m_code_item_emits is empty
Expand Down
1 change: 1 addition & 0 deletions libredex/DexStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dex_stats_t& dex_stats_t::operator+=(const dex_stats_t& rhs) {
num_type_lists += rhs.num_type_lists;
num_bytes += rhs.num_bytes;
num_instructions += rhs.num_instructions;
num_tries += rhs.num_tries;
num_unique_types += rhs.num_unique_types;
num_unique_protos += rhs.num_unique_protos;
num_unique_strings += rhs.num_unique_strings;
Expand Down
1 change: 1 addition & 0 deletions libredex/DexStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct dex_stats_t {
int num_instructions = 0;
int num_callsites = 0;
int num_methodhandles = 0;
int num_tries = 0;

int num_unique_strings = 0;
int num_unique_types = 0;
Expand Down
1 change: 1 addition & 0 deletions tools/redex-all/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ Json::Value get_stats(const dex_stats_t& stats) {
val["num_annotations"] = stats.num_annotations;
val["num_bytes"] = stats.num_bytes;
val["num_instructions"] = stats.num_instructions;
val["num_tries"] = stats.num_tries;

val["num_unique_types"] = stats.num_unique_types;
val["num_unique_protos"] = stats.num_unique_protos;
Expand Down

0 comments on commit c5f6dfb

Please sign in to comment.