Skip to content

Commit

Permalink
dump necessary info for offline analysis
Browse files Browse the repository at this point in the history
Summary: as title

Reviewed By: thezhangwei

Differential Revision: D52850723

fbshipit-source-id: e147f17b31adcb70ff16033a1db3d11d444f427a
  • Loading branch information
beicy authored and facebook-github-bot committed Jan 26, 2024
1 parent 33aeb6d commit 2a8dee2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions opt/interdex/InterDexPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void InterDexPass::run_pass(

mgr.set_metric("root_store.dexes", dexen.size());
redex_assert(dexen.size() == interdex.get_dex_info().size());

for (size_t i = 0; i != dexen.size(); ++i) {
std::string key_prefix = "root_store.dexes." + std::to_string(i) + ".";
mgr.set_metric(key_prefix + "classes", dexen[i].size());
Expand Down
9 changes: 8 additions & 1 deletion service/cross-dex-ref-minimizer/CrossDexRefMinimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,20 @@ void CrossDexRefMinimizer::sample(DexClass* cls) {
}

if (m_json_classes) {
Json::Value json_interface = Json::arrayValue;
auto intfs = cls->get_interfaces();
for (auto intf : *intfs) {
json_interface.append(show(intf));
}
Json::Value json_class;
json_class["method_refs"] = m_json_methods.get(cls_refs.method_refs);
json_class["field_refs"] = m_json_fields.get(cls_refs.field_refs);
json_class["types"] = m_json_types.get(cls_refs.types);
json_class["strings"] = m_json_strings.get(cls_refs.strings);
json_class["is_generated"] = cls->rstate.is_generated();
json_class["insert_index"] = -1;
json_class["super_cls"] = cls->get_super_class()->get_name()->c_str();
json_class["interfaces"] = json_interface;
(*m_json_classes)[get_json_class_index(cls)] = json_class;
}
}
Expand Down Expand Up @@ -526,7 +533,7 @@ Json::Value CrossDexRefMinimizer::get_json_mapping() {
// These could be further nested into a ref-specific path,
// but it just makes the mapping more annoying to use.
Json::Value res = Json::objectValue;
m_json_methods.get_mapping(&res);
m_json_methods.get_method_mapping(&res);
m_json_fields.get_mapping(&res);
m_json_types.get_mapping(&res);
m_json_strings.get_mapping(&res);
Expand Down
20 changes: 20 additions & 0 deletions service/cross-dex-ref-minimizer/CrossDexRefMinimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,26 @@ class CrossDexRefMinimizer {
(*res)[format(index)] = show(ref);
}
}

void get_method_mapping(Json::Value* res) const {
for (const auto& [ref, index] : m_indices) {
Json::Value method_info;
method_info["name"] = show(ref);
const DexMethod* meth = ref->as_def();
if (meth == nullptr) {
method_info["type"] = "no_method";
} else if (meth->is_virtual()) {
method_info["type"] = "virtual";
} else if (is_static(meth)) {
method_info["type"] = "static";
} else if (is_final(meth)) {
method_info["type"] = "final";
} else {
method_info["type"] = "other";
}
(*res)[format(index)] = method_info;
}
}
};
JsonRefIndices<DexMethodRef*> m_json_methods{"M"};
JsonRefIndices<DexFieldRef*> m_json_fields{"F"};
Expand Down

0 comments on commit 2a8dee2

Please sign in to comment.